Skip to content

Commit b6454c1

Browse files
authored
Merge pull request #2702 from ferd/vendor-plugin-support
Support plugins in experimental vendor provider
2 parents d574535 + 12bf539 commit b6454c1

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

src/rebar_prv_vendor.erl

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,34 @@ do_(InitState) ->
5757
RootDir = rebar_dir:root_dir(InitState),
5858
VendorDir = filename:join(RootDir, "vendor"),
5959
VendorBak = filename:join(RootDir, "_vendor"),
60-
catch rebar_file_utils:rm_rf(VendorBak),
61-
catch rebar_file_utils:mv(VendorDir, VendorBak),
60+
PluginVDir = filename:join(RootDir, "vendor_plugins"),
61+
PluginVBak = filename:join(RootDir, "_vendor_plugins"),
62+
filelib:is_dir(VendorBak) andalso rebar_file_utils:rm_rf(VendorBak),
63+
filelib:is_dir(VendorDir) andalso rebar_file_utils:mv(VendorDir, VendorBak),
64+
filelib:is_dir(PluginVBak) andalso rebar_file_utils:rm_rf(PluginVBak),
65+
filelib:is_dir(PluginVDir) andalso rebar_file_utils:mv(PluginVDir, PluginVBak),
6266
filelib:ensure_dir(filename:join(VendorDir, ".touch")),
67+
filelib:ensure_dir(filename:join(PluginVDir, ".touch")),
6368
%% remove the src_dirs option for vendored files
6469
CleanDirs = rebar_dir:lib_dirs(InitState) -- ["vendor/*"],
65-
CleanState = rebar_state:set(InitState, project_app_dirs, CleanDirs),
70+
CleanStateTmp = rebar_state:set(InitState, project_app_dirs, CleanDirs),
71+
CleanPlugins = rebar_dir:project_plugin_dirs(InitState) -- ["vendor_plugins/*"],
72+
CleanState = rebar_state:set(CleanStateTmp, project_plugin_dirs, CleanPlugins),
73+
%% re-install non-local plugins, assume the already-loaded project plugins
74+
%% we dropped are fine in memory
75+
TmpState1 = rebar_plugins:top_level_install(CleanState),
6676
%% re-run discovery
67-
{ok, TmpState1} = rebar_prv_app_discovery:do(CleanState),
77+
{ok, TmpState2} = rebar_prv_app_discovery:do(TmpState1),
6878
%% run a full fetch (which implicitly upgrades, since the lock file
6979
%% should be unset for any vendored app)
70-
{ok, TmpState2} = rebar_prv_install_deps:do(TmpState1),
80+
{ok, TmpState3} = rebar_prv_install_deps:do(TmpState2),
81+
%% move the plugins to the vendor path
82+
%% The plugins aren't tracked as nicely as the deps (no lock file) and
83+
%% there isn't a preset function to grab them all, so we'll instead
84+
%% copy everything that was in the plugin directory.
85+
vendor_plugins(TmpState3, PluginVDir),
7186
%% move the libs to the vendor path
72-
AllDeps = rebar_state:lock(TmpState2),
87+
AllDeps = rebar_state:lock(TmpState3),
7388
[begin
7489
AppDir = rebar_app_info:dir(Dep),
7590
NewAppDir = filename:join(VendorDir, filename:basename(AppDir)),
@@ -79,12 +94,15 @@ do_(InitState) ->
7994
%% -- we don't actually want to mess with the user's file so we have to
8095
%% let them know what it should be:
8196
NewAppDirs = CleanDirs ++ ["vendor/*"],
97+
NewPluginDirs = CleanPlugins ++ ["vendor_plugins/*"],
8298
?CONSOLE("Vendoring in place. To use the vendored libraries, configure "
8399
"the source application directories for your project with:~n~n"
84-
"{project_app_dirs, ~p}.~n~n"
100+
"{project_app_dirs, ~p}.~n"
101+
"{project_plugin_dirs, ~p}.~n"
102+
"~n"
85103
"and move the {deps, ...} tuple to the rebar.config files "
86104
"of the proper top-level applications rather than the project root.",
87-
[NewAppDirs]),
105+
[NewAppDirs, NewPluginDirs]),
88106
State1 = rebar_state:set(InitState, project_app_dirs, NewAppDirs),
89107
{ok, State1}.
90108

@@ -117,3 +135,11 @@ check_project_layout(State) ->
117135
end
118136
end.
119137

138+
vendor_plugins(State, PluginVDir) ->
139+
PluginDir = rebar_dir:plugins_dir(State),
140+
{ok, Files} = file:list_dir_all(PluginDir),
141+
[rebar_file_utils:mv(Path, filename:join(PluginVDir, PathPart))
142+
|| PathPart <- Files,
143+
Path <- [filename:join(PluginDir, PathPart)],
144+
filelib:is_dir(Path)],
145+
ok.

0 commit comments

Comments
 (0)