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

Test and improve the merging of package configuration patches #348

Conversation

primeos-work
Copy link
Member

@primeos-work primeos-work commented Feb 21, 2024

This adds test to ensure the additional logic for handling/merging the patches value (array) in pkg.toml works correctly, simplifies the code (especially to make it more readable / easier to understand), and fixes a bug (minor as it's a special case).

Edit: The bugfix could be considered a bit of a breaking change but I consider it self-documenting as it results in a easy to understand error message if invalid (non-existent) patches are specified, e.g. (I added the pkg.toml file path to the output):

Error: The patch is declared here: examples/packages/repo/s/19.1/pkg.toml

Caused by:
    Patch does not exist: examples/packages/repo/s/19.1/./foo.patch

I recently looked into this when trying to update the `config` crate and
noticed that the "merging" is more of an anti-feature (IMO). This
demonstrates the surprising behavior of the extra check based on the
file/base name of the patch.

Signed-off-by: Michael Weiss <michael.weiss@eviden.com>
The old logic silently ignored a patch if a patch with the same name was
declared in an upper level/layer package configuration.
This fixes that issue and I now know why that "else if" branch exists:
The `config.set_once("patches", config::Value::from(patches))` didn't
last beyond the next `config.merge()` so the custom logic is required to
ensure that `patches` will be empty so that `patches_before_merge` (with
the value from `config.set_once()`) gets used instead.

I'm now using `config.merge()` to properly update `patches` so that we
can simply check if `patches_before_merge == patches` (i.e., no changes
occurred after merging the next `pkg.toml` file).
This looks a bit more complex at first but can be cleaned up next and I
hope that newer versions of the `config` crate make this easier for us
(we can really simplify the code if we can request the source (file path
of the `pkg.toml` file) that set the final `patches` value).

I can also "fix" the tests now that the "merging" works as intended.

Signed-off-by: Michael Weiss <michael.weiss@eviden.com>
This keeps the logic from the previous commit but restructures/reorders
the code to make it much more readable.

Signed-off-by: Michael Weiss <michael.weiss@eviden.com>
@primeos-work primeos-work added this pull request to the merge queue Feb 21, 2024
Merged via the queue into science-computing:master with commit c4e7156 Feb 21, 2024
13 checks passed
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.

None yet

1 participant