Improve error message for `dune utop`
Closes #1149 Signed-off-by: Etienne Millon <me@emillon.org>
This commit is contained in:
parent
99d82c235c
commit
6fe9ec68c0
|
@ -14,6 +14,9 @@ next
|
||||||
- Add `dune unstable-fmt` to format `dune` files. The interface and syntax are
|
- Add `dune unstable-fmt` to format `dune` files. The interface and syntax are
|
||||||
still subject to change, so use with caution. (#1130, fix #940, @emillon)
|
still subject to change, so use with caution. (#1130, fix #940, @emillon)
|
||||||
|
|
||||||
|
- Improve error message for `dune utop` without a library name (#1154, fix
|
||||||
|
#1149, @emillon)
|
||||||
|
|
||||||
1.1.1 (08/08/2018)
|
1.1.1 (08/08/2018)
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
|
15
bin/main.ml
15
bin/main.ml
|
@ -1374,12 +1374,15 @@ let utop =
|
||||||
] in
|
] in
|
||||||
let term =
|
let term =
|
||||||
let%map common = common
|
let%map common = common
|
||||||
and dir = Arg.(value & pos 0 dir "" & Arg.info [] ~docv:"PATH")
|
and dir = Arg.(value & pos 0 string "" & Arg.info [] ~docv:"PATH")
|
||||||
and ctx_name = context_arg ~doc:{|Select context where to build/run utop.|}
|
and ctx_name = context_arg ~doc:{|Select context where to build/run utop.|}
|
||||||
and args = Arg.(value & pos_right 0 string [] (Arg.info [] ~docv:"ARGS"))
|
and args = Arg.(value & pos_right 0 string [] (Arg.info [] ~docv:"ARGS"))
|
||||||
in
|
in
|
||||||
set_dirs common;
|
set_dirs common;
|
||||||
let utop_target = dir |> Path.of_string |> Utop.utop_exe |> Path.to_string in
|
let dir = Path.of_string dir in
|
||||||
|
if not (Path.is_directory dir) then
|
||||||
|
die "cannot find directory: %a" Path.pp dir;
|
||||||
|
let utop_target = dir |> Utop.utop_exe |> Path.to_string in
|
||||||
set_common_other common ~targets:[utop_target];
|
set_common_other common ~targets:[utop_target];
|
||||||
let log = Log.create common in
|
let log = Log.create common in
|
||||||
let (build_system, context, utop_path) =
|
let (build_system, context, utop_path) =
|
||||||
|
@ -1387,10 +1390,10 @@ let utop =
|
||||||
let context = Main.find_context_exn setup ~name:ctx_name in
|
let context = Main.find_context_exn setup ~name:ctx_name in
|
||||||
let setup = { setup with contexts = [context] } in
|
let setup = { setup with contexts = [context] } in
|
||||||
let target =
|
let target =
|
||||||
match resolve_targets_exn ~log common setup [utop_target] with
|
match resolve_target common ~setup utop_target with
|
||||||
| [] -> die "no libraries defined in %s" dir
|
| Error _ -> die "no library is defined in %a" Path.pp dir
|
||||||
| [File target] -> target
|
| Ok [File target] -> target
|
||||||
| _ -> assert false
|
| Ok _ -> assert false
|
||||||
in
|
in
|
||||||
do_build setup [File target] >>| fun () ->
|
do_build setup [File target] >>| fun () ->
|
||||||
(setup.build_system, context, Path.to_string target)
|
(setup.build_system, context, Path.to_string target)
|
||||||
|
|
|
@ -780,6 +780,14 @@
|
||||||
test-cases/utop
|
test-cases/utop
|
||||||
(progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))
|
(progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))
|
||||||
|
|
||||||
|
(alias
|
||||||
|
(name utop-default)
|
||||||
|
(deps (package dune) (source_tree test-cases/utop-default))
|
||||||
|
(action
|
||||||
|
(chdir
|
||||||
|
test-cases/utop-default
|
||||||
|
(progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))
|
||||||
|
|
||||||
(alias
|
(alias
|
||||||
(name windows-diff)
|
(name windows-diff)
|
||||||
(deps (package dune) (source_tree test-cases/windows-diff))
|
(deps (package dune) (source_tree test-cases/windows-diff))
|
||||||
|
@ -892,6 +900,7 @@
|
||||||
(alias too-many-parens)
|
(alias too-many-parens)
|
||||||
(alias use-meta)
|
(alias use-meta)
|
||||||
(alias utop)
|
(alias utop)
|
||||||
|
(alias utop-default)
|
||||||
(alias windows-diff)
|
(alias windows-diff)
|
||||||
(alias workspaces)))
|
(alias workspaces)))
|
||||||
|
|
||||||
|
@ -979,6 +988,7 @@
|
||||||
(alias tests-stanza)
|
(alias tests-stanza)
|
||||||
(alias too-many-parens)
|
(alias too-many-parens)
|
||||||
(alias use-meta)
|
(alias use-meta)
|
||||||
|
(alias utop-default)
|
||||||
(alias windows-diff)
|
(alias windows-diff)
|
||||||
(alias workspaces)))
|
(alias workspaces)))
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
(library (name mylib))
|
|
@ -0,0 +1 @@
|
||||||
|
(lang dune 1.1)
|
|
@ -0,0 +1 @@
|
||||||
|
(lang dune 1.1)
|
|
@ -0,0 +1 @@
|
||||||
|
(library (name private_lib_a))
|
|
@ -0,0 +1,19 @@
|
||||||
|
By default, dune utop tries to make a toplevel for the current directory:
|
||||||
|
|
||||||
|
$ echo 'exit 0;;' | dune utop --root lib-in-root | grep -v 'version'
|
||||||
|
Entering directory 'lib-in-root'
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
If there is no library there, it displays an error message:
|
||||||
|
|
||||||
|
$ dune utop --root nothing-in-root
|
||||||
|
Entering directory 'nothing-in-root'
|
||||||
|
No library is defined in .
|
||||||
|
[1]
|
||||||
|
|
||||||
|
The message where the library path does not exist is different:
|
||||||
|
|
||||||
|
$ dune utop --root nothing-in-root does-not-exist
|
||||||
|
Cannot find directory: does-not-exist
|
||||||
|
[1]
|
Loading…
Reference in New Issue