Skip to content

Commit

Permalink
fix: restore compat with opam 2.0.x
Browse files Browse the repository at this point in the history
check --version of opam before using --global

Signed-off-by: Rudi Grinberg <me@rgrinberg.com>

ps-id: F323DC28-D851-4218-8373-6760F56EE13C
  • Loading branch information
rgrinberg committed Feb 21, 2022
1 parent b1a22da commit 5de9226
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 1.9.4

- Restore compatibility with opam 2.1.x (#884)

## 1.9.3

- Fix dune subdir stanza syntax highlighting (#870)
Expand Down
19 changes: 17 additions & 2 deletions src/opam.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,23 @@ let make ?root () =
| Error _, _ -> Promise.return None
| Ok bin, Some root -> Promise.return (Some { bin; root })
| Ok bin, None -> (
let var_root_cmd =
Cmd.Spawn (Cmd.append bin [ "var"; "--global"; "root" ])
let* var_root_cmd =
let+ args =
let+ version = Cmd.output (Spawn { bin with args = [ "--version" ] }) in
let global =
match version with
| Error _ -> []
| Ok v -> (
match Stdlib.Scanf.sscanf v "%d.%d" (fun x y -> (x, y)) with
| (exception End_of_file)
| (exception Failure _)
| (exception Stdlib.Scanf.Scan_failure _) -> []
| major, minor ->
if Poly.((major, minor) >= (2, 1)) then [ "--global" ] else [])
in
("var" :: global) @ [ "root" ]
in
Cmd.Spawn (Cmd.append bin args)
in
let+ var_root_output = Cmd.output var_root_cmd in
match var_root_output with
Expand Down

0 comments on commit 5de9226

Please sign in to comment.