Skip to content

Commit 9820143

Browse files
authored
Merge pull request #12706 from Sudha247/ocaml-index-dev-tool
Add ocaml-index as a dev tool
2 parents 2154a32 + 7fb45ca commit 9820143

File tree

6 files changed

+55
-4
lines changed

6 files changed

+55
-4
lines changed

bin/tools/group.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ module Exec = struct
88
Cmd.group
99
info
1010
(List.map
11-
[ Ocamlformat; Ocamllsp; Ocamlearlybird; Odig; Opam_publish; Dune_release ]
11+
[ Ocamlformat
12+
; Ocamllsp
13+
; Ocamlearlybird
14+
; Odig
15+
; Opam_publish
16+
; Dune_release
17+
; Ocaml_index
18+
]
1219
~f:Tools_common.exec_command)
1320
;;
1421
end

src/dune_pkg/dev_tool.ml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type t =
99
| Odig
1010
| Opam_publish
1111
| Dune_release
12+
| Ocaml_index
1213

1314
let to_dyn = function
1415
| Ocamlformat -> Dyn.variant "Ocamlformat" []
@@ -19,10 +20,20 @@ let to_dyn = function
1920
| Odig -> Dyn.variant "Odig" []
2021
| Opam_publish -> Dyn.variant "Opam_publish" []
2122
| Dune_release -> Dyn.variant "Dune_release" []
23+
| Ocaml_index -> Dyn.variant "Ocaml_index" []
2224
;;
2325

2426
let all =
25-
[ Ocamlformat; Odoc; Ocamllsp; Utop; Ocamlearlybird; Odig; Opam_publish; Dune_release ]
27+
[ Ocamlformat
28+
; Odoc
29+
; Ocamllsp
30+
; Utop
31+
; Ocamlearlybird
32+
; Odig
33+
; Opam_publish
34+
; Dune_release
35+
; Ocaml_index
36+
]
2637
;;
2738

2839
let equal a b =
@@ -43,6 +54,9 @@ let equal a b =
4354
| Opam_publish, _ -> false
4455
| _, Opam_publish -> false
4556
| Dune_release, Dune_release -> true
57+
| Dune_release, _ -> false
58+
| _, Dune_release -> false
59+
| Ocaml_index, Ocaml_index -> true
4660
;;
4761

4862
let hash = Poly.hash
@@ -56,6 +70,7 @@ let package_name = function
5670
| Odig -> Package_name.of_string "odig"
5771
| Opam_publish -> Package_name.of_string "opam-publish"
5872
| Dune_release -> Package_name.of_string "dune-release"
73+
| Ocaml_index -> Package_name.of_string "ocaml-index"
5974
;;
6075

6176
let of_package_name package_name =
@@ -68,6 +83,7 @@ let of_package_name package_name =
6883
| "odig" -> Odig
6984
| "opam-publish" -> Opam_publish
7085
| "dune-release" -> Dune_release
86+
| "ocaml-index" -> Ocaml_index
7187
| other -> User_error.raise [ Pp.textf "No such dev tool: %s" other ]
7288
;;
7389

@@ -80,6 +96,7 @@ let exe_name = function
8096
| Odig -> "odig"
8197
| Opam_publish -> "opam-publish"
8298
| Dune_release -> "dune-release"
99+
| Ocaml_index -> "ocaml-index"
83100
;;
84101

85102
let exe_path_components_within_package t = [ "bin"; exe_name t ]
@@ -93,5 +110,5 @@ let needs_to_build_with_same_compiler_as_project = function
93110
false
94111
| Opam_publish -> false
95112
| Dune_release -> false
96-
| Utop | Odoc | Ocamllsp | Odig -> true
113+
| Utop | Odoc | Ocamllsp | Ocaml_index | Odig -> true
97114
;;

src/dune_pkg/dev_tool.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type t =
77
| Odig
88
| Opam_publish
99
| Dune_release
10+
| Ocaml_index
1011

1112
val to_dyn : t -> Dyn.t
1213
val all : t list

src/dune_rules/merlin/ocaml_index.ml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
open Import
22
open Memo.O
33

4+
let ocaml_index_dev_tool_exe_path_building_if_necessary () =
5+
let open Action_builder.O in
6+
let path = Path.build (Pkg_dev_tool.exe_path Ocaml_index) in
7+
let+ () = Action_builder.path path in
8+
Ok path
9+
;;
10+
11+
let ocaml_index_dev_tool_exists () =
12+
Lock_dir.dev_tool_source_lock_dir Ocaml_index |> Path.source |> Path.Untracked.exists
13+
;;
14+
415
let ocaml_index sctx ~dir =
5-
Super_context.resolve_program ~loc:None ~dir sctx "ocaml-index"
16+
match ocaml_index_dev_tool_exists () with
17+
| true -> ocaml_index_dev_tool_exe_path_building_if_necessary ()
18+
| false ->
19+
Super_context.resolve_program
20+
sctx
21+
~dir
22+
"ocaml-index"
23+
~loc:None
24+
~hint:"opam install ocaml-index"
625
;;
726

827
let index_file_name = "cctx.ocaml-index"

test/blackbox-tests/test-cases/pkg/dev-tools-help-message.t

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ Output the help text:
2323
dune-release executable (pass flags to dune-release after the '--'
2424
argument, such as 'dune tools exec dune-release -- --help').
2525

26+
ocaml-index [OPTION]… [ARGS]…
27+
Wrapper for running ocaml-index intended to be run automatically
28+
by a text editor. All positional arguments will be passed to the
29+
ocaml-index executable (pass flags to ocaml-index after the '--'
30+
argument, such as 'dune tools exec ocaml-index -- --help').
31+
2632
ocamlearlybird [OPTION]… [ARGS]…
2733
Wrapper for running ocamlearlybird intended to be run
2834
automatically by a text editor. All positional arguments will be

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Confirm that each dev tool's bin directory is now in PATH:
2828
- ocaml.5.2.0
2929
- ocaml-lsp-server.0.0.1
3030
Running 'ocamllsp'
31+
$TESTCASE_ROOT/_build/_private/default/.dev-tool/ocaml-index/target/bin
3132
$TESTCASE_ROOT/_build/_private/default/.dev-tool/dune-release/target/bin
3233
$TESTCASE_ROOT/_build/_private/default/.dev-tool/opam-publish/target/bin
3334
$TESTCASE_ROOT/_build/_private/default/.dev-tool/odig/target/bin

0 commit comments

Comments
 (0)