Skip to content

Commit 770c2e1

Browse files
authored
Fixes for DPM (#1925)
* Provide cwd when invoking ocamlc --version Dune Package Manager would fail when checking the compiler version without a working directory. The process was spawned with no cwd, causing DPM to error. Set an explicit cwd when invoking ocamlc --version, consistent with other toolchain commands. This avoids the DPM failure and makes version probing reliable. Signed-off-by: Sora Morimoto <[email protected]> * Update CHANGELOG.md Signed-off-by: Sora Morimoto <[email protected]> * Add explicit cwd to tool presence checks so commands resolve under DPM Signed-off-by: Sora Morimoto <[email protected]> * Prefer POSIX-style `-version` for OCaml compiler Signed-off-by: Sora Morimoto <[email protected]> --------- Signed-off-by: Sora Morimoto <[email protected]>
1 parent 394ce7b commit 770c2e1

File tree

7 files changed

+35
-14
lines changed

7 files changed

+35
-14
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
## Unreleased
44

5+
- Fix DPM error when invoking `ocamlc --version` without a working directory by
6+
providing an explicit cwd. (#1925)
7+
- Prefer POSIX-style flags for OCaml compiler (e.g. use `-version` instead of
8+
`--version`) to maintain compatibility with older OCaml compilers (< 4.02).
9+
(#1925)
10+
- Unify cwd detection for `Cmd.output` calls by using
11+
`Sandbox.workspace_root ()` where commands depend on the workspace context.
12+
This removes ad-hoc `Workspace.workspaceFolders()` handling and improves
13+
consistency. (#1925)
14+
- Add explicit cwd for tool presence checks executed via the sandbox (e.g.
15+
`utop --version`, `ocamlearlybird --help`, `odig --version`,
16+
`ocamlobjinfo <file>`). This ensures commands resolve correctly under Dune
17+
Package Management. (#1925)
18+
519
## 1.32.0
620

721
- Check that the dune version installed supports DPM (Dune Package Management).

src/cm_editor.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ end = struct
2424
let sandbox = Extension_instance.sandbox instance in
2525
Sandbox.get_command sandbox "ocamlobjinfo" [ file_path ] `Exec
2626
in
27-
Cmd.output command
27+
let cwd = Sandbox.workspace_root () in
28+
Cmd.output ?cwd command
2829
;;
2930

3031
let create ~(uri : Uri.t) =

src/earlybird.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ let check_earlybird_available (sandbox : Sandbox.t) =
3838
(* earlybird <= 1.1.0 doesn't have --version *)
3939
Sandbox.get_command sandbox "ocamlearlybird" [ "--help" ] `Tool
4040
in
41-
Cmd.output earlybird_help
41+
let cwd = Sandbox.workspace_root () in
42+
Cmd.output ?cwd earlybird_help
4243
|> Promise.Result.fold
4344
~ok:(fun (_ : string) -> ())
4445
~error:(fun (_ : string) ->

src/extension_instance.ml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,7 @@ let check_ocaml_lsp_available (sandbox : Sandbox.t) =
149149
let ocaml_lsp_version sandbox =
150150
Sandbox.get_command sandbox "ocamllsp" [ "--version" ] `Tool
151151
in
152-
let cwd =
153-
match Workspace.workspaceFolders () with
154-
| [ cwd ] -> Some (cwd |> WorkspaceFolder.uri |> Uri.fsPath |> Path.of_string)
155-
| _ -> None
156-
in
152+
let cwd = Sandbox.workspace_root () in
157153
Cmd.output ?cwd (ocaml_lsp_version sandbox)
158154
|> Promise.Result.fold
159155
~ok:(fun (_ : string) -> ())
@@ -427,7 +423,10 @@ let close_repl t = t.repl <- None
427423
let update_ocaml_info t =
428424
let open Promise.Syntax in
429425
let+ ocaml_version =
430-
let+ r = Sandbox.get_command t.sandbox "ocamlc" [ "--version" ] `Exec |> Cmd.output in
426+
let cwd = Sandbox.workspace_root () in
427+
let+ r =
428+
Sandbox.get_command t.sandbox "ocamlc" [ "-version" ] `Exec |> Cmd.output ?cwd
429+
in
431430
match r with
432431
| Ok v ->
433432
Ocaml_version.of_string v
@@ -436,7 +435,7 @@ let update_ocaml_info t =
436435
log_chan
437436
~section:"Ocaml.version_semver"
438437
`Warn
439-
"Error running `ocamlc --version`: %s"
438+
"Error running `ocamlc -version`: %s"
440439
e;
441440
Error `Ocamlc_missing
442441
in

src/odig.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ let of_sandbox (sandbox : Sandbox.t) =
1212
let make_odig_cmd = make_odig_cmd sandbox in
1313
let odig_version = make_odig_cmd [ "--version" ] in
1414
let open Promise.Syntax in
15-
let* output = Cmd.output odig_version in
15+
let cwd = Sandbox.workspace_root () in
16+
let* output = Cmd.output ?cwd odig_version in
1617
match output with
1718
| Ok _ ->
18-
let+ cache_dir = Cmd.output (make_odig_cmd [ "cache"; "path" ]) in
19+
let+ cache_dir = Cmd.output ?cwd (make_odig_cmd [ "cache"; "path" ]) in
1920
(match cache_dir with
2021
| Ok cache_dir ->
2122
let cache_dir = cache_dir |> String.strip |> Path.of_string in
@@ -28,7 +29,11 @@ let of_sandbox (sandbox : Sandbox.t) =
2829
generate documentation.")
2930
;;
3031

31-
let cmd_output ~sandbox ~args = Cmd.output (make_odig_cmd sandbox args)
32+
let cmd_output ~sandbox ~args =
33+
let cwd = Sandbox.workspace_root () in
34+
Cmd.output ?cwd (make_odig_cmd sandbox args)
35+
;;
36+
3237
let html_dir t = Path.(t.cache_dir / "/html/")
3338

3439
let odoc_exec t ~sandbox ~package_name =

src/repl.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ let name = "REPL"
5555
let has_utop (sandbox : Sandbox.t) =
5656
let open Promise.Syntax in
5757
let cmd = Sandbox.get_command sandbox "utop" [ "--version" ] `Tool in
58-
let+ result = Cmd.output cmd in
58+
let cwd = Sandbox.workspace_root () in
59+
let+ result = Cmd.output ?cwd cmd in
5960
match result with
6061
| Error _ -> false
6162
| Ok _ -> true

src/sandbox.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,8 @@ let get_exec_command sandbox tools =
587587
;;
588588

589589
let ocaml_version sandbox =
590-
let cmd = get_command sandbox "ocamlc" [ "--version" ] `Exec in
591590
let open Promise.Result.Syntax in
591+
let cmd = get_command sandbox "ocamlc" [ "-version" ] `Exec in
592592
let* cmd = Cmd.check cmd in
593593
let+ output = Cmd.output cmd in
594594
String.strip output

0 commit comments

Comments
 (0)