|
554 | 554 |
|
555 | 555 | module OpamSys = struct |
556 | 556 |
|
| 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 | + |
557 | 583 | let with_process_in cmd args f = |
558 | | - let path = ["/bin";"/usr/bin"] in |
| 584 | + let path = split_path_variable (Env.get "PATH") in |
559 | 585 | let cmd = |
560 | 586 | List.find Sys.file_exists (List.map (fun d -> Filename.concat d cmd) path) |
561 | 587 | in |
@@ -670,8 +696,6 @@ module OpamSys = struct |
670 | 696 | | "fish" -> `fish |
671 | 697 | | _ -> `sh |
672 | 698 |
|
673 | | - let is_windows = Sys.os_type = "Win32" |
674 | | - |
675 | 699 | let executable_name = |
676 | 700 | if is_windows then |
677 | 701 | fun name -> |
@@ -727,30 +751,6 @@ module OpamSys = struct |
727 | 751 | (fun f -> try f () with _ -> ()) |
728 | 752 | !registered_at_exit |
729 | 753 |
|
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 | | - |
754 | 754 | exception Exit of int |
755 | 755 | exception Exec of string * string array * string array |
756 | 756 |
|
|
0 commit comments