Skip to content

Commit 04bfd5d

Browse files
committed
Follow PATH when looking for sys configuration tools
No need to restrict them to `/bin`, `/usr/bin`, and that breaks on NixOS. Closes #3258. Thanks a lot for the detailed reports and helping find the root cause!
1 parent ed75205 commit 04bfd5d

1 file changed

Lines changed: 27 additions & 27 deletions

File tree

src/core/opamStd.ml

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,34 @@ end
554554

555555
module OpamSys = struct
556556

557+
let is_windows = Sys.os_type = "Win32"
558+
559+
let path_sep = if is_windows then ';' else ':'
560+
561+
let split_path_variable =
562+
if is_windows then fun path ->
563+
let length = String.length path in
564+
let rec f acc index current last normal =
565+
if index = length
566+
then let current = current ^ String.sub path last (index - last) in
567+
if current <> "" then current::acc else acc
568+
else let c = path.[index]
569+
and next = succ index in
570+
if c = ';' && normal || c = '"' then
571+
let current = current ^ String.sub path last (index - last) in
572+
if c = '"' then
573+
f acc next current next (not normal)
574+
else
575+
let acc = if current = "" then acc else current::acc in
576+
f acc next "" next true
577+
else
578+
f acc next current last normal in
579+
f [] 0 "" 0 true
580+
else fun path ->
581+
OpamString.split_delim path path_sep
582+
557583
let with_process_in cmd args f =
558-
let path = ["/bin";"/usr/bin"] in
584+
let path = split_path_variable (Env.get "PATH") in
559585
let cmd =
560586
List.find Sys.file_exists (List.map (fun d -> Filename.concat d cmd) path)
561587
in
@@ -670,8 +696,6 @@ module OpamSys = struct
670696
| "fish" -> `fish
671697
| _ -> `sh
672698

673-
let is_windows = Sys.os_type = "Win32"
674-
675699
let executable_name =
676700
if is_windows then
677701
fun name ->
@@ -727,30 +751,6 @@ module OpamSys = struct
727751
(fun f -> try f () with _ -> ())
728752
!registered_at_exit
729753

730-
let path_sep = if is_windows then ';' else ':'
731-
732-
let split_path_variable =
733-
if is_windows then fun path ->
734-
let length = String.length path in
735-
let rec f acc index current last normal =
736-
if index = length
737-
then let current = current ^ String.sub path last (index - last) in
738-
if current <> "" then current::acc else acc
739-
else let c = path.[index]
740-
and next = succ index in
741-
if c = ';' && normal || c = '"' then
742-
let current = current ^ String.sub path last (index - last) in
743-
if c = '"' then
744-
f acc next current next (not normal)
745-
else
746-
let acc = if current = "" then acc else current::acc in
747-
f acc next "" next true
748-
else
749-
f acc next current last normal in
750-
f [] 0 "" 0 true
751-
else fun path ->
752-
OpamString.split_delim path path_sep
753-
754754
exception Exit of int
755755
exception Exec of string * string array * string array
756756

0 commit comments

Comments
 (0)