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

Conversation

ferd
Copy link
Collaborator

@ferd ferd commented Feb 19, 2024

The issue appears to be that because the 'clean' operation might be run while dependencies have not yet been compiled, we applied a partial app detection mechanism with rebar_app_disover:find_apps(..., ..., all, ...), which worked to parse "invalid" (unbuilt) apps, but also did not apply overrides.

Instead, we trust the install_deps provider dependency by reusing the apps as they were fully parsed if they were valid, and falling back to the rebar_app_discover:find_apps/4 call only to cover the unreadable ones.

This, it turns out, has the side effect of properly applying hooks when apps are fully parsed, and fixes #2862

In turn, this change let me fix things up such that we no longer call install_deps when just calling rebar3 clean -- we still need to call it when doing a broader clean (--apps or --all) but not when just calling it with no arguments.

@ferd
Copy link
Collaborator Author

ferd commented Feb 19, 2024

This patch currently breaks profile application with -p when cleaning and can't be merged as such.

@ferd
Copy link
Collaborator Author

ferd commented Feb 20, 2024

huh, I think this fixed the application of single app hooks by properly assigning them in the top-level app in a non-umbrella project. See how the multi app filehas a single CLEAN! hook but the single app one had two for clean while having a single one for compile.

@tsloughter I think this is fixing things properly and we'll need to update the shelltests to accomodate this.

ferd added a commit to tsloughter/rebar3_tests that referenced this pull request Feb 20, 2024
As mentioned in erlang/rebar3#2863, fixing the `clean` hooks appears to have fixed their count by properly assigning them in the top-level app in a non-umbrella project. See how [the multi app file](https:/tsloughter/rebar3_tests/blob/cba67afa851747bcdb5294c9d88c697f0d814b3c/multi_app_hooks/multi_app_hooks.test#L5) has a single `CLEAN!` hook but [the single app one had two for clean](https:/tsloughter/rebar3_tests/blob/cba67afa851747bcdb5294c9d88c697f0d814b3c/single_app_hooks/single_app_hooks.test#L5-L6) while [having a single one for compile](https:/tsloughter/rebar3_tests/blob/cba67afa851747bcdb5294c9d88c697f0d814b3c/single_app_hooks/single_app_hooks.test#L14).

This is because the discovery step we weren't doing right before the PR meant that the hook was assigned both to the project and the individual app. By fixing the detection and overrides, the hook is properly assigned to the app in a single-app project, and to the project root when in an umbrella.

This PR prepares tests to pass once the rebar3 one is merged.
@ferd
Copy link
Collaborator Author

ferd commented Feb 20, 2024

Related PR: tsloughter/rebar3_tests#20

@ferd ferd changed the title Fix clean hooks when override are presents Fix "clean" hooks in non-umbrella apps and when override are presents Feb 20, 2024
The issue appears to be that because the 'clean' operation might be run
while dependencies have not yet been compiled, we applied a partial app
detection mechanism with `rebar_app_disover:find_apps(..., ..., all,
...)`, which worked to parse "invalid" (unbuilt) apps, but also did not
apply overrides.

Instead, we trust the `install_deps` provider dependency by reusing the
apps as they were fully parsed _if_ they were valid, and falling back to
the `rebar_app_discover:find_apps/4` call only to cover the unreadable
ones.

This, it turns out, has the side effect of properly applying hooks when
apps are fully parsed, and fixes erlang#2862

Note that we can only clean paths safely if the discovery steps for the
apps is done with the right profile and options, which may also impact
configurations and hooks.

So rather than duplicating that, we invoke the 'as' provider. This also
opens the door on choosing a different provider (such as 'app_discover'
only) down the road if the -a option isn't given.
The selection is a bit coarse right now (it's possible a specific app is
not a dep but a top-level app), but we regardless keep basic cleaning
as a simple discovery step to avoid installing deps there.
ferd added a commit to tsloughter/rebar3_tests that referenced this pull request Feb 21, 2024
erlang/rebar3#2863 makes it so we stop scanning dependencies when cleaning only top-level apps.
@ferd
Copy link
Collaborator Author

ferd commented Feb 21, 2024

tsloughter/rebar3_tests#21 is needed for this to pass.

@ferd
Copy link
Collaborator Author

ferd commented Feb 21, 2024

tsloughter/rebar3_tests#22 again :(

@ferd ferd merged commit 2f1a67d into erlang:main Feb 21, 2024
6 checks passed
cannadayr added a commit to cannadayr/BeamQN that referenced this pull request May 18, 2024
Expand documentation with risks and status.
Include a local rebar3 build to include erlang/rebar3#2863.
Extend commands to use path environment variable to prevent erlang/otp header mismatch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dependency post_hooks clean override not executed.
2 participants