Skip to content

Commit 9bd82ac

Browse files
committed
fix: show clear error when running uninstalled dev tool
Signed-off-by: Sachin Beniwal <s474996633@gmail.com>
1 parent ad3703e commit 9bd82ac

10 files changed

+52
-21
lines changed

bin/tools/tools_common.ml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,24 @@ let install_command dev_tool =
127127

128128
let exec_command dev_tool =
129129
let exe_name = Pkg_dev_tool.exe_name dev_tool in
130+
let exe_path = dev_tool_exe_path dev_tool in
130131
let term =
131132
let+ builder = Common.Builder.term
132133
(* CR-someday Alizter: document this option *)
133134
and+ args = Arg.(value & pos_all string [] (info [] ~docv:"ARGS" ~doc:None)) in
134-
let common, config = Common.init builder in
135-
lock_build_and_run_dev_tool ~common ~config builder dev_tool ~args
135+
let common, _config = Common.init builder in
136+
if Path.exists exe_path
137+
then run_dev_tool (Common.root common) dev_tool ~args
138+
else
139+
User_error.raise
140+
[ Pp.textf "The tool %s is not installed." exe_name ]
141+
~hints:
142+
[ Pp.concat
143+
~sep:Pp.space
144+
[ Pp.text "Try running"
145+
; User_message.command (sprintf "dune tools install %s" exe_name)
146+
]
147+
]
136148
in
137149
let info =
138150
let doc =

test/blackbox-tests/test-cases/pkg/ocamlformat/ocamlformat-which.t

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ The command will fail because the dev tool is not installed:
2020
_build/_private/default/.dev-tool/ocamlformat/target/bin/ocamlformat
2121

2222
Install the dev tool:
23-
$ dune tools exec ocamlformat
23+
$ dune tools install ocamlformat
2424
Solution for _build/.dev-tools.locks/ocamlformat:
2525
- ocamlformat.0.26.2
26+
27+
$ dune tools exec ocamlformat
2628
Running 'ocamlformat'
2729
formatted with version 0.26.2
2830

test/blackbox-tests/test-cases/pkg/ocamlformat/ocamlformat-wrapper.t

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ Exercise running the ocamlformat wrapper command.
77
$ make_ocamlformat_opam_pkg "0.26.2"
88
$ make_project_with_dev_tool_lockdir
99

10-
$ DUNE_CONFIG__LOCK_DEV_TOOL=enabled dune tools exec ocamlformat
10+
$ DUNE_CONFIG__LOCK_DEV_TOOL=enabled dune tools install ocamlformat
1111
Solution for _build/.dev-tools.locks/ocamlformat:
1212
- ocamlformat.0.26.2
13+
14+
$ dune tools exec ocamlformat
1315
Running 'ocamlformat'
1416
formatted with version 0.26.2

test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-basic.t

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
Test that the "dune tools exec ocamllsp" command causes ocamllsp to be
2-
locked, built and run when the command is run from a dune project with
3-
a lockdir containing an "ocaml" lockfile.
1+
Test that the "dune tools exec ocamllsp" command runs ocamllsp after it
2+
has been installed with "dune tools install ocamllsp".
43

54
$ . ../helpers.sh
65
$ . ./helpers.sh
@@ -24,10 +23,16 @@ a lockdir containing an "ocaml" lockfile.
2423
> (version 5.2.0)
2524
> EOF
2625

27-
$ dune tools exec ocamllsp
26+
First install the tool:
27+
28+
$ dune tools install ocamllsp
2829
Solution for _build/.dev-tools.locks/ocaml-lsp-server:
2930
- ocaml.5.2.0
3031
- ocaml-lsp-server.0.0.1
32+
33+
Then exec runs it:
34+
35+
$ dune tools exec ocamllsp
3136
Running 'ocamllsp'
3237
hello from fake ocamllsp
3338

test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-env-path-var.t

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ Make a fake ocamllsp package that prints out the PATH variable:
2222
> (version 5.2.0)
2323
> EOF
2424

25-
Confirm that each dev tool's bin directory is now in PATH:
26-
$ dune tools exec ocamllsp | tr : '\n' | grep '_build/_private/default/.dev-tool'
25+
First install the tool:
26+
$ dune tools install ocamllsp
2727
Solution for _build/.dev-tools.locks/ocaml-lsp-server:
2828
- ocaml.5.2.0
2929
- ocaml-lsp-server.0.0.1
30+
31+
Confirm that each dev tool's bin directory is now in PATH:
32+
$ dune tools exec ocamllsp | tr : '\n' | grep '_build/_private/default/.dev-tool'
3033
Running 'ocamllsp'
3134
$TESTCASE_ROOT/_build/_private/default/.dev-tool/ocaml-index/target/bin
3235
$TESTCASE_ROOT/_build/_private/default/.dev-tool/dune-release/target/bin

test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-install-concurrent-with-watch-server.t

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ Test that ocamllsp can be installed while dune is running in watch mode.
3333
Success, waiting for filesystem changes...
3434
Success, waiting for filesystem changes...
3535

36-
$ dune tools exec ocamllsp
36+
$ dune tools install ocamllsp
3737
Solution for dev-tools.locks/ocaml-lsp-server:
3838
- ocaml.5.2.0
3939
- ocaml-lsp-server.0.0.1
40+
41+
$ dune tools exec ocamllsp
4042
Running 'ocamllsp'
4143
hello from fake ocamllsp
4244

test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-no-lock-dir.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ dune project with no lockdir.
1010
> EOF
1111

1212
$ dune tools exec ocamllsp
13-
Error: Unable to load the lockdir for the default build context.
14-
Hint: Try running 'dune pkg lock'
13+
Error: The tool ocamllsp is not installed.
14+
Hint: Try running 'dune tools install ocamllsp'
1515
[1]

test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-no-ocaml-lockfile.t

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ doesn't contain a lockfile for the "ocaml" package.
1414
$ make_lockdir
1515

1616
$ dune tools exec ocamllsp
17-
Error: The lockdir doesn't contain a lockfile for the package "ocaml".
18-
Hint: Add a dependency on "ocaml" to one of the packages in dune-project and
19-
then run 'dune pkg lock'
17+
Error: The tool ocamllsp is not installed.
18+
Hint: Try running 'dune tools install ocamllsp'
2019
[1]

test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-ocamlformat.t

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ Make a fake ocamlformat
4848
Solution for dev-tools.locks/ocamlformat:
4949
- ocamlformat.0.0.1
5050

51-
$ dune tools exec ocamllsp
51+
$ dune tools install ocamllsp
5252
Solution for dev-tools.locks/ocaml-lsp-server:
5353
- ocaml.5.2.0
5454
- ocaml-lsp-server.0.0.1
55+
56+
$ dune tools exec ocamllsp
5557
Running 'ocamllsp'
5658
fake ocamllsp will now run fake ocamlformat:
5759
hello from fake ocamlformat

test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-relock-on-ocaml-version-change.t

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ same version of the ocaml compiler as the code that it's analyzing.
2828
> EOF
2929

3030
Initially ocamllsp will be depend on ocaml.5.2.0 to match the project.
31-
$ dune tools exec ocamllsp
31+
$ dune tools install ocamllsp
3232
Solution for _build/.dev-tools.locks/ocaml-lsp-server:
3333
- ocaml.5.2.0
3434
- ocaml-lsp-server.0.0.1
35+
36+
$ dune tools exec ocamllsp
3537
Running 'ocamllsp'
3638
hello from fake ocamllsp
3739
$ cat "${dev_tool_lock_dir}"/ocaml.pkg
@@ -47,16 +49,18 @@ Change the version of ocaml that the project depends on.
4749
> (version 5.1.0)
4850
> EOF
4951

50-
Running "dune tools exec ocamllsp" causes ocamllsp to be relocked and rebuilt
51-
before running. Ocamllsp now depends on ocaml.5.1.0.
52-
$ DUNE_CONFIG__LOCK_DEV_TOOL=enabled dune tools exec ocamllsp
52+
Running "dune tools install ocamllsp" causes ocamllsp to be relocked and rebuilt.
53+
Ocamllsp now depends on ocaml.5.1.0.
54+
$ DUNE_CONFIG__LOCK_DEV_TOOL=enabled dune tools install ocamllsp
5355
The version of the compiler package ("ocaml") in this project's lockdir has
5456
changed to 5.1.0 (formerly the compiler version was 5.2.0). The dev-tool
5557
"ocaml-lsp-server" will be re-locked and rebuilt with this version of the
5658
compiler.
5759
Solution for _build/.dev-tools.locks/ocaml-lsp-server:
5860
- ocaml.5.1.0
5961
- ocaml-lsp-server.0.0.1
62+
63+
$ dune tools exec ocamllsp
6064
Running 'ocamllsp'
6165
hello from fake ocamllsp
6266
$ cat "${dev_tool_lock_dir}"/ocaml.pkg

0 commit comments

Comments
 (0)