Skip to content

Commit

Permalink
fix: disallow absolute paths in dune ocaml top-module
Browse files Browse the repository at this point in the history
Signed-off-by: Ali Caglayan <alizter@gmail.com>
  • Loading branch information
Alizter committed Jul 24, 2023
1 parent 875fc23 commit 3411cef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Unreleased

- Add `dune show rules` as alias of the `dune rules` command. (#8000, @Alizter)

- Fix `dune ocaml top-module` to correctly reject absolute paths. (#8249, fixes
#7370, @Alizter)

- Add `dune show installed-libraries` as an alias of the `dune
installed-libraries` command. (#8135, @Alizter)

Expand Down
16 changes: 10 additions & 6 deletions bin/ocaml/top.ml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ module Module = struct
let term =
let+ common = Common.term
and+ module_path =
Arg.(required & pos 0 (some string) None & Arg.info [] ~docv:"MODULE")
let doc =
"Relative path to an OCaml module. (File extension not necessary)."
in
Arg.(
required & pos 0 (some string) None & Arg.info [] ~docv:"MODULE" ~doc)
and+ ctx_name =
Common.context_arg ~doc:{|Select context where to build/run utop.|}
in
Expand All @@ -223,12 +227,12 @@ module Module = struct
|> Option.value_exn
in
let+ directives =
let module_path =
if Filename.is_relative module_path then
let root = Common.root common in
Path.Source.relative Path.Source.root
(root.reach_from_root_prefix ^ module_path)
in
module_directives sctx module_path
module_directives sctx
(Path.Source.relative Path.Source.root
(Filename.concat root.reach_from_root_prefix module_path))
else User_error.raise [ Pp.text "Module path must be relative." ]
in
Dune_rules.Toplevel.print_toplevel_init_file directives))
end
Expand Down
11 changes: 3 additions & 8 deletions test/blackbox-tests/test-cases/top-module/load-from-lib.t
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ We try to load a module defined in a library with a dependnecy
$ ls _build/default/mydummylib/*.cma
_build/default/mydummylib/mydummylib.cma

$ dune ocaml top-module $PWD/foo/foo.ml 2>&1 | head -n7
Internal error, please report upstream including the contents of _build/log.
Description:
("Local.relative: received absolute path",
{ t = "."
; path =
"$TESTCASE_ROOT/foo/foo.ml"
})
$ dune ocaml top-module $PWD/foo/foo.ml
Error: Module path must be relative.
[1]

0 comments on commit 3411cef

Please sign in to comment.