您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

57 行
2.2 KiB

  1. -module(rebar_prv_bare_compile).
  2. -behaviour(provider).
  3. -export([init/1,
  4. do/1,
  5. format_error/1]).
  6. -include_lib("providers/include/providers.hrl").
  7. -include("rebar.hrl").
  8. -define(PROVIDER, compile).
  9. -define(NAMESPACE, bare).
  10. -define(DEPS, [{default, app_discovery}]).
  11. %% ===================================================================
  12. %% Public API
  13. %% ===================================================================
  14. -spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
  15. init(State) ->
  16. State1 =
  17. rebar_state:add_provider(State,
  18. providers:create([{name, ?PROVIDER},
  19. {module, ?MODULE},
  20. {namespace, ?NAMESPACE},
  21. {bare, false},
  22. {deps, ?DEPS},
  23. {example, ""},
  24. {short_desc, ""},
  25. {desc, ""},
  26. {opts, [{paths, $p, "paths", string, "Wildcard paths of ebin directories to add to code path, separated by a colon"},
  27. {separator, $s, "separator", string, "In case of multiple return paths, the separator character to use to join them."}]}])),
  28. {ok, State1}.
  29. -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
  30. do(State) ->
  31. OrigPath = code:get_path(),
  32. %% Add code paths from --paths to the beginning of the code path
  33. {RawOpts, _} = rebar_state:command_parsed_args(State),
  34. Paths = proplists:get_value(paths, RawOpts),
  35. Sep = proplists:get_value(separator, RawOpts, " "),
  36. [ code:add_pathsa(filelib:wildcard(PathWildcard))
  37. || PathWildcard <- string:tokens(Paths, Sep) ],
  38. [AppInfo] = rebar_state:project_apps(State),
  39. AppInfo1 = rebar_app_info:out_dir(AppInfo, rebar_dir:get_cwd()),
  40. rebar_prv_compile:compile(State, AppInfo1),
  41. rebar_utils:cleanup_code_path(OrigPath),
  42. {ok, State}.
  43. -spec format_error(any()) -> iolist().
  44. format_error(Reason) ->
  45. io_lib:format("~p", [Reason]).