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

Two (more) environment fixes #5837

Merged
merged 3 commits into from
Feb 16, 2024
Merged

Two (more) environment fixes #5837

merged 3 commits into from
Feb 16, 2024

Conversation

dra27
Copy link
Member

@dra27 dra27 commented Feb 14, 2024

Two fixes here, both relatively subtle:

  • If the environment contained FOO=bar, the update FOO += "" would cause opam to execute without FOO in the environment
  • A small regression in Fix case-preserving environment updates on Windows #5356 - in the refactoring for case-preserving updates, a boolean check got accidentally inverted

Copy link
Member

@kit-ty-kate kit-ty-kate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The manual might need to be updated. In particular, it says:

FOO += "", FOO := "", etc. are all ignored - i.e. opam never adds empty segments to an existing variable.

Copy link
Collaborator

@rjbou rjbou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is missing a test for the case add an empty string to an undefined variable. Nothing changes in the environment as the variable is not defined beforehand.

diff --git a/tests/reftests/env.test b/tests/reftests/env.test
index 0a8a7a210..781341de3 100644
--- a/tests/reftests/env.test
+++ b/tests/reftests/env.test
@@ -80,6 +80,7 @@ setenv: [
   [ NV_VARS3 := ""    ]
   [ NV_VARS3 := "foo" ]
   [ NV_VARS4  = ""    ]
+  [ NV_VARS5 += ""    ] # undefined
 ]
 flags: compiler
 ### opam switch create emptyvar nv

An update of the documentation to be more precise, and lgtm!

@dra27
Copy link
Member Author

dra27 commented Feb 15, 2024

I think the manual’s correct, isn’t it? The issue was that opam wasn’t previously doing what it was supposed to (by any definition of +=)

If FOO=bar in the environment, the update FOO += "" will cause FOO to
cease to be defined in the environment.
When applying environment updates, opam ensures that the final value
only appears once in the list. This is done by looking at the keys in
the list of updates and filtering out the values in the environment
itself (the computation of the updates already takes into account
existing values).

The only problem is that FOO += "" will be filtered when the updates are
applied, resulting in no value for FOO in the final environment _unless_
there was another update to it in the list.

The fix is simply apply the updates first, and then compute the filtered
keys afterwards.
Logical statement became accidentally inverted.
Copy link
Collaborator

@rjbou rjbou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@kit-ty-kate
Copy link
Member

Thanks

@kit-ty-kate kit-ty-kate merged commit 938e091 into ocaml:master Feb 16, 2024
29 checks passed
@dra27 dra27 deleted the env-occlusion branch May 3, 2024 10:49
@dra27 dra27 mentioned this pull request Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants