Refactor/simplify things since we only run one command at a time (versus a string of them)

This commit is contained in:
Dave Smith 2010-06-03 14:47:13 -06:00
parent cad24b28fc
commit 1866f65758

View file

@ -72,7 +72,7 @@ run(RawArgs) ->
?DEBUG("Rebar location: ~p\n", [rebar_config:get_global(escript, undefined)]), ?DEBUG("Rebar location: ~p\n", [rebar_config:get_global(escript, undefined)]),
%% Load rebar.config, if it exists %% Load rebar.config, if it exists
[process_dir(rebar_utils:get_cwd(), rebar_config:new(), [Command]) [process_dir(rebar_utils:get_cwd(), rebar_config:new(), Command)
|| Command <- CommandAtoms], || Command <- CommandAtoms],
ok. ok.
@ -250,7 +250,7 @@ filter_flags([Item | Rest], Commands) ->
end. end.
process_dir(Dir, ParentConfig, Commands) -> process_dir(Dir, ParentConfig, Command) ->
case filelib:is_dir(Dir) of case filelib:is_dir(Dir) of
false -> false ->
?WARN("Skipping non-existent sub-dir: ~p\n", [Dir]), ?WARN("Skipping non-existent sub-dir: ~p\n", [Dir]),
@ -279,7 +279,7 @@ process_dir(Dir, ParentConfig, Commands) ->
Modules = AnyDirModules ++ DirModules, Modules = AnyDirModules ++ DirModules,
ok = process_subdirs(Dir, Modules, Config, ModuleSetFile, Commands), ok = process_subdirs(Dir, Modules, Config, ModuleSetFile, Command),
%% Once we're all done processing, reset the code path to whatever %% Once we're all done processing, reset the code path to whatever
%% the parent initialized it to %% the parent initialized it to
@ -289,13 +289,13 @@ process_dir(Dir, ParentConfig, Commands) ->
%% %%
%% Run the preprocessors and execute commands on all newly %% Run the preprocessors and execute the command on all newly
%% found Dirs until no new Dirs are found by the preprocessors. %% found Dirs until no new Dirs are found by the preprocessors.
%% %%
process_subdirs(Dir, Modules, Config, ModuleSetFile, Commands) -> process_subdirs(Dir, Modules, Config, ModuleSetFile, Command) ->
process_subdirs(Dir, Modules, Config, ModuleSetFile, Commands, sets:new()). process_subdirs(Dir, Modules, Config, ModuleSetFile, Command, sets:new()).
process_subdirs(Dir, Modules, Config, ModuleSetFile, Commands, ProcessedDirs) -> process_subdirs(Dir, Modules, Config, ModuleSetFile, Command, ProcessedDirs) ->
%% Give the modules a chance to tweak config and indicate if there %% Give the modules a chance to tweak config and indicate if there
%% are any other dirs that might need processing first. %% are any other dirs that might need processing first.
{UpdatedConfig, Dirs} = acc_modules(select_modules(Modules, preprocess, []), {UpdatedConfig, Dirs} = acc_modules(select_modules(Modules, preprocess, []),
@ -309,7 +309,7 @@ process_subdirs(Dir, Modules, Config, ModuleSetFile, Commands, ProcessedDirs) ->
F = fun (D, S) -> F = fun (D, S) ->
case filelib:is_dir(D) andalso (not sets:is_element(D, S)) of case filelib:is_dir(D) andalso (not sets:is_element(D, S)) of
true -> true ->
process_dir(D, UpdatedConfig, Commands), process_dir(D, UpdatedConfig, Command),
sets:add_element(D, S); sets:add_element(D, S);
false -> false ->
S S
@ -320,8 +320,7 @@ process_subdirs(Dir, Modules, Config, ModuleSetFile, Commands, ProcessedDirs) ->
%% http://bitbucket.org/basho/rebar/issue/5 %% http://bitbucket.org/basho/rebar/issue/5
%% If the compiler ran, run the preprocess again because a new ebin dir %% If the compiler ran, run the preprocess again because a new ebin dir
%% may have been produced. %% may have been produced.
{UpdatedConfig1, _} = case (Dirs =/= [] andalso {UpdatedConfig1, _} = case (Dirs =/= [] andalso compile == Command) of
lists:member(compile, Commands)) of
true -> true ->
acc_modules( acc_modules(
select_modules(Modules, preprocess, []), select_modules(Modules, preprocess, []),
@ -344,8 +343,8 @@ process_subdirs(Dir, Modules, Config, ModuleSetFile, Commands, ProcessedDirs) ->
{ok, PluginModules} = plugin_modules(UpdatedConfig1), {ok, PluginModules} = plugin_modules(UpdatedConfig1),
%% Finally, process the current working directory %% Finally, process the current working directory
?DEBUG("Commands: ~p Modules: ~p Plugins: ~p\n", [Commands, Modules, PluginModules]), ?DEBUG("Command: ~p Modules: ~p Plugins: ~p\n", [Command, Modules, PluginModules]),
apply_commands(Commands, Modules ++ PluginModules, UpdatedConfig1, ModuleSetFile) apply_command(Command, Modules ++ PluginModules, UpdatedConfig1, ModuleSetFile)
end, end,
%% Repeat the process if there are new SeenDirs %% Repeat the process if there are new SeenDirs
@ -353,7 +352,7 @@ process_subdirs(Dir, Modules, Config, ModuleSetFile, Commands, ProcessedDirs) ->
true -> true ->
ok; ok;
false -> false ->
process_subdirs(Dir, Modules, UpdatedConfig1, ModuleSetFile, Commands, process_subdirs(Dir, Modules, UpdatedConfig1, ModuleSetFile, Command,
NewProcessedDirs) NewProcessedDirs)
end. end.
@ -430,14 +429,12 @@ rel_dir(Dir) ->
apply_commands([], _Modules, _Config, _ModuleFile) -> apply_command(Command, Modules, Config, ModuleFile) ->
ok;
apply_commands([Command | Rest], Modules, Config, ModuleFile) ->
case select_modules(Modules, Command, []) of case select_modules(Modules, Command, []) of
[] -> [] ->
?WARN("'~p' command does not apply to directory ~s\n", ?WARN("'~p' command does not apply to directory ~s\n",
[Command, rebar_utils:get_cwd()]), [Command, rebar_utils:get_cwd()]);
apply_commands(Rest, Modules, Config, ModuleFile);
TargetModules -> TargetModules ->
%% Provide some info on where we are %% Provide some info on where we are
Dir = rebar_utils:get_cwd(), Dir = rebar_utils:get_cwd(),
@ -446,7 +443,7 @@ apply_commands([Command | Rest], Modules, Config, ModuleFile) ->
%% Run the available modules %% Run the available modules
case catch(run_modules(TargetModules, Command, Config, ModuleFile)) of case catch(run_modules(TargetModules, Command, Config, ModuleFile)) of
ok -> ok ->
apply_commands(Rest, Modules, Config, ModuleFile); ok;
{error, failed} -> {error, failed} ->
?FAIL; ?FAIL;
Other -> Other ->