You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.3 KiB

10 years ago
10 years ago
  1. %% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
  2. %% ex: ts=4 sw=4 et
  3. -module(rebar_prv_release).
  4. -behaviour(provider).
  5. -export([init/1,
  6. do/1,
  7. format_error/1]).
  8. -include("rebar.hrl").
  9. -define(PROVIDER, release).
  10. -define(DEPS, [compile]).
  11. %% ===================================================================
  12. %% Public API
  13. %% ===================================================================
  14. -spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
  15. init(State) ->
  16. State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
  17. {module, ?MODULE},
  18. {bare, false},
  19. {deps, ?DEPS},
  20. {example, "rebar3 release"},
  21. {short_desc, "Build release of project."},
  22. {desc, ""},
  23. {opts, relx:opt_spec_list()}])),
  24. {ok, State1}.
  25. -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
  26. do(State) ->
  27. Caller = rebar_state:get(State, caller, api),
  28. Options = rebar_state:command_args(State),
  29. DepsDir = rebar_dir:deps_dir(State),
  30. LibDirs = rebar_utils:filtermap(fun ec_file:exists/1,
  31. [DepsDir | lists:delete(".", ?DEFAULT_PROJECT_APP_DIRS)]),
  32. OutputDir = filename:join(rebar_dir:base_dir(State), ?DEFAULT_RELEASE_DIR),
  33. AllOptions = string:join(["release" | Options], " "),
  34. try
  35. case rebar_state:get(State, relx, []) of
  36. [] ->
  37. relx:main([{lib_dirs, LibDirs}
  38. ,{output_dir, OutputDir}
  39. ,{caller, Caller}], AllOptions);
  40. Config ->
  41. relx:main([{lib_dirs, LibDirs}
  42. ,{config, lists:reverse(Config)}
  43. ,{output_dir, OutputDir}
  44. ,{caller, Caller}], AllOptions)
  45. end,
  46. {ok, State}
  47. catch
  48. throw:T ->
  49. {error, {rlx_prv_release, T}}
  50. end.
  51. -spec format_error(any()) -> iolist().
  52. format_error(Reason) ->
  53. io_lib:format("~p", [Reason]).