summaryrefslogtreecommitdiff
path: root/priv
diff options
context:
space:
mode:
authorDave Smith <dizzyd@dizzyd.com>2009-11-25 20:24:51 -0700
committerDave Smith <dizzyd@dizzyd.com>2009-11-25 20:24:51 -0700
commit620867d5d511e1c6e962f54e7f53a3b2ae2a052e (patch)
tree362782b713719cfef7db6b6cda7afc8398427065 /priv
parente52bb6783c34e1bacd419d787ee8fbad0a394624 (diff)
More work on getting compilation and clean working properly
Diffstat (limited to 'priv')
-rwxr-xr-xpriv/rebar46
1 files changed, 30 insertions, 16 deletions
diff --git a/priv/rebar b/priv/rebar
index f911966..a9e229f 100755
--- a/priv/rebar
+++ b/priv/rebar
@@ -28,12 +28,9 @@
-include_lib("rebar/include/rebar.hrl").
-main([CommandStr | _Args]) ->
+main(Commands) ->
%% Pre-load the rebar app so that we get default configuration
application:load(rebar),
-
- %% Convert the command into an atom for convenience
- Command = list_to_atom(CommandStr),
%% From the current working directory, search recursively and find
%% all the application and release directories. We always terminate the
@@ -46,18 +43,14 @@ main([CommandStr | _Args]) ->
Targets = [{Type, Cwd, Filename}]
end,
- %% Filter out all the targets, based on the specified command.
- FilteredTargets = [{Type, Dir, Filename} || {Type, Dir, Filename} <- Targets,
- valid_command(Command, Type) == true],
-
%% Prefix all the app targets to the code path so that inter-app compilation
%% works properly
- update_code_path(FilteredTargets),
+ update_code_path(Targets),
%% Finally, apply the specified command to each target
- apply_command(FilteredTargets, Command);
+ apply_commands(Targets, Commands);
main(_) ->
- io:format("usage: rebar <command>\n").
+ io:format("usage: rebar <command>...\n").
%%
@@ -65,25 +58,27 @@ main(_) ->
%%
find_targets(Root) ->
{ok, Files} = file:list_dir(Root),
- find_targets(Files, Root, []).
+ find_targets(Files, Root, [], 1).
-find_targets([], _Root, Acc) ->
+find_targets([], _Root, Acc, _Depth) ->
+ Acc;
+find_targets(_Files, _Root, Acc, 10) ->
Acc;
-find_targets([F | Rest], Root, Acc) ->
+find_targets([F | Rest], Root, Acc, Depth) ->
AbsName = filename:join([Root, F]),
case target_type(AbsName) of
undefined ->
case filelib:is_dir(AbsName) of
true ->
{ok, SubFiles} = file:list_dir(AbsName),
- Acc2 = find_targets(SubFiles, AbsName, Acc);
+ Acc2 = find_targets(SubFiles, AbsName, Acc, Depth+1);
false ->
Acc2 = Acc
end;
{Type, Filename} ->
Acc2 = [{Type, AbsName, Filename} | Acc]
end,
- find_targets(Rest, Root, Acc2).
+ find_targets(Rest, Root, Acc2, Depth).
%%
%% Determine the target type of a given file: app, rel or undefined
@@ -123,12 +118,31 @@ update_code_path([_ | Rest]) ->
update_code_path(Rest).
+apply_commands(_Targets, []) ->
+ ok;
+apply_commands(Targets, [CommandStr | Rest]) ->
+ %% Convert the command into an atom for convenience
+ Command = list_to_atom(CommandStr),
+
+ %% Filter out all the targets, based on the specified command.
+ FilteredTargets = [{Type, Dir, Filename} || {Type, Dir, Filename} <- Targets,
+ valid_command(Command, Type) == true],
+ case apply_command(FilteredTargets, Command) of
+ ok ->
+ apply_commands(Targets, Rest);
+ Other ->
+ Other
+ end.
+
apply_command([], _Command) ->
ok;
apply_command([{Type, Dir, File} | Rest], Command) ->
ok = file:set_cwd(Dir),
Config = rebar_config:new(Dir),
+ %% Provide some info on where we are
+ ?CONSOLE("==> ~s (~s)\n", [filename:basename(Dir), Command]),
+
%% Pull the list of modules that are associated with Type operations. Each module
%% will be inspected for a function matching Command and if found, will execute that.
Modules = rebar_config:get_modules(Config, Type),