1%%% @doc 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 set_paths/2, 13 unset_paths/2, 14 add_deps_to_path/1, 15 restore_code_path/1, 16 processing_base_dir/1, 17 ssl_opts/1]). 18 19-export_type([rebar_dict/0, rebar_digraph/0]). 20 21%%%%%%%%%%%%%%%%%%%%%%% 22%%% Error reporting %%% 23%%%%%%%%%%%%%%%%%%%%%%% 24 25%% @doc Interrupts program flow 26-spec abort() -> no_return(). 27abort() -> ?ABORT. 28 29%% @doc like {@link error/2}, except it also raises an 30%% exception to interrupt program flow. 31-spec abort(string(), list()) -> no_return(). 32abort(Str, Args) -> ?ABORT(Str, Args). 33 34%% @doc Prints to the console, including a newline 35-spec console(string(), list()) -> ok. 36console(Str, Args) -> ?CONSOLE(Str, Args). 37 38%% @doc logs with severity `debug' 39-spec debug(string(), list()) -> ok. 40debug(Str, Args) -> ?DEBUG(Str, Args). 41 42%% @doc logs with severity `info' 43-spec info(string(), list()) -> ok. 44info(Str, Args) -> ?INFO(Str, Args). 45 46%% @doc logs with severity `warn' 47-spec warn(string(), list()) -> ok. 48warn(Str, Args) -> ?WARN(Str, Args). 49 50%% @doc logs with severity `error' 51-spec error(string(), list()) -> ok. 52error(Str, Args) -> ?ERROR(Str, Args). 53 54%% @doc Given env. variable `FOO' we want to expand all references to 55%% it in `InStr'. References can have two forms: `$FOO' and `${FOO}' 56%% The end of form `$FOO' is delimited with whitespace or EOL 57-spec expand_env_variable(string(), string(), term()) -> string(). 58expand_env_variable(InStr, VarName, RawVarValue) -> 59 rebar_utils:expand_env_variable(InStr, VarName, RawVarValue). 60 61%% @doc returns the sytem architecture, in strings like 62%% `"19.0.4-x86_64-unknown-linux-gnu-64"'. 63-spec get_arch() -> string(). 64get_arch() -> 65 rebar_utils:get_arch(). 66 67%% @doc returns the size of a word on the system, as a string 68-spec wordsize() -> string(). 69wordsize() -> 70 rebar_utils:wordsize(). 71 72%% @doc Set code paths. Takes arguments of the form 73%% `[plugins, deps]' or `[deps, plugins]' and ensures the 74%% project's app and dependencies are set in the right order 75%% for the next bit of execution 76-spec set_paths(rebar_paths:targets(), rebar_state:t()) -> ok. 77set_paths(List, State) -> 78 rebar_paths:set_paths(List, State). 79 80%% @doc Unsets code paths. Takes arguments of the form 81%% `[plugins, deps]' or `[deps, plugins]' and ensures the 82%% paths are no longer active. 83-spec unset_paths(rebar_paths:targets(), rebar_state:t()) -> ok. 84unset_paths(List, State) -> 85 rebar_paths:unset_paths(List, State). 86 87%% @doc Add deps to the code path 88-spec add_deps_to_path(rebar_state:t()) -> ok. 89add_deps_to_path(State) -> 90 code:add_pathsa(rebar_state:code_paths(State, all_deps)). 91 92%% @doc Revert to only having the beams necessary for running rebar3 and 93%% plugins in the path 94-spec restore_code_path(rebar_state:t()) -> true | {error, term()}. 95restore_code_path(State) -> 96 rebar_utils:cleanup_code_path(rebar_state:code_paths(State, default)). 97 98%% @doc checks if the current working directory is the base directory 99%% for the project. 100-spec processing_base_dir(rebar_state:t()) -> boolean(). 101processing_base_dir(State) -> 102 rebar_dir:processing_base_dir(State). 103 104%% @doc returns the SSL options adequate for the project based on 105%% its configuration, including for validation of certs. 106-spec ssl_opts(string() | binary()) -> [term()]. 107ssl_opts(Url) -> 108 rebar_utils:ssl_opts(Url). 109