Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "clean" hooks in non-umbrella apps and when override are presents #2863

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions apps/rebar/src/rebar_prv_clean.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
-include("rebar.hrl").

-define(PROVIDER, clean).
-define(DEPS, [app_discovery, install_deps]).
-define(DEPS, []).

%% ===================================================================
%% Public API
Expand All @@ -37,15 +37,31 @@ do(State) ->
Providers = rebar_state:providers(State),
{All, Profiles, Specific} = handle_args(State),

State1 = rebar_state:apply_profiles(State, [list_to_atom(X) || X <- Profiles]),
%% Invoke provider deps as the desired profile(s) so the discovery of
%% apps respects profile options.
Task = if All; Specific =/= [] -> "install_deps";
true -> "app_discovery"
end,
State0 = rebar_state:command_args(
State,
lists:join(",", ["default"|Profiles]) ++ [Task]
),
{ok, State1} = rebar_prv_as:do(State0),

Cwd = rebar_dir:get_cwd(),
rebar_hooks:run_all_hooks(Cwd, pre, ?PROVIDER, Providers, State1),

if All; Specific =/= [] ->
DepsDir = rebar_dir:deps_dir(State1),
DepsDirs = filelib:wildcard(filename:join(DepsDir, "*")),
AllApps = rebar_app_discover:find_apps(DepsDirs, all, State),
ProjectApps = rebar_state:project_apps(State1),
Deps = rebar_state:all_deps(State1),
KnownAppNames = [rebar_app_info:name(App) || App <- ProjectApps++Deps],
ParsedApps = rebar_app_discover:find_apps(DepsDirs, all, State1),
AllApps = ProjectApps ++ Deps ++
[App || App <- ParsedApps,
not lists:member(rebar_app_info:name(App),
KnownAppNames)],
Filter = case All of
true -> fun(_) -> true end;
false -> fun(AppInfo) -> filter_name(AppInfo, Specific) end
Expand Down
3 changes: 2 additions & 1 deletion apps/rebar/test/rebar_as_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,5 @@ clean_as_profile(Config) ->
rebar_test_utils:run_and_check(Config,
[],
["clean", "-a", "-p", "foo"],
{ok, [{app, Name, invalid}]}).
{ok, [{app, Name, invalid}]}),
ok.
9 changes: 8 additions & 1 deletion apps/rebar/test/rebar_hooks_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,17 @@ deps_clean_hook_namespace(Config) ->
]}
]}
],
%% Only detect dependencies when asked to parse them.
%% Avoids scanning and fetching them only to clean them.
rebar_test_utils:run_and_check(
Config, RebarConfig, ["clean"],
{ok, [{dep_not_exist, "some_dep"}]}
),
rebar_test_utils:run_and_check(
Config, RebarConfig, ["clean", "-a"],
{ok, [{dep, "some_dep"}]}
).
),
ok.

%% Checks that a hook that is defined on an app (not a top level hook of a project with subapps) is run
eunit_app_hooks(Config) ->
Expand Down
Loading