Skip to content

pkg: Display error message when no dependencies exist in dune-project #11573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/dune_pkg/local_package.ml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,26 @@ let of_package (t : Dune_lang.Package.t) =
let name = Package.name t in
match Package.original_opam_file t with
| None ->
let dependencies = t |> Package.depends |> Dependency_formula.of_dependencies in
let depends =
match Package.depends t, Package.has_opam_file t with
| [], Exists true ->
let name = t |> Package.name |> Package_name.to_string in
let hints =
[ Pp.textf "Add a `depends` field in the `package` stanza of package %S or" name
; Pp.textf "Delete the package %S from `dune-project`" name
]
in
User_warning.emit
~hints
[ Pp.textf
"Package %S loaded from `dune-project` but does not declare any \
dependencies"
name
];
[]
| otherwise, _ -> otherwise
in
let dependencies = Dependency_formula.of_dependencies depends in
{ name
; version
; dependencies
Expand Down
20 changes: 18 additions & 2 deletions test/blackbox-tests/test-cases/pkg/pin-stanza/mixed-opam-dune.t
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,34 @@ should favor the dune metadata in such a case.
> EOF

$ dune pkg lock
Warning: Package "bar" loaded from `dune-project` but does not declare any
dependencies
Hint: Add a `depends` field in the `package` stanza of package "bar" or
Hint: Delete the package "bar" from `dune-project`
Warning: Package "bar" loaded from `dune-project` but does not declare any
dependencies
Hint: Add a `depends` field in the `package` stanza of package "bar" or
Hint: Delete the package "bar" from `dune-project`
Warning: Package "bar" loaded from `dune-project` but does not declare any
dependencies
Hint: Add a `depends` field in the `package` stanza of package "bar" or
Hint: Delete the package "bar" from `dune-project`
Warning: Package "bar" loaded from `dune-project` but does not declare any
dependencies
Hint: Add a `depends` field in the `package` stanza of package "bar" or
Hint: Delete the package "bar" from `dune-project`
Solution for dune.lock:
- bar.dev
- foo.dev

$ cat dune.lock/bar.pkg | sed "/source/,//d"
$ cat dune.lock/bar.pkg | sed "/source/,//d"
(version dev)

(dune)


(dev)
$ cat dune.lock/foo.pkg | sed "/source/,//d"
$ cat dune.lock/foo.pkg | sed "/source/,//d"
(version dev)

(dune)
Expand Down
Loading