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.

91 lines
2.9 KiB

преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
  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. add_deps_to_path/1,
  13. restore_code_path/1,
  14. processing_base_dir/1,
  15. ssl_opts/1]).
  16. -export_type([rebar_dict/0, rebar_digraph/0]).
  17. %%%%%%%%%%%%%%%%%%%%%%%
  18. %%% Error reporting %%%
  19. %%%%%%%%%%%%%%%%%%%%%%%
  20. %% @doc Interrupts program flow
  21. -spec abort() -> no_return().
  22. abort() -> ?FAIL.
  23. %% @doc like {@link error/2}, except it also raises an
  24. %% exception to interrupt program flow.
  25. -spec abort(string(), list()) -> no_return().
  26. abort(Str, Args) -> ?ABORT(Str, Args).
  27. %% @doc Prints to the console, including a newline
  28. -spec console(string(), list()) -> ok.
  29. console(Str, Args) -> ?CONSOLE(Str, Args).
  30. %% @doc logs with severity `debug'
  31. -spec debug(string(), list()) -> ok.
  32. debug(Str, Args) -> ?DEBUG(Str, Args).
  33. %% @doc logs with severity `info'
  34. -spec info(string(), list()) -> ok.
  35. info(Str, Args) -> ?INFO(Str, Args).
  36. %% @doc logs with severity `warn'
  37. -spec warn(string(), list()) -> ok.
  38. warn(Str, Args) -> ?WARN(Str, Args).
  39. %% @doc logs with severity `error'
  40. -spec error(string(), list()) -> ok.
  41. error(Str, Args) -> ?ERROR(Str, Args).
  42. %% @doc Given env. variable `FOO' we want to expand all references to
  43. %% it in `InStr'. References can have two forms: `$FOO' and `${FOO}'
  44. %% The end of form `$FOO' is delimited with whitespace or EOL
  45. -spec expand_env_variable(string(), string(), term()) -> string().
  46. expand_env_variable(InStr, VarName, RawVarValue) ->
  47. rebar_utils:expand_env_variable(InStr, VarName, RawVarValue).
  48. %% @doc returns the sytem architecture, in strings like
  49. %% `"19.0.4-x86_64-unknown-linux-gnu-64"'.
  50. -spec get_arch() -> string().
  51. get_arch() ->
  52. rebar_utils:get_arch().
  53. %% @doc returns the size of a word on the system, as a string
  54. -spec wordsize() -> string().
  55. wordsize() ->
  56. rebar_utils:wordsize().
  57. %% @doc Add deps to the code path
  58. -spec add_deps_to_path(rebar_state:t()) -> ok.
  59. add_deps_to_path(State) ->
  60. code:add_pathsa(rebar_state:code_paths(State, all_deps)).
  61. %% @doc Revert to only having the beams necessary for running rebar3 and
  62. %% plugins in the path
  63. -spec restore_code_path(rebar_state:t()) -> true | {error, term()}.
  64. restore_code_path(State) ->
  65. rebar_utils:cleanup_code_path(rebar_state:code_paths(State, default)).
  66. %% @doc checks if the current working directory is the base directory
  67. %% for the project.
  68. -spec processing_base_dir(rebar_state:t()) -> boolean().
  69. processing_base_dir(State) ->
  70. rebar_dir:processing_base_dir(State).
  71. %% @doc returns the SSL options adequate for the project based on
  72. %% its configuration, including for validation of certs.
  73. -spec ssl_opts(string()) -> [term()].
  74. ssl_opts(Url) ->
  75. rebar_pkg_resource:ssl_opts(Url).