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 case-preserving environment updates on Windows #5356

Merged
merged 5 commits into from
Feb 8, 2023

Conversation

dra27
Copy link
Member

@dra27 dra27 commented Nov 16, 2022

There's existing code (of mine) which tries to deal with the fact that environment variable names are case insensitive on Windows. In OpamStd.Env, this is dealt with largely correctly in get, but the handling in OpamEnv is not. When dealing with environment updates, it's necessary to transform the names of any updates - i.e. PATH += "foo" needs to be transformed to Path += "foo" to use the same case as the base environment.

The problem is manifesting itself principally with PATH, which by default is actually Path on Windows. When reverting the updates in OpamEnv.get_pure (for example, to evaluate eval_variables), the switch's bin directory is correctly ignored when resolving the command, but when the command is executed, it re-emerges, because of a duplicate instruction in the env block for both Path (with the switch directory, as that comes from the calling environment) and PATH (as determined in OpamEnv.get_pure, which reverts the updates previously made).

In particular, with this branch, opam config list stops reporting the switch's compiler settings in sys-ocaml-arch, sys-ocaml-cc, and sys-ocaml-libc, but I still need to mull some more whether this is strictly the correct approach (and the environment update code is already nightmarishly complicated even on Unix...)

@dra27 dra27 marked this pull request as ready for review November 25, 2022 12:13
@rjbou rjbou added the PR: QUEUED Pending pull request, waiting for other work to be merged or closed label Dec 1, 2022
@rjbou
Copy link
Collaborator

rjbou commented Dec 1, 2022

queued on #5374

It's irrelevant - the current directory is _always_ included in PATH on
Windows.
@dra27 dra27 removed the PR: QUEUED Pending pull request, waiting for other work to be merged or closed label Feb 7, 2023
@dra27 dra27 added this to PR in progress in Opam 2.2.0 via automation Feb 7, 2023
@dra27 dra27 added this to the 2.2.0~alpha milestone Feb 7, 2023
@dra27 dra27 added the KIND: BUG label Feb 7, 2023
@dra27 dra27 moved this from PR in progress to PR to review in Opam 2.2.0 Feb 7, 2023
src/core/opamStd.mli Outdated Show resolved Hide resolved
src/core/opamStd.mli Outdated Show resolved Hide resolved
src/core/opamStd.mli Outdated Show resolved Hide resolved
src/state/opamEnv.ml Outdated Show resolved Hide resolved
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.

lgtm! just some cosmetic changes.

@rjbou
Copy link
Collaborator

rjbou commented Feb 7, 2023

added a test

rjbou and others added 3 commits February 7, 2023 19:05
OpamEnv.Env.Name.t introduced to defend against comparing environment
variable names as strings. Propagate this change and fix comparison of
environment variables on Windows in the process.
@rjbou rjbou moved this from PR to review to PR finalised (merge with CI) in Opam 2.2.0 Feb 7, 2023
@dra27 dra27 merged commit 149cc1c into ocaml:master Feb 8, 2023
Opam 2.2.0 automation moved this from PR finalised (merge with CI) to Done Feb 8, 2023
@dra27 dra27 deleted the fix-env-again branch February 8, 2023 17:02
dra27 added a commit to dra27/opam that referenced this pull request Feb 14, 2024
Logical statement became accidentally inverted.
rjbou pushed a commit to dra27/opam that referenced this pull request Feb 16, 2024
Logical statement became accidentally inverted.
dra27 added a commit to dra27/opam that referenced this pull request Mar 10, 2024
Logical statement became accidentally inverted.
@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
No open projects
Opam 2.2.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants