25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

74 satır
3.2 KiB

10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
  1. -module(rebar_prv_edoc).
  2. -behaviour(provider).
  3. -export([init/1,
  4. do/1,
  5. format_error/1]).
  6. -include("rebar.hrl").
  7. -define(PROVIDER, edoc).
  8. -define(DEPS, [compile]).
  9. %% ===================================================================
  10. %% Public API
  11. %% ===================================================================
  12. -spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
  13. init(State) ->
  14. State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
  15. {module, ?MODULE},
  16. {bare, true},
  17. {deps, ?DEPS},
  18. {example, "rebar3 edoc"},
  19. {short_desc, "Generate documentation using edoc."},
  20. {desc, "Generate documentation using edoc."},
  21. {opts, []},
  22. {profiles, [docs]}])),
  23. {ok, State1}.
  24. -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
  25. do(State) ->
  26. code:add_pathsa(rebar_state:code_paths(State, all_deps)),
  27. ProjectApps = rebar_state:project_apps(State),
  28. Providers = rebar_state:providers(State),
  29. EdocOpts = rebar_state:get(State, edoc_opts, []),
  30. ShouldAccPaths = not has_configured_paths(EdocOpts),
  31. Cwd = rebar_state:dir(State),
  32. rebar_hooks:run_all_hooks(Cwd, pre, ?PROVIDER, Providers, State),
  33. lists:foldl(fun(AppInfo, EdocOptsAcc) ->
  34. rebar_hooks:run_all_hooks(Cwd, pre, ?PROVIDER, Providers, AppInfo, State),
  35. AppName = ec_cnv:to_list(rebar_app_info:name(AppInfo)),
  36. ?INFO("Running edoc for ~s", [AppName]),
  37. AppDir = rebar_app_info:dir(AppInfo),
  38. ok = edoc:application(list_to_atom(AppName), AppDir, EdocOptsAcc),
  39. rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, AppInfo, State),
  40. case ShouldAccPaths of
  41. true ->
  42. %% edoc wants / on all OSes
  43. add_to_paths(EdocOptsAcc, AppDir++"/doc");
  44. false ->
  45. EdocOptsAcc
  46. end
  47. end, EdocOpts, ProjectApps),
  48. rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, State),
  49. rebar_utils:cleanup_code_path(rebar_state:code_paths(State, default)),
  50. {ok, State}.
  51. -spec format_error(any()) -> iolist().
  52. format_error(Reason) ->
  53. io_lib:format("~p", [Reason]).
  54. %% ===================================================================
  55. %% Internal functions
  56. %% ===================================================================
  57. has_configured_paths(EdocOpts) ->
  58. proplists:get_value(dir, EdocOpts) =/= undefined.
  59. add_to_paths([], Path) ->
  60. [{doc_path, [Path]}];
  61. add_to_paths([{doc_path, Paths}|T], Path) ->
  62. [{doc_path, [Path | Paths]} | T];
  63. add_to_paths([H|T], Path) ->
  64. [H | add_to_paths(Path, T)].