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.

65 lines
1.9 KiB

  1. %%% Packages rebar.hrl features and macros into a more generic API
  2. %%% that can be used by plugin builders.
  3. -module(rebar_api).
  4. -include("rebar.hrl").
  5. -include_lib("providers/include/providers.hrl").
  6. -export([abort/0, abort/2,
  7. console/2,
  8. debug/2, info/2, warn/2, error/2,
  9. expand_env_variable/3,
  10. get_arch/0,
  11. wordsize/0,
  12. add_deps_to_path/1,
  13. restore_code_path/1,
  14. processing_base_dir/1]).
  15. -export_type([rebar_dict/0, rebar_digraph/0]).
  16. %%%%%%%%%%%%%%%%%%%%%%%
  17. %%% Error reporting %%%
  18. %%%%%%%%%%%%%%%%%%%%%%%
  19. %% @doc Interrupts program flow
  20. abort() -> ?FAIL.
  21. %% @doc like {@link error/2}, except it also raises an
  22. %% exception to interrupt program flow.
  23. abort(Str, Args) -> ?ABORT(Str, Args).
  24. %% @doc Prints to the console, including a newline
  25. console(Str, Args) -> ?CONSOLE(Str, Args).
  26. %% @doc logs with severity `debug'
  27. debug(Str, Args) -> ?DEBUG(Str, Args).
  28. %% @doc logs with severity `info'
  29. info(Str, Args) -> ?INFO(Str, Args).
  30. %% @doc logs with severity `warn'
  31. warn(Str, Args) -> ?WARN(Str, Args).
  32. %% @doc logs with severity `error'
  33. error(Str, Args) -> ?ERROR(Str, Args).
  34. %%
  35. %% Given env. variable FOO we want to expand all references to
  36. %% it in InStr. References can have two forms: $FOO and ${FOO}
  37. %% The end of form $FOO is delimited with whitespace or eol
  38. %%
  39. expand_env_variable(InStr, VarName, RawVarValue) ->
  40. rebar_utils:expand_env_variable(InStr, VarName, RawVarValue).
  41. get_arch() ->
  42. rebar_utils:get_arch().
  43. wordsize() ->
  44. rebar_utils:wordsize().
  45. %% Add deps to the code path
  46. add_deps_to_path(State) ->
  47. code:add_pathsa(rebar_state:code_paths(State, all_deps)).
  48. %% Revert to only having the beams necessary for running rebar3 and plugins in the path
  49. restore_code_path(State) ->
  50. rebar_utils:cleanup_code_path(rebar_state:code_paths(State, default)).
  51. processing_base_dir(State) ->
  52. rebar_dir:processing_base_dir(State).