Pārlūkot izejas kodu

run legacy hooks for clean task

pull/3/head
Tristan Sloughter pirms 10 gadiem
vecāks
revīzija
920fd53397
2 mainītis faili ar 33 papildinājumiem un 37 dzēšanām
  1. +29
    -12
      src/rebar_prv_clean.erl
  2. +4
    -25
      src/rebar_prv_compile.erl

+ 29
- 12
src/rebar_prv_clean.erl Parādīt failu

@ -35,19 +35,23 @@ do(State) ->
ProjectApps = rebar_state:project_apps(State),
{all, All} = handle_args(State),
Apps = case All of
true ->
DepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIR),
DepApps = rebar_app_discover:find_apps([DepsDir], all),
ProjectApps ++ DepApps;
false ->
ProjectApps
end,
case All of
true ->
DepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIR),
DepApps = rebar_app_discover:find_apps([DepsDir], all);
false ->
DepApps = []
end,
lists:foreach(fun(AppInfo) ->
?INFO("Cleaning out ~s...~n", [rebar_app_info:name(AppInfo)]),
rebar_erlc_compiler:clean(State, ec_cnv:to_list(rebar_app_info:dir(AppInfo)))
end, Apps),
%% Need to allow global config vars used on deps
%% Right now no way to differeniate and just give deps a new state
EmptyState = rebar_state:new(),
clean_apps(EmptyState, DepApps),
Cwd = rebar_utils:get_cwd(),
rebar_hooks:run_compile_hooks(Cwd, pre_hooks, clean, State),
clean_apps(State, ProjectApps),
rebar_hooks:run_compile_hooks(Cwd, post_hooks, clean, State),
{ok, State}.
@ -59,6 +63,19 @@ format_error(Reason, State) ->
%% Internal functions
%% ===================================================================
clean_apps(State, Apps) ->
lists:foreach(fun(AppInfo) ->
AppDir = rebar_app_info:dir(AppInfo),
C = rebar_config:consult(AppDir),
S = rebar_state:new(State, C, AppDir),
?INFO("Cleaning out ~s...~n", [rebar_app_info:name(AppInfo)]),
%% Legacy hook support
rebar_hooks:run_compile_hooks(AppDir, pre_hooks, clean, S),
rebar_erlc_compiler:clean(State, ec_cnv:to_list(rebar_app_info:dir(AppInfo))),
rebar_hooks:run_compile_hooks(AppDir, post_hooks, clean, S)
end, Apps).
handle_args(State) ->
{Args, _} = rebar_state:command_parsed_args(State),
All = proplists:get_value(all, Args, false),

+ 4
- 25
src/rebar_prv_compile.erl Parādīt failu

@ -51,11 +51,11 @@ do(State) ->
%% Use the project State for building project apps
Cwd = rebar_utils:get_cwd(),
run_compile_hooks(Cwd, pre_hooks, State1),
rebar_hooks:run_compile_hooks(Cwd, pre_hooks, compile, State1),
%% Set hooks to empty so top-level hooks aren't run for each project app
State2 = rebar_state:set(rebar_state:set(State1, post_hooks, []), pre_hooks, []),
build_apps(State2, ProjectApps),
run_compile_hooks(Cwd, post_hooks, State1),
rebar_hooks:run_compile_hooks(Cwd, post_hooks, compile, State1),
{ok, State1}.
@ -70,9 +70,9 @@ build_apps(State, Apps) ->
S = rebar_state:new(State, C, AppDir),
%% Legacy hook support
run_compile_hooks(AppDir, pre_hooks, S),
rebar_hooks:run_compile_hooks(AppDir, pre_hooks, compile, S),
build(S, AppInfo),
run_compile_hooks(AppDir, post_hooks, S)
rebar_hooks:run_compile_hooks(AppDir, post_hooks, compile, S)
end, Apps).
build(State, AppInfo) ->
@ -89,24 +89,3 @@ handle_args(State) ->
{Args, _} = rebar_state:command_parsed_args(State),
Jobs = proplists:get_value(jobs, Args, ?DEFAULT_JOBS),
{ok, rebar_state:set(State, jobs, Jobs)}.
run_compile_hooks(Dir, Type, State) ->
Hooks = rebar_state:get(State, Type, []),
lists:foreach(fun({_, compile, _}=Hook) ->
apply_hook(Dir, [], Hook);
({compile, _}=Hook)->
apply_hook(Dir, [], Hook);
(_) ->
continue
end, Hooks).
apply_hook(Dir, Env, {Arch, Command, Hook}) ->
case rebar_utils:is_arch(Arch) of
true ->
apply_hook(Dir, Env, {Command, Hook});
false ->
ok
end;
apply_hook(Dir, Env, {Command, Hook}) ->
Msg = lists:flatten(io_lib:format("Hook for ~p failed!~n", [Command])),
rebar_utils:sh(Hook, [{cd, Dir}, {env, Env}, {abort_on_error, Msg}]).

Notiek ielāde…
Atcelt
Saglabāt