-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dune tools env to configure PATH
Signed-off-by: ArthurW <[email protected]>
- Loading branch information
Showing
9 changed files
with
120 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
open! Import | ||
module Pkg_dev_tool = Dune_rules.Pkg_dev_tool | ||
|
||
let all_tools = List.map ~f:Pkg_dev_tool.exe_name [ Ocamlformat; Ocamllsp ] | ||
let bin_path () = Path.build (Pkg_dev_tool.bin_path ()) | ||
|
||
let shell_script = {|#!/bin/sh | ||
dune tools exec $(basename $0) -- "$@" | ||
|} | ||
|
||
let setup path = | ||
if not (Path.exists path) then Path.mkdir_p path; | ||
List.iter all_tools ~f:(fun tool -> | ||
let tool_path = Path.relative path tool in | ||
if not (Path.exists tool_path) then Io.write_file ~perm:0o777 tool_path shell_script) | ||
;; | ||
|
||
let add_path env = | ||
let dir = bin_path () in | ||
setup dir; | ||
Env_path.cons env ~dir | ||
;; | ||
|
||
let term = | ||
let+ builder = Common.Builder.term in | ||
let common, config = Common.init builder in | ||
Scheduler.go ~common ~config (fun () -> | ||
let env = add_path Env.initial in | ||
Format.printf | ||
"%s=%s@." | ||
Env_path.var | ||
(Option.value ~default:"" (Env.get env Env_path.var)); | ||
Fiber.return ()) | ||
;; | ||
|
||
let info = | ||
let doc = "Configure shell environment" in | ||
Cmd.info "env" ~doc | ||
;; | ||
|
||
let command = Cmd.v info term |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
open! Import | ||
|
||
val add_path : Env.t -> Env.t | ||
val command : unit Cmd.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-env.t
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
Check that `dune tools exec ocamllsp` can call the dune tools version of ocamlformat: | ||
|
||
$ . ../helpers.sh | ||
$ . ./helpers.sh | ||
|
||
$ mkrepo | ||
$ mkpkg ocaml 5.2.0 | ||
$ mkpkg ocaml-lsp-server <<EOF | ||
> install: [ | ||
> [ "sh" "-c" "echo '#!/bin/sh' > %{bin}%/ocamllsp" ] | ||
> [ "sh" "-c" "echo 'echo hello from fake ocamllsp' >> %{bin}%/ocamllsp" ] | ||
> [ "sh" "-c" "echo ocamlformat >> %{bin}%/ocamllsp" ] | ||
> [ "sh" "-c" "chmod a+x %{bin}%/ocamllsp" ] | ||
> ] | ||
> EOF | ||
$ mkpkg ocamlformat <<EOF | ||
> install: [ | ||
> [ "sh" "-c" "echo '#!/bin/sh' > %{bin}%/ocamlformat" ] | ||
> [ "sh" "-c" "echo 'echo hello from fake ocamlformat' >> %{bin}%/ocamlformat" ] | ||
> [ "sh" "-c" "chmod a+x %{bin}%/ocamlformat" ] | ||
> ] | ||
> EOF | ||
|
||
$ setup_ocamllsp_workspace | ||
|
||
$ cat > dune-project <<EOF | ||
> (lang dune 3.16) | ||
> EOF | ||
|
||
$ make_lockdir | ||
$ cat > dune.lock/ocaml.pkg <<EOF | ||
> (version 5.2.0) | ||
> EOF | ||
|
||
$ dune tools exec ocamllsp | ||
Solution for dev-tools.locks/ocaml-lsp-server: | ||
- ocaml.5.2.0 | ||
- ocaml-lsp-server.0.0.1 | ||
Running 'ocamllsp' | ||
hello from fake ocamllsp | ||
Solution for dev-tools.locks/ocamlformat: | ||
- ocamlformat.0.0.1 | ||
Running 'ocamlformat' | ||
hello from fake ocamlformat | ||
|
||
Users can also configure their PATH variable environment: | ||
|
||
$ eval $(dune tools env) | ||
$ echo $PATH | sed 's/:.*//' | ||
$TESTCASE_ROOT/_build/_private/default/.dev-tool/bin | ||
$ which ocamllsp | ||
$TESTCASE_ROOT/_build/_private/default/.dev-tool/bin/ocamllsp | ||
$ which ocamlformat | ||
$TESTCASE_ROOT/_build/_private/default/.dev-tool/bin/ocamlformat | ||
$ ocamllsp | ||
Running 'ocamllsp' | ||
hello from fake ocamllsp | ||
Running 'ocamlformat' | ||
hello from fake ocamlformat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters