summaryrefslogtreecommitdiff
path: root/src/rebar_api.erl
blob: 88c7538db1a05d0a017cfbef356a813c3140f118 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
%%% Packages rebar.hrl features and macros into a more generic API
%%% that can be used by plugin builders.
-module(rebar_api).
-include("rebar.hrl").
-include_lib("providers/include/providers.hrl").
-export([abort/0, abort/2,
         console/2,
         debug/2, info/2, warn/2, error/2,
         expand_env_variable/3,
         get_arch/0,
         wordsize/0,
         add_deps_to_path/1,
         restore_code_path/1]).

-export_type([rebar_dict/0, rebar_digraph/0]).

%%%%%%%%%%%%%%%%%%%%%%%
%%% Error reporting %%%
%%%%%%%%%%%%%%%%%%%%%%%

%% @doc Interrupts program flow
abort() -> ?FAIL.

%% @doc like {@link error/2}, except it also raises an
%% exception to interrupt program flow.
abort(Str, Args) -> ?ABORT(Str, Args).

%% @doc Prints to the console, including a newline
console(Str, Args) -> ?CONSOLE(Str, Args).

%% @doc logs with severity `debug'
debug(Str, Args) -> ?DEBUG(Str, Args).
%% @doc logs with severity `info'
info(Str, Args) -> ?INFO(Str, Args).
%% @doc logs with severity `warn'
warn(Str, Args) -> ?WARN(Str, Args).
%% @doc logs with severity `error'
error(Str, Args) -> ?ERROR(Str, Args).

%%
%% Given env. variable FOO we want to expand all references to
%% it in InStr. References can have two forms: $FOO and ${FOO}
%% The end of form $FOO is delimited with whitespace or eol
%%
expand_env_variable(InStr, VarName, RawVarValue) ->
    rebar_utils:expand_env_variable(InStr, VarName, RawVarValue).

get_arch() ->
    rebar_utils:get_arch().

wordsize() ->
    rebar_utils:wordsize().


%% Add deps to the code path
add_deps_to_path(State) ->
  code:add_pathsa(rebar_state:code_paths(State, all_deps)).

%% Revert to only having the beams necessary for running rebar3 and plugins in the path
restore_code_path(State) ->
  rebar_utils:cleanup_code_path(rebar_state:code_paths(State, default)).