mirror of
https://github.com/correl/rebar.git
synced 2024-11-23 19:19:54 +00:00
More work on getting compilation and clean working properly
This commit is contained in:
parent
e52bb6783c
commit
620867d5d5
3 changed files with 37 additions and 19 deletions
46
priv/rebar
46
priv/rebar
|
@ -28,12 +28,9 @@
|
||||||
|
|
||||||
-include_lib("rebar/include/rebar.hrl").
|
-include_lib("rebar/include/rebar.hrl").
|
||||||
|
|
||||||
main([CommandStr | _Args]) ->
|
main(Commands) ->
|
||||||
%% Pre-load the rebar app so that we get default configuration
|
%% Pre-load the rebar app so that we get default configuration
|
||||||
application:load(rebar),
|
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
|
%% From the current working directory, search recursively and find
|
||||||
%% all the application and release directories. We always terminate the
|
%% all the application and release directories. We always terminate the
|
||||||
|
@ -46,18 +43,14 @@ main([CommandStr | _Args]) ->
|
||||||
Targets = [{Type, Cwd, Filename}]
|
Targets = [{Type, Cwd, Filename}]
|
||||||
end,
|
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
|
%% Prefix all the app targets to the code path so that inter-app compilation
|
||||||
%% works properly
|
%% works properly
|
||||||
update_code_path(FilteredTargets),
|
update_code_path(Targets),
|
||||||
|
|
||||||
%% Finally, apply the specified command to each target
|
%% Finally, apply the specified command to each target
|
||||||
apply_command(FilteredTargets, Command);
|
apply_commands(Targets, Commands);
|
||||||
main(_) ->
|
main(_) ->
|
||||||
io:format("usage: rebar <command>\n").
|
io:format("usage: rebar <command>...\n").
|
||||||
|
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
@ -65,25 +58,27 @@ main(_) ->
|
||||||
%%
|
%%
|
||||||
find_targets(Root) ->
|
find_targets(Root) ->
|
||||||
{ok, Files} = file:list_dir(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;
|
Acc;
|
||||||
find_targets([F | Rest], Root, Acc) ->
|
find_targets(_Files, _Root, Acc, 10) ->
|
||||||
|
Acc;
|
||||||
|
find_targets([F | Rest], Root, Acc, Depth) ->
|
||||||
AbsName = filename:join([Root, F]),
|
AbsName = filename:join([Root, F]),
|
||||||
case target_type(AbsName) of
|
case target_type(AbsName) of
|
||||||
undefined ->
|
undefined ->
|
||||||
case filelib:is_dir(AbsName) of
|
case filelib:is_dir(AbsName) of
|
||||||
true ->
|
true ->
|
||||||
{ok, SubFiles} = file:list_dir(AbsName),
|
{ok, SubFiles} = file:list_dir(AbsName),
|
||||||
Acc2 = find_targets(SubFiles, AbsName, Acc);
|
Acc2 = find_targets(SubFiles, AbsName, Acc, Depth+1);
|
||||||
false ->
|
false ->
|
||||||
Acc2 = Acc
|
Acc2 = Acc
|
||||||
end;
|
end;
|
||||||
{Type, Filename} ->
|
{Type, Filename} ->
|
||||||
Acc2 = [{Type, AbsName, Filename} | Acc]
|
Acc2 = [{Type, AbsName, Filename} | Acc]
|
||||||
end,
|
end,
|
||||||
find_targets(Rest, Root, Acc2).
|
find_targets(Rest, Root, Acc2, Depth).
|
||||||
|
|
||||||
%%
|
%%
|
||||||
%% Determine the target type of a given file: app, rel or undefined
|
%% Determine the target type of a given file: app, rel or undefined
|
||||||
|
@ -123,12 +118,31 @@ update_code_path([_ | Rest]) ->
|
||||||
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) ->
|
apply_command([], _Command) ->
|
||||||
ok;
|
ok;
|
||||||
apply_command([{Type, Dir, File} | Rest], Command) ->
|
apply_command([{Type, Dir, File} | Rest], Command) ->
|
||||||
ok = file:set_cwd(Dir),
|
ok = file:set_cwd(Dir),
|
||||||
Config = rebar_config:new(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
|
%% 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.
|
%% will be inspected for a function matching Command and if found, will execute that.
|
||||||
Modules = rebar_config:get_modules(Config, Type),
|
Modules = rebar_config:get_modules(Config, Type),
|
||||||
|
|
|
@ -40,11 +40,14 @@ compile(Config, Dir) ->
|
||||||
fun compile_mib/2).
|
fun compile_mib/2).
|
||||||
|
|
||||||
clean(Config, Dir) ->
|
clean(Config, Dir) ->
|
||||||
% rebar_utils:delete_files("ebin/*.beam"),
|
%% TODO: This would be more portable if it used Erlang to traverse
|
||||||
% rebar_utils:delete_files("priv/mibs/*.bin").
|
%% the dir structure and delete each file; however it would also
|
||||||
|
%% much slower.
|
||||||
|
[] = os:cmd("rm -f ebin/*.beam priv/mibs/*.bin"),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
|
@ -96,7 +99,7 @@ compile_erl(Source, Config) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
compile_mib(Source, Config) ->
|
compile_mib(Source, Config) ->
|
||||||
Opts = meab_config:get_list(mibc_opts, []),
|
Opts = rebar_config:get_list(Config, mibc_opts, []),
|
||||||
case snmpc:compile(Source, [{outdir, "priv/mibs"}, {i, ["priv/mibs"]}] ++ Opts) of
|
case snmpc:compile(Source, [{outdir, "priv/mibs"}, {i, ["priv/mibs"]}] ++ Opts) of
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
ok;
|
ok;
|
||||||
|
|
|
@ -29,3 +29,4 @@
|
||||||
get_cwd() ->
|
get_cwd() ->
|
||||||
{ok, Dir} = file:get_cwd(),
|
{ok, Dir} = file:get_cwd(),
|
||||||
Dir.
|
Dir.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue