diff --git a/CHANGES.md b/CHANGES.md index 417075ca..36a6fd9a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,9 @@ next - 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) +- Improve error message for `dune utop` without a library name (#1154, fix + #1149, @emillon) + 1.1.1 (08/08/2018) ------------------ diff --git a/bin/main.ml b/bin/main.ml index 24457577..f73e5517 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1374,12 +1374,15 @@ let utop = ] in let term = 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 args = Arg.(value & pos_right 0 string [] (Arg.info [] ~docv:"ARGS")) in 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]; let log = Log.create common in let (build_system, context, utop_path) = @@ -1387,10 +1390,10 @@ let utop = let context = Main.find_context_exn setup ~name:ctx_name in let setup = { setup with contexts = [context] } in let target = - match resolve_targets_exn ~log common setup [utop_target] with - | [] -> die "no libraries defined in %s" dir - | [File target] -> target - | _ -> assert false + match resolve_target common ~setup utop_target with + | Error _ -> die "no library is defined in %a" Path.pp dir + | Ok [File target] -> target + | Ok _ -> assert false in do_build setup [File target] >>| fun () -> (setup.build_system, context, Path.to_string target) diff --git a/test/blackbox-tests/dune.inc b/test/blackbox-tests/dune.inc index 14165f47..6fefde28 100644 --- a/test/blackbox-tests/dune.inc +++ b/test/blackbox-tests/dune.inc @@ -780,6 +780,14 @@ test-cases/utop (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 (name windows-diff) (deps (package dune) (source_tree test-cases/windows-diff)) @@ -892,6 +900,7 @@ (alias too-many-parens) (alias use-meta) (alias utop) + (alias utop-default) (alias windows-diff) (alias workspaces))) @@ -979,6 +988,7 @@ (alias tests-stanza) (alias too-many-parens) (alias use-meta) + (alias utop-default) (alias windows-diff) (alias workspaces))) diff --git a/test/blackbox-tests/test-cases/utop-default/lib-in-root/dune b/test/blackbox-tests/test-cases/utop-default/lib-in-root/dune new file mode 100644 index 00000000..f254aaa2 --- /dev/null +++ b/test/blackbox-tests/test-cases/utop-default/lib-in-root/dune @@ -0,0 +1 @@ +(library (name mylib)) diff --git a/test/blackbox-tests/test-cases/utop-default/lib-in-root/dune-project b/test/blackbox-tests/test-cases/utop-default/lib-in-root/dune-project new file mode 100644 index 00000000..7655de07 --- /dev/null +++ b/test/blackbox-tests/test-cases/utop-default/lib-in-root/dune-project @@ -0,0 +1 @@ +(lang dune 1.1) diff --git a/test/blackbox-tests/test-cases/utop-default/lib-in-root/utop-script b/test/blackbox-tests/test-cases/utop-default/lib-in-root/utop-script new file mode 100644 index 00000000..e69de29b diff --git a/test/blackbox-tests/test-cases/utop-default/nothing-in-root/dune-project b/test/blackbox-tests/test-cases/utop-default/nothing-in-root/dune-project new file mode 100644 index 00000000..7655de07 --- /dev/null +++ b/test/blackbox-tests/test-cases/utop-default/nothing-in-root/dune-project @@ -0,0 +1 @@ +(lang dune 1.1) diff --git a/test/blackbox-tests/test-cases/utop-default/nothing-in-root/lib/dune b/test/blackbox-tests/test-cases/utop-default/nothing-in-root/lib/dune new file mode 100644 index 00000000..f0d0755b --- /dev/null +++ b/test/blackbox-tests/test-cases/utop-default/nothing-in-root/lib/dune @@ -0,0 +1 @@ +(library (name private_lib_a)) diff --git a/test/blackbox-tests/test-cases/utop-default/run.t b/test/blackbox-tests/test-cases/utop-default/run.t new file mode 100644 index 00000000..22080882 --- /dev/null +++ b/test/blackbox-tests/test-cases/utop-default/run.t @@ -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]