Display actual stanza when package is ambiguous

Previously we displayed `(install ...)` in all cases.

Closes #1123

Signed-off-by: Etienne Millon <me@emillon.org>
This commit is contained in:
Etienne Millon 2018-08-13 09:56:40 +00:00
parent 7a8b86d6c2
commit 0603f4fca6
17 changed files with 73 additions and 10 deletions

View File

@ -9,6 +9,8 @@ next
- Highlight error locations in error messages (#1121, @emillon) - Highlight error locations in error messages (#1121, @emillon)
- Display actual stanza when package is ambiguous (#1126, fix #1123, @emillon)
1.1.1 (08/08/2018) 1.1.1 (08/08/2018)
------------------ ------------------

View File

@ -166,7 +166,7 @@ module Pkg = struct
(Package.Name.to_string pkg.Package.name) (Package.Name.to_string pkg.Package.name)
(Path.to_string (Package.opam_file pkg)))) (Path.to_string (Package.opam_file pkg))))
let default (project : Dune_project.t) = let default (project : Dune_project.t) stanza =
match Package.Name.Map.values project.packages with match Package.Name.Map.values project.packages with
| [pkg] -> Ok pkg | [pkg] -> Ok pkg
| [] -> | [] ->
@ -178,11 +178,12 @@ module Pkg = struct
| _ :: _ :: _ -> | _ :: _ :: _ ->
Error Error
(sprintf (sprintf
"I can't determine automatically which package this (install ...) \ "I can't determine automatically which package this \
stanza is for. I have the choice between these ones:\n\ stanza is for.\nI have the choice between these ones:\n\
%s\n\ %s\n\
You need to add a (package ...) field in this (install ...) stanza" You need to add a (package ...) field to this (%s) stanza."
(listing (Package.Name.Map.values project.packages))) (listing (Package.Name.Map.values project.packages))
stanza)
let resolve (project : Dune_project.t) name = let resolve (project : Dune_project.t) name =
match Package.Name.Map.find project.packages name with match Package.Name.Map.find project.packages name with
@ -215,14 +216,14 @@ module Pkg = struct
| Ok x -> x | Ok x -> x
| Error e -> Loc.fail loc "%s" e | Error e -> Loc.fail loc "%s" e
let field = let field stanza =
map_validate map_validate
(let%map p = Dune_project.get_exn () (let%map p = Dune_project.get_exn ()
and pkg = field_o "package" string in and pkg = field_o "package" string in
(p, pkg)) (p, pkg))
~f:(fun (p, pkg) -> ~f:(fun (p, pkg) ->
match pkg with match pkg with
| None -> default p | None -> default p stanza
| Some name -> resolve p (Package.Name.of_string name)) | Some name -> resolve p (Package.Name.of_string name))
end end
@ -1049,7 +1050,7 @@ module Install_conf = struct
record record
(let%map section = field "section" Install.Section.t (let%map section = field "section" Install.Section.t
and files = field "files" (list file) and files = field "files" (list file)
and package = Pkg.field and package = Pkg.field "install"
in in
{ section { section
; files ; files
@ -1289,7 +1290,10 @@ module Executables = struct
match match
match package with match package with
| None -> | None ->
(buildable.loc, Pkg.default project) let stanza =
pluralize ~multi "executable"
in
(buildable.loc, Pkg.default project stanza)
| Some (loc, name) -> | Some (loc, name) ->
(loc, Pkg.resolve project (Package.Name.of_string name)) (loc, Pkg.resolve project (Package.Name.of_string name))
with with
@ -1705,7 +1709,7 @@ module Documentation = struct
let t = let t =
record record
(let%map package = Pkg.field (let%map package = Pkg.field "documentation"
and mld_files = Ordered_set_lang.field "mld_files" and mld_files = Ordered_set_lang.field "mld_files"
and loc = loc in and loc = loc in
{ loc { loc

View File

@ -708,6 +708,14 @@
test-cases/select test-cases/select
(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 several-packages)
(deps (package dune) (source_tree test-cases/several-packages))
(action
(chdir
test-cases/several-packages
(progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))
(alias (alias
(name shadow-bindings) (name shadow-bindings)
(deps (package dune) (source_tree test-cases/shadow-bindings)) (deps (package dune) (source_tree test-cases/shadow-bindings))
@ -867,6 +875,7 @@
(alias scope-bug) (alias scope-bug)
(alias scope-ppx-bug) (alias scope-ppx-bug)
(alias select) (alias select)
(alias several-packages)
(alias shadow-bindings) (alias shadow-bindings)
(alias subst) (alias subst)
(alias syntax-versioning) (alias syntax-versioning)
@ -953,6 +962,7 @@
(alias reporting-of-cycles) (alias reporting-of-cycles)
(alias scope-bug) (alias scope-bug)
(alias select) (alias select)
(alias several-packages)
(alias shadow-bindings) (alias shadow-bindings)
(alias subst) (alias subst)
(alias syntax-versioning) (alias syntax-versioning)

View File

@ -0,0 +1 @@
(documentation)

View File

@ -0,0 +1 @@
(lang dune 1.1)

View File

@ -0,0 +1 @@
(lang dune 1.1)

View File

@ -0,0 +1,3 @@
(executable
(public_name an_executable)
)

View File

@ -0,0 +1 @@
(lang dune 1.1)

View File

@ -0,0 +1,4 @@
(install
(section etc)
(files file.conf)
)

View File

@ -0,0 +1 @@
(lang dune 1.1)

View File

@ -0,0 +1,35 @@
If two packages are available and no (package) is present, an error message is
displayed. This can happen for:
- (executable)
$ dune build --root executable
File "dune", line 1, characters 0-43:
Error: I can't determine automatically which package this stanza is for.
I have the choice between these ones:
- pkg1 (because of pkg1.opam)
- pkg2 (because of pkg2.opam)
You need to add a (package ...) field to this (executables) stanza.
[1]
- (documentation)
$ dune build --root documentation
File "dune", line 1, characters 0-15:
Error: I can't determine automatically which package this stanza is for.
I have the choice between these ones:
- pkg1 (because of pkg1.opam)
- pkg2 (because of pkg2.opam)
You need to add a (package ...) field to this (documentation) stanza.
[1]
- (install)
$ dune build --root install
File "dune", line 1, characters 0-44:
Error: I can't determine automatically which package this stanza is for.
I have the choice between these ones:
- pkg1 (because of pkg1.opam)
- pkg2 (because of pkg2.opam)
You need to add a (package ...) field to this (install) stanza.
[1]