Skip to content

when: deal with % vs. ^ correctly#51259

Merged
haampie merged 6 commits intospack:developfrom
alalazo:refactor/simplify-when-context
Sep 2, 2025
Merged

when: deal with % vs. ^ correctly#51259
haampie merged 6 commits intospack:developfrom
alalazo:refactor/simplify-when-context

Conversation

@alalazo
Copy link
Copy Markdown
Member

@alalazo alalazo commented Sep 1, 2025

builds on #51256

#51256 solves the most common bug in the when context manager, i.e. the case of a single % used in a constraint spec, but doesn't do anything for other, less common, cases where % is treated incorrectly.

Here we fix those cases too, by removing the ad-hoc merge_abstract_anonymous_specs function, and using Spec.constrain instead. To do so we had to:

  1. Implement Spec.satisfies, Spec.constrain, and Spec.intersects in terms a private function with an additional argument, i.e. resolve_virtuals.
  2. Use Spec._constrain with resolve_virtuals=False in the context of evaluating directives

The PR is separate from #51256 because it involves code changes that touch functions that are widely use, which may be a source of bugs, so we may want to avoid backporting this.

Other changes:

  • Spec.common_dependencies, Spec.direct_dep_difference have been removed since they are unused, and are pretty much internal API. They can be deprecated, if that seems better.

fixes spack#51248

The value of the "direct" attribute of dependencies
is currently lost in "when" context managers.

This PR fixes the issue and adds unit tests to prevent
regressions

Signed-off-by: Massimiliano Culpo <[email protected]>
This commit adds an argument to:
* Spec.constrain
* Spec.satisfies
* Spec.intersects
to avoid solving virtuals when performing those operations.
This is useful in contexts where a repository is not available.

Signed-off-by: Massimiliano Culpo <[email protected]>
@alalazo alalazo added the bugfix Something wasn't working, here's a fix label Sep 1, 2025
@haampie
Copy link
Copy Markdown
Member

haampie commented Sep 1, 2025

I think this is more complete than the other, but this cannot be backported because it extends the package api.

So, def satisfies(...) etc should remain as is, but you could make them call _satisfies(..., resolve_virtuals=True).

Signed-off-by: Massimiliano Culpo <[email protected]>
@haampie haampie merged commit cefe06c into spack:develop Sep 2, 2025
33 checks passed
@haampie haampie added the v1.0.2 PRs / Bug fixes to backport for v1.0.2 label Sep 2, 2025
@alalazo alalazo deleted the refactor/simplify-when-context branch September 2, 2025 08:01
@alalazo alalazo mentioned this pull request Sep 3, 2025
26 tasks
alalazo added a commit that referenced this pull request Sep 8, 2025
Fixes a bug where `with when("..."):` incorrectly relaxed `%dep` to `^dep`.

Removes the custom and faulty logic in `merge_abstract_anonymous_specs`, in favor of the existing and better tested `Spec.constrain` function, with the subtle different that virtuals are not resolved from configured package repositories. The constrain operation is entirely symbolic.

Signed-off-by: Massimiliano Culpo <[email protected]>
haampie pushed a commit that referenced this pull request Sep 12, 2025
Fixes a bug where `with when("..."):` incorrectly relaxed `%dep` to `^dep`.

Removes the custom and faulty logic in `merge_abstract_anonymous_specs`, in favor of the existing and better tested `Spec.constrain` function, with the subtle different that virtuals are not resolved from configured package repositories. The constrain operation is entirely symbolic.

Signed-off-by: Massimiliano Culpo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Something wasn't working, here's a fix v1.0.2 PRs / Bug fixes to backport for v1.0.2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants