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

Add winsymlinks:native to the CYGWIN environment variable when running a Cygwin executable on Windows #5793

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/pages/Manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,7 @@ files.
- `OPAM_PACKAGE_VERSION=<ver>` (`<ver>` is the version of the package being built/installed/removed)
- `OPAMCLI=2.0` (since opam 2.1)
- `TMP` and `TMPDIR` are set by the sandbox script (bubblewrap), but should not be relied on since the sandbox is not used on all platforms and can be disabled by the user.
- `CYGWIN=winsymlinks:native` on Windows, or `CYGWIN=$CYGWIN winsymlinks:native` if `CYGWIN` is defined and not empty and `CYGWIN` does not contain either `winsymlinks:native` or `winsymlinks:nativestrict` already (since opam 2.2). In some cases `noglob` can also be added to this variable, such that the default value becomes `CYGWIN=winsymlinks:native noglob` (since opam 2.1)

See [`x-env-path-rewrite:`](#opamfield-x-env-path-rewrite)
for path portability of environment variables on Windows.
Expand Down
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ users)
## Build
* Do not check for cppo in the configure script (not used directly anymore since #5498) [#5794 @kit-ty-kate]
* Upgrade vendored cmdliner to 1.2.0 [#5797 @kit-ty-kate]
* Add winsymlinks:native to the CYGWIN environment variable when installing a package on Windows [#5793 @kit-ty-kate - fix #5782]

## Infrastructure
* Fix depexts CI workflow and ensure all workflows run on master push [#5788 @dra27]
Expand Down
50 changes: 35 additions & 15 deletions src/core/opamProcess.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ let cygwin_create_process_env prog args env fd1 fd2 fd3 =
* time in OPAM.
*
* [This stray " is here to terminate a previous part of the comment!]
*
* Automatically setting CYGWIN to at least contain winsymlinks:native was
* also added later to make sure the native links are used.
*)
let make_args argv =
let b = Buffer.create 128 in
Expand Down Expand Up @@ -108,7 +111,7 @@ let cygwin_create_process_env prog args env fd1 fd2 fd3 =
let (command_line, no_glob) = make_args (Array.to_list args) in
log "cygvoke(%sglob): %s" (if no_glob then "no" else "") command_line;
let env = Array.to_list env in
let set = ref false in
let cygwin_set = ref false in
let f item =
let (key, value) =
match OpamStd.String.cut_at item '=' with
Expand All @@ -118,43 +121,58 @@ let cygwin_create_process_env prog args env fd1 fd2 fd3 =
| "cygwin" ->
let () =
if key = "CYGWIN" then
set := true in
cygwin_set := true in
let settings = OpamStd.String.split value ' ' in
let set = ref false in
let noglob_set = ref false in
let winsymlinks_set = ref false in
let f setting =
let setting = String.trim setting in
let setting =
let setting, value =
match OpamStd.String.cut_at setting ':' with
Some (setting, _) -> setting
| None -> setting in
| Some (setting, value) -> (setting, Some value)
| None -> (setting, None) in
match setting with
"glob" ->
| "glob" ->
if no_glob then begin
log ~level:2 "Removing glob from %s" key;
false
end else begin
log ~level:2 "Leaving glob in %s" key;
set := true;
noglob_set := true;
true
end
| "noglob" ->
if no_glob then begin
log ~level:2 "Leaving noglob in %s" key;
set := true;
noglob_set := true;
true
end else begin
log ~level:2 "Removing noglob from %s" key;
false
end
| "winsymlinks" ->
begin match value with
| Some ("nativestrict" as value) | Some ("native" as value) ->
log ~level:2 "Leaving %s:%s in %s" setting value key;
winsymlinks_set := true;
true
| Some _ | None -> false
end
| _ ->
true in
let settings = List.filter f settings in
let settings =
if not !set && no_glob then begin
if not !noglob_set && no_glob then begin
log ~level:2 "Setting noglob in %s" key;
"noglob"::settings
end else
settings in
let settings =
if not !winsymlinks_set then begin
log ~level:2 "Setting winsymlinks:native in %s" key;
settings @ ["winsymlinks:native"]
end else
settings in
if settings = [] then begin
log ~level:2 "Removing %s completely" key;
None
Expand Down Expand Up @@ -187,14 +205,16 @@ let cygwin_create_process_env prog args env fd1 fd2 fd3 =
Some item in
let env = OpamStd.List.filter_map f env in
let env =
if !set then
if !cygwin_set then
env
else
if no_glob then begin
log ~level:2 "Adding CYGWIN=noglob";
"CYGWIN=noglob"::env
end else
env in
log ~level:2 "Adding CYGWIN=winsymlinks:native noglob";
"CYGWIN=winsymlinks:native noglob"::env
end else begin
log ~level:2 "Adding CYGWIN=winsymlinks:native";
"CYGWIN=winsymlinks:native"::env
end in
OpamStubs.win_create_process prog command_line
(Some(String.concat "\000" env ^ "\000"))
fd1 fd2 fd3
Expand Down
Loading