mirror of
https://github.com/correl/rebar.git
synced 2024-12-18 11:06:20 +00:00
Merge pull request #38 from tuncer/fix-sub_dir-association
rebar_core: fix sub dir association
This commit is contained in:
commit
21038d537c
1 changed files with 24 additions and 24 deletions
|
@ -139,21 +139,21 @@ process_dir(Dir, ParentConfig, Command, DirSet) ->
|
||||||
{ok, AvailModuleSets} = application:get_env(rebar, modules),
|
{ok, AvailModuleSets} = application:get_env(rebar, modules),
|
||||||
ModuleSet = choose_module_set(AvailModuleSets, Dir),
|
ModuleSet = choose_module_set(AvailModuleSets, Dir),
|
||||||
skip_or_process_dir(ModuleSet, Config, CurrentCodePath,
|
skip_or_process_dir(ModuleSet, Config, CurrentCodePath,
|
||||||
Dir, Command, DirSet)
|
Dir, Command, DirSet)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
skip_or_process_dir({[], undefined}=ModuleSet, Config, CurrentCodePath,
|
skip_or_process_dir({[], undefined}=ModuleSet, Config, CurrentCodePath,
|
||||||
Dir, Command, DirSet) ->
|
Dir, Command, DirSet) ->
|
||||||
process_dir1(Dir, Command, DirSet, Config, CurrentCodePath, ModuleSet);
|
process_dir1(Dir, Command, DirSet, Config, CurrentCodePath, ModuleSet);
|
||||||
skip_or_process_dir({_, ModuleSetFile}=ModuleSet, Config, CurrentCodePath,
|
skip_or_process_dir({_, ModuleSetFile}=ModuleSet, Config, CurrentCodePath,
|
||||||
Dir, Command, DirSet) ->
|
Dir, Command, DirSet) ->
|
||||||
case lists:suffix(".app.src", ModuleSetFile)
|
case lists:suffix(".app.src", ModuleSetFile)
|
||||||
orelse lists:suffix(".app", ModuleSetFile) of
|
orelse lists:suffix(".app", ModuleSetFile) of
|
||||||
true ->
|
true ->
|
||||||
%% .app or .app.src file, check if is_skipped_app
|
%% .app or .app.src file, check if is_skipped_app
|
||||||
skip_or_process_dir1(ModuleSetFile, ModuleSet,
|
skip_or_process_dir1(ModuleSetFile, ModuleSet,
|
||||||
Config, CurrentCodePath, Dir,
|
Config, CurrentCodePath, Dir,
|
||||||
Command, DirSet);
|
Command, DirSet);
|
||||||
false ->
|
false ->
|
||||||
%% not an app dir, no need to consider apps=/skip_apps=
|
%% not an app dir, no need to consider apps=/skip_apps=
|
||||||
process_dir1(Dir, Command, DirSet, Config,
|
process_dir1(Dir, Command, DirSet, Config,
|
||||||
|
@ -161,7 +161,7 @@ skip_or_process_dir({_, ModuleSetFile}=ModuleSet, Config, CurrentCodePath,
|
||||||
end.
|
end.
|
||||||
|
|
||||||
skip_or_process_dir1(AppFile, ModuleSet, Config, CurrentCodePath,
|
skip_or_process_dir1(AppFile, ModuleSet, Config, CurrentCodePath,
|
||||||
Dir, Command, DirSet) ->
|
Dir, Command, DirSet) ->
|
||||||
case rebar_app_utils:is_skipped_app(Config, AppFile) of
|
case rebar_app_utils:is_skipped_app(Config, AppFile) of
|
||||||
{Config1, {true, SkippedApp}} ->
|
{Config1, {true, SkippedApp}} ->
|
||||||
?DEBUG("Skipping app: ~p~n", [SkippedApp]),
|
?DEBUG("Skipping app: ~p~n", [SkippedApp]),
|
||||||
|
@ -187,11 +187,12 @@ process_dir1(Dir, Command, DirSet, Config0, CurrentCodePath,
|
||||||
{Config1, Predirs} = acc_modules(Modules, preprocess, Config0,
|
{Config1, Predirs} = acc_modules(Modules, preprocess, Config0,
|
||||||
ModuleSetFile),
|
ModuleSetFile),
|
||||||
|
|
||||||
SubdirAssoc = remember_cwd_subdir(Dir, Predirs),
|
%% Remember associated pre-dirs (used for plugin lookup)
|
||||||
|
PredirsAssoc = remember_cwd_predirs(Dir, Predirs),
|
||||||
|
|
||||||
%% Get the list of plug-in modules from rebar.config. These
|
%% Get the list of plug-in modules from rebar.config. These
|
||||||
%% modules may participate in preprocess and postprocess.
|
%% modules may participate in preprocess and postprocess.
|
||||||
{ok, PluginModules} = plugin_modules(Config1, SubdirAssoc),
|
{ok, PluginModules} = plugin_modules(Config1, PredirsAssoc),
|
||||||
|
|
||||||
{Config2, PluginPredirs} = acc_modules(PluginModules, preprocess,
|
{Config2, PluginPredirs} = acc_modules(PluginModules, preprocess,
|
||||||
Config1, ModuleSetFile),
|
Config1, ModuleSetFile),
|
||||||
|
@ -253,7 +254,7 @@ process_dir1(Dir, Command, DirSet, Config0, CurrentCodePath,
|
||||||
%% Return the updated {config, dirset} as result
|
%% Return the updated {config, dirset} as result
|
||||||
Res.
|
Res.
|
||||||
|
|
||||||
remember_cwd_subdir(Cwd, Subdirs) ->
|
remember_cwd_predirs(Cwd, Predirs) ->
|
||||||
Store = fun(Dir, Dict) ->
|
Store = fun(Dir, Dict) ->
|
||||||
case dict:find(Dir, Dict) of
|
case dict:find(Dir, Dict) of
|
||||||
error ->
|
error ->
|
||||||
|
@ -264,11 +265,10 @@ remember_cwd_subdir(Cwd, Subdirs) ->
|
||||||
?ABORT("Internal consistency assertion failed.~n"
|
?ABORT("Internal consistency assertion failed.~n"
|
||||||
"sub_dir ~s already associated with ~s.~n"
|
"sub_dir ~s already associated with ~s.~n"
|
||||||
"Duplicate sub_dirs or deps entries?",
|
"Duplicate sub_dirs or deps entries?",
|
||||||
[Dir, Existing]),
|
[Dir, Existing])
|
||||||
Dict
|
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
lists:foldl(Store, dict:new(), Subdirs).
|
lists:foldl(Store, dict:new(), Predirs).
|
||||||
|
|
||||||
maybe_load_local_config(Dir, ParentConfig) ->
|
maybe_load_local_config(Dir, ParentConfig) ->
|
||||||
%% We need to ensure we don't overwrite custom
|
%% We need to ensure we don't overwrite custom
|
||||||
|
@ -488,9 +488,9 @@ acc_modules([Module | Rest], Command, Config, File, Acc) ->
|
||||||
%%
|
%%
|
||||||
%% Return a flat list of rebar plugin modules.
|
%% Return a flat list of rebar plugin modules.
|
||||||
%%
|
%%
|
||||||
plugin_modules(Config, SubdirAssoc) ->
|
plugin_modules(Config, PredirsAssoc) ->
|
||||||
Modules = lists:flatten(rebar_config:get_all(Config, plugins)),
|
Modules = lists:flatten(rebar_config:get_all(Config, plugins)),
|
||||||
plugin_modules(Config, SubdirAssoc, ulist(Modules)).
|
plugin_modules(Config, PredirsAssoc, ulist(Modules)).
|
||||||
|
|
||||||
ulist(L) ->
|
ulist(L) ->
|
||||||
ulist(L, []).
|
ulist(L, []).
|
||||||
|
@ -505,16 +505,16 @@ ulist([H | T], Acc) ->
|
||||||
ulist(T, [H | Acc])
|
ulist(T, [H | Acc])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
plugin_modules(_Config, _SubdirAssoc, []) ->
|
plugin_modules(_Config, _PredirsAssoc, []) ->
|
||||||
{ok, []};
|
{ok, []};
|
||||||
plugin_modules(Config, SubdirAssoc, Modules) ->
|
plugin_modules(Config, PredirsAssoc, Modules) ->
|
||||||
FoundModules = [M || M <- Modules, code:which(M) =/= non_existing],
|
FoundModules = [M || M <- Modules, code:which(M) =/= non_existing],
|
||||||
plugin_modules(Config, SubdirAssoc, FoundModules, Modules -- FoundModules).
|
plugin_modules(Config, PredirsAssoc, FoundModules, Modules -- FoundModules).
|
||||||
|
|
||||||
plugin_modules(_Config, _SubdirAssoc, FoundModules, []) ->
|
plugin_modules(_Config, _PredirsAssoc, FoundModules, []) ->
|
||||||
{ok, FoundModules};
|
{ok, FoundModules};
|
||||||
plugin_modules(Config, SubdirAssoc, FoundModules, MissingModules) ->
|
plugin_modules(Config, PredirsAssoc, FoundModules, MissingModules) ->
|
||||||
{Loaded, NotLoaded} = load_plugin_modules(Config, SubdirAssoc,
|
{Loaded, NotLoaded} = load_plugin_modules(Config, PredirsAssoc,
|
||||||
MissingModules),
|
MissingModules),
|
||||||
AllViablePlugins = FoundModules ++ Loaded,
|
AllViablePlugins = FoundModules ++ Loaded,
|
||||||
case NotLoaded =/= [] of
|
case NotLoaded =/= [] of
|
||||||
|
@ -528,7 +528,7 @@ plugin_modules(Config, SubdirAssoc, FoundModules, MissingModules) ->
|
||||||
end,
|
end,
|
||||||
{ok, AllViablePlugins}.
|
{ok, AllViablePlugins}.
|
||||||
|
|
||||||
load_plugin_modules(Config, SubdirAssoc, Modules) ->
|
load_plugin_modules(Config, PredirsAssoc, Modules) ->
|
||||||
Cwd = rebar_utils:get_cwd(),
|
Cwd = rebar_utils:get_cwd(),
|
||||||
PluginDir = case rebar_config:get_local(Config, plugin_dir, undefined) of
|
PluginDir = case rebar_config:get_local(Config, plugin_dir, undefined) of
|
||||||
undefined ->
|
undefined ->
|
||||||
|
@ -540,7 +540,7 @@ load_plugin_modules(Config, SubdirAssoc, Modules) ->
|
||||||
%% Find relevant sources in base_dir and plugin_dir
|
%% Find relevant sources in base_dir and plugin_dir
|
||||||
Erls = string:join([atom_to_list(M)++"\\.erl" || M <- Modules], "|"),
|
Erls = string:join([atom_to_list(M)++"\\.erl" || M <- Modules], "|"),
|
||||||
RE = "^" ++ Erls ++ "\$",
|
RE = "^" ++ Erls ++ "\$",
|
||||||
BaseDir = get_plugin_base_dir(Cwd, SubdirAssoc),
|
BaseDir = get_plugin_base_dir(Cwd, PredirsAssoc),
|
||||||
%% If a plugin is found both in base_dir and plugin_dir, the clash
|
%% If a plugin is found both in base_dir and plugin_dir, the clash
|
||||||
%% will provoke an error and we'll abort.
|
%% will provoke an error and we'll abort.
|
||||||
Sources = rebar_utils:find_files(PluginDir, RE, false)
|
Sources = rebar_utils:find_files(PluginDir, RE, false)
|
||||||
|
@ -552,8 +552,8 @@ load_plugin_modules(Config, SubdirAssoc, Modules) ->
|
||||||
NotLoaded = [V || V <- Modules, FilterMissing(V)],
|
NotLoaded = [V || V <- Modules, FilterMissing(V)],
|
||||||
{Loaded, NotLoaded}.
|
{Loaded, NotLoaded}.
|
||||||
|
|
||||||
get_plugin_base_dir(Cwd, SubdirAssoc) ->
|
get_plugin_base_dir(Cwd, PredirsAssoc) ->
|
||||||
case dict:find(Cwd, SubdirAssoc) of
|
case dict:find(Cwd, PredirsAssoc) of
|
||||||
{ok, BaseDir} ->
|
{ok, BaseDir} ->
|
||||||
BaseDir;
|
BaseDir;
|
||||||
error ->
|
error ->
|
||||||
|
|
Loading…
Reference in a new issue