Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

69 rader
2.8 KiB

  1. %% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
  2. %% ex: ts=4 sw=4 et
  3. -module(rebar_prv_app_discovery).
  4. -behaviour(provider).
  5. -export([init/1,
  6. do/1,
  7. format_error/1]).
  8. -include("rebar.hrl").
  9. -include_lib("providers/include/providers.hrl").
  10. -define(PROVIDER, app_discovery).
  11. -define(DEPS, []).
  12. %% ===================================================================
  13. %% Public API
  14. %% ===================================================================
  15. -spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
  16. init(State) ->
  17. State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
  18. {module, ?MODULE},
  19. {bare, false},
  20. {deps, ?DEPS},
  21. {example, ""},
  22. {short_desc, ""},
  23. {desc, ""},
  24. {opts, []}])),
  25. {ok, State1}.
  26. -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
  27. do(State) ->
  28. LibDirs = rebar_dir:lib_dirs(State),
  29. try
  30. State1 = rebar_app_discover:do(State, LibDirs),
  31. State2 = rebar_plugins:project_apps_install(State1),
  32. {ok, State2}
  33. catch
  34. throw:{error, {rebar_packages, Error}} ->
  35. {error, {rebar_packages, Error}};
  36. throw:{error, {rebar_app_utils, Error}} ->
  37. {error, {rebar_app_utils, Error}};
  38. throw:{error, {rebar_app_discover, Error}} ->
  39. {error, {rebar_app_discover, Error}};
  40. throw:{error, Error} ->
  41. ?PRV_ERROR(Error)
  42. end.
  43. -spec format_error(any()) -> iolist().
  44. format_error({multiple_app_files, Files}) ->
  45. io_lib:format("Multiple app files found in one app dir: ~ts", [rebar_string:join(Files, " and ")]);
  46. format_error({invalid_app_file, File, Reason}) ->
  47. case Reason of
  48. {Line, erl_parse, Description} ->
  49. io_lib:format("Invalid app file ~ts at line ~b: ~p",
  50. [File, Line, lists:flatten(Description)]);
  51. _ ->
  52. io_lib:format("Invalid app file ~ts: ~p", [File, Reason])
  53. end;
  54. %% Provide a slightly more informative error message for consult of app file failure
  55. format_error({rebar_file_utils, {bad_term_file, AppFile, Reason}}) ->
  56. io_lib:format("Error in app file ~ts: ~ts", [rebar_dir:make_relative_path(AppFile,
  57. rebar_dir:get_cwd()),
  58. file:format_error(Reason)]);
  59. format_error(Reason) ->
  60. io_lib:format("~p", [Reason]).