Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

101 строка
4.3 KiB

10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
  1. %% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
  2. %% ex: ts=4 sw=4 et
  3. %% -------------------------------------------------------------------
  4. %%
  5. %% rebar: Erlang Build Tools
  6. %%
  7. %% Copyright (c) 2009 Dave Smith (dizzyd@dizzyd.com)
  8. %%
  9. %% Permission is hereby granted, free of charge, to any person obtaining a copy
  10. %% of this software and associated documentation files (the "Software"), to deal
  11. %% in the Software without restriction, including without limitation the rights
  12. %% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. %% copies of the Software, and to permit persons to whom the Software is
  14. %% furnished to do so, subject to the following conditions:
  15. %%
  16. %% The above copyright notice and this permission notice shall be included in
  17. %% all copies or substantial portions of the Software.
  18. %%
  19. %% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. %% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. %% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. %% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. %% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. %% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. %% THE SOFTWARE.
  26. %% -------------------------------------------------------------------
  27. -module(rebar_core).
  28. -export([process_command/2
  29. ,update_code_path/1]).
  30. -include("rebar.hrl").
  31. -spec process_command(rebar_state:t(), atom()) -> {ok, rebar_state:t()} | {error, string()}.
  32. process_command(State, Command) ->
  33. %% ? rebar_prv_install_deps:setup_env(State),
  34. Providers = rebar_state:providers(State),
  35. TargetProviders = providers:get_target_providers(Command, Providers),
  36. case providers:get_provider(Command, Providers) of
  37. not_found ->
  38. {error, io_lib:format("Command ~p not found", [Command])};
  39. CommandProvider ->
  40. case Command of
  41. Command when Command =:= do
  42. ; Command =:= as ->
  43. do(TargetProviders, State);
  44. _ ->
  45. Profile = providers:profile(CommandProvider),
  46. State1 = rebar_state:apply_profiles(State, [Profile]),
  47. Opts = providers:opts(CommandProvider)++rebar3:global_option_spec_list(),
  48. case getopt:parse(Opts, rebar_state:command_args(State1)) of
  49. {ok, Args} ->
  50. State2 = rebar_state:command_parsed_args(State1, Args),
  51. do(TargetProviders, State2);
  52. {error, {invalid_option, Option}} ->
  53. {error, io_lib:format("Invalid option ~s on task ~p", [Option, Command])}
  54. end
  55. end
  56. end.
  57. -spec do([{atom(), atom()}], rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
  58. do([], State) ->
  59. {ok, State};
  60. do([{ProviderName, _} | Rest], State) ->
  61. Provider = providers:get_provider(ProviderName
  62. ,rebar_state:providers(State)),
  63. case providers:do(Provider, State) of
  64. {ok, State1} ->
  65. do(Rest, State1);
  66. {error, Error} ->
  67. {error, Error}
  68. end.
  69. update_code_path(State) ->
  70. true = rebar_utils:expand_code_path(),
  71. LibDirs = rebar_dir:lib_dirs(State),
  72. DepsDir = rebar_dir:deps_dir(State),
  73. PluginsDir = rebar_dir:plugins_dir(State),
  74. _UpdatedCodePaths = update_code_path_(lists:usort([DepsDir, PluginsDir | LibDirs])).
  75. %% ===================================================================
  76. %% Internal functions
  77. %% ===================================================================
  78. update_code_path_(Paths) ->
  79. LibPaths = expand_lib_dirs(Paths, rebar_dir:get_cwd(), []),
  80. ok = code:add_pathsa(LibPaths),
  81. %% track just the paths we added, so we can remove them without
  82. %% removing other paths added by this dep
  83. {added, LibPaths}.
  84. expand_lib_dirs([], _Root, Acc) ->
  85. Acc;
  86. expand_lib_dirs([Dir | Rest], Root, Acc) ->
  87. Apps = filelib:wildcard(filename:join([Dir, "*", "ebin"])),
  88. FqApps = case filename:pathtype(Dir) of
  89. absolute -> Apps;
  90. _ -> [filename:join([Root, A]) || A <- Apps]
  91. end,
  92. expand_lib_dirs(Rest, Root, Acc ++ FqApps).