Skip to content

Commit

Permalink
env: Translate Windows paths in init shells scripts with cygpath
Browse files Browse the repository at this point in the history
Co-authored-by: Kate <kit-ty-kate@outlook.com>
  • Loading branch information
rjbou and kit-ty-kate committed Feb 19, 2024
1 parent c0b9b66 commit 3b8e0ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ users)
* Fix shell detection on Windows when opam is called via Cygwin's /usr/bin/env even though cmd/powershell is used [#5797 @kit-ty-kate]
* Fix incorrect deduplication of environment variables on update. Effect was that FOO += "" would occlude the value of FOO in the environment [#5837 @dra27]
* Fix regression from #5356 on the detection of out-of-date environment variables. As part of a refactoring, a filter predicate got inverted [#5837 @dra27]
* Unixify Windows paths in init shells scripts (sh, bash, zsh, fish & tsh) [#5797 @rjbou]

## Opamfile

Expand Down
16 changes: 11 additions & 5 deletions src/state/opamEnv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -875,19 +875,25 @@ let env_hook_script shell =

let source root shell f =
let fname = OpamFilename.to_string (OpamPath.init root // f) in
let unix_transform ?using_backslashes () =
let cygpath = Lazy.force OpamSystem.get_cygpath_path_transform in
cygpath ~pathlist:false fname
|> OpamStd.Env.escape_single_quotes ?using_backslashes
in
match shell with
| SH_csh ->
let fname = OpamStd.Env.escape_single_quotes fname in
Printf.sprintf "if ( -f '%s' ) source '%s' >& /dev/null\n" fname fname
let fname = unix_transform () in
Printf.sprintf "if ( -f '%s' ) source '%s' >& /dev/null\n"
fname fname
| SH_fish ->
let fname = OpamStd.Env.escape_single_quotes ~using_backslashes:true fname in
let fname = unix_transform ~using_backslashes:true () in
Printf.sprintf "source '%s' > /dev/null 2> /dev/null; or true\n" fname
| SH_sh | SH_bash ->
let fname = OpamStd.Env.escape_single_quotes fname in
let fname = unix_transform () in
Printf.sprintf "test -r '%s' && . '%s' > /dev/null 2> /dev/null || true\n"
fname fname
| SH_zsh ->
let fname = OpamStd.Env.escape_single_quotes fname in
let fname = unix_transform () in
Printf.sprintf "[[ ! -r '%s' ]] || source '%s' > /dev/null 2> /dev/null\n"
fname fname
| SH_cmd ->
Expand Down

0 comments on commit 3b8e0ce

Please sign in to comment.