Detection and warning for common typos in package dependency constraints#11600
Detection and warning for common typos in package dependency constraints#11600gridbugs merged 1 commit intoocaml:mainfrom
Conversation
gridbugs
left a comment
There was a problem hiding this comment.
Nice work so far! In addition to the comments, please add some cram tests (see the contents of test/blackbox-tests/test-cases/ for examples).
There was a problem hiding this comment.
Avoid including unrelated changes in PRs. If you want to update the readme file, it's more appropriate to do it in a separate PR.
boot/libs.ml
Outdated
| @@ -1,4 +1,4 @@ | |||
| let external_libraries = [ "unix"; "threads" ] | |||
| let external_libraries = [ "threads.posix" ] | |||
There was a problem hiding this comment.
Dune's build process is a little annoying in that it sometimes changes this file. Get into the habit of not staging changes to this file when making commits to this repo.
class.sol
Outdated
There was a problem hiding this comment.
What is this file? Please remove it from the PR.
src/dune_pkg/package_dependency.ml
Outdated
| (* Function to emit warnings for common typos when processing dependencies *) | ||
| let warn_on_typos ~loc dependency = | ||
| (* We'll implement a copy of the check_for_version_typo function here | ||
| since it's not directly accessible from the other module *) |
There was a problem hiding this comment.
See if you can come up with a way to avoid this duplication. You're welcome to extend the interface to Dune_lange.Package_dependency if necessary.
src/dune_lang/package_dependency.ml
Outdated
| ( sprintf | ||
| "Possible typo in package dependency for %s: '(= version)' might be a mistake." | ||
| (Package_name.to_string name) | ||
| , "Did you mean to use the `:version` variable instead? Use: (depends (bar :version))" ) |
There was a problem hiding this comment.
In the example, instead of (depends (bar :version)) it would be better to reproduce the text of the constraint the user actually used, but corrected.
src/dune_lang/package_dependency.ml
Outdated
| (* Check for typos and emit warnings *) | ||
| (match check_for_version_typo result with | ||
| | Some (msg, suggestion) -> | ||
| User_warning.emit [Pp.text msg; Pp.text suggestion] |
There was a problem hiding this comment.
Take a look at User_message.make. You can create a message, possibly including hints which are formatted differently from the regular warning body and would be suitable for the "Did you mean..." parts of the warning. The message can then be printed as a warning with User_warning.emit_message.
So concretely I'm suggesting that you change the check_for_version_type function to return a User_message.t option.
src/dune_lang/package_dependency.ml
Outdated
| "Possible typo in package dependency for %s: '(= version)' might be a mistake." | ||
| (Package_name.to_string name) | ||
| , "Did you mean to use the `:version` variable instead? Use: (depends (bar :version))" ) | ||
| | Some (Bop (Relop.Eq, Value.String_literal "version", _)) -> |
There was a problem hiding this comment.
I think we only expect version comparisons to use the Uop constructor.
src/dune_lang/package_dependency.ml
Outdated
| | Some (Uop (Relop.Eq, Value.String_literal "version")) -> | ||
| Some | ||
| ( sprintf | ||
| "Possible typo in package dependency for %s: '(= version)' might be a mistake." |
There was a problem hiding this comment.
I think it would be more accurate to say "Possible typo in constraint for dependency %S: ...".
src/dune_pkg/package_dependency.ml
Outdated
| (match Constraint.opt_of_opam_condition condition with | ||
| | Ok constraint_ -> | ||
| let dep = { name; constraint_ } in | ||
| warn_on_typos ~loc dep; |
There was a problem hiding this comment.
Will this print warnings for projects that don't use dune package management?
There was a problem hiding this comment.
I think printing the warning in decode is sufficient, since for all operations dune will need to decode the dune-project file anyway.
There was a problem hiding this comment.
I'll look at it again and give feedback.
There was a problem hiding this comment.
@gridbugs , I've added fixes based on your suggestions apart from cram tests, I'm currently working on that. Please kindly review and let me know if I'm on track, thanks.
gridbugs
left a comment
There was a problem hiding this comment.
Looking pretty good. I've left several minor suggestions. Looking forward to seeing the tests.
There was a problem hiding this comment.
Try to keep the diff to just contain the meaningful part of your change (e.g. explicitly stage individual files rather than doing git commit -a).
src/dune_lang/package_dependency.ml
Outdated
| Package_name.equal name t.name | ||
| && Option.equal Package_constraint.equal constraint_ t.constraint_ | ||
| ;; | ||
| ;; No newline at end of file |
There was a problem hiding this comment.
Try to avoid adding/removing the trailing newline from the diff (ie. only include the meaningful part of your change). Some editors automatically mess with file endings. The problem with checking this in is that the next person who touches the file will have to deal with the changed line ending from their editor and so on. My advice would be to configure your editor to leave file endings alone, and also to use git add -p or similar to only stage the meaningful changes.
src/dune_lang/package_dependency.ml
Outdated
| "Possible typo in constraint for dependency %S: '(= version)' might be a mistake." | ||
| (Package_name.to_string name) | ||
| ] | ||
| ~hints:[ Pp.text "Did you mean to use the `:version` variable instead? Example: (depends (bar :version))" ] |
There was a problem hiding this comment.
Instead of (depends (bar :version)), it would be better to print the actual package name from the user's dune-project. Also (depends (bar :version)) isn't the right syntax; it should be (depends (bar (= :version))).
src/dune_lang/package_dependency.ml
Outdated
| "Possible typo in constraint for dependency %S: ':with_test' might be a mistake." | ||
| (Package_name.to_string name) | ||
| ] | ||
| ~hints:[ Pp.text "Did you mean to use ':with-test' instead? Example: (depends (bar :with-test))" ] |
There was a problem hiding this comment.
Replace the bar with the package name from the offending line.
src/dune_pkg/package_dependency.ml
Outdated
| | Ok constraint_ -> { name; constraint_ } | ||
| | Ok constraint_ -> | ||
| let dep = { name; constraint_ } in | ||
| (* We don't need to check for typos here since it's already handled in decode *) |
There was a problem hiding this comment.
I don't think this comment is necessary.
There was a problem hiding this comment.
@gridbugs Thanks for the feedback, I've noted all requested changes and will adjust accordingly.
There was a problem hiding this comment.
@gridbugs

, here are my updates, attached to this comment is a screenshot showing the result of running the test
There was a problem hiding this comment.
Nice. Please include the test in this PR.
There was a problem hiding this comment.
Nice. Please include the test in this PR.
Added , please kindly review
src/dune_pkg/package_dependency.ml
Outdated
| (match Constraint.opt_of_opam_condition condition with | ||
| | Ok constraint_ -> { name; constraint_ } | ||
| | Ok constraint_ -> | ||
| let dep = { name; constraint_ } in |
There was a problem hiding this comment.
There's no need for this let binding anymore. You can just revert this file to its original state.
There was a problem hiding this comment.
There's no need for this let binding anymore. You can just revert this file to its original state.
@gridbugs Updated.
src/dune_pkg/package_dependency.ml
Outdated
| let name = Package_name.of_opam_package_name name in | ||
| (match Constraint.opt_of_opam_condition condition with | ||
| | Ok constraint_ -> { name; constraint_ } | ||
| | Ok constraint_ -> {name; constraint_} |
There was a problem hiding this comment.
Run dune fmt to automatically fix the style.
There was a problem hiding this comment.
Alright @gridbugs, thanks for your guiding me all the way. Implementing final changes now.
|
This is getting pretty close to done. A few things left before I'll consider merging it:
I'll mark this as not a draft so others can take a look if they want. |
efdef19 to
d7af4b7
Compare
@gridbugs all done, please kindly review |
There was a problem hiding this comment.
Please remove unrelated changes from the readme.
|
Looks like your commit is not signed (the "DCO" test is failing). Run |
Okay thanks, let me try again. |
|
One more thing I'll ask of you is to add a file to doc/changes describing the change (follow the example of the other files in that directory). |
Alright mentor, on it. |
d7af4b7 to
e62f5df
Compare
@gridbugs I've added the docs. Please kindly review. Thanks. |
doc/changes/11575.md
Outdated
There was a problem hiding this comment.
Thanks for the detailed explanation, but this just needed to be a single line for our change log. You're welcome to write more docs elsewhere but I think for this particular change it won't be necessary. I'll fix up this file to match other changelog entries before and merge this PR today.
There was a problem hiding this comment.
Alright, noted with thanks.
8ab32bc to
debedeb
Compare
4eeb981 to
97f4491
Compare
61aca2c to
c6bb552
Compare
|
@gridbugs , added updates, please kindly review, thanks |
Signed-off-by: kemsguy7 <mattidungafa@gmail.com>
c6bb552 to
38b9b8d
Compare
There was a problem hiding this comment.
Since this is related to package management, shouldn't we move this to an experimental subfolder or not add a changelog?
CHANGES: ### Fixed - Fixed a bug that was causing cram tests attached to multiple aliases to be run multiple times. (ocaml/dune#11547, @Alizter) - Fix: pass pkg-config (extra) args in all pkgconfig invocations. A missing --personality flag would result in pkgconf not finding libraries in some contexts. (ocaml/dune#11619, @MisterDA) - Fix: Evaluate `enabled_if` when computing the stubs for stanzas such as `foreign_library` (ocaml/dune#11707, @Alizter, @rgrinberg) - Fix $ dune describe pp for libraries in the presence of `(include_subdirs unqualified)` (ocaml/dune#11729, fixes ocaml/dune#10999, @rgrinberg) - Fix `$ dune subst` in sub directories of a git repository (ocaml/dune#11760, fixes ocaml/dune#11045, @Richard-Degenne) - Fix a crash involving `Path.drop_prefix` when using Melange on Windows (ocaml/dune#11767, @nojb) ### Added - Added detection and warning for common typos in package dependency constraints (ocaml/dune#11600, fixes ocaml/dune#11575, @kemsguy7) - Added `(extra_objects)` field to `(foreign_library)` stanza with `(:include)` support. (ocaml/dune#11683, @Alizter) ### Changed - Allow build RPC messages to be handled by dune's RPC server in eager watch mode (ocaml/dune#11622, @gridbugs) - Allow concurrent build with RPC server (ocaml/dune#11712, @gridbugs)
CHANGES: ### Fixed - Fixed a bug that was causing cram tests attached to multiple aliases to be run multiple times. (ocaml/dune#11547, @Alizter) - Fix: pass pkg-config (extra) args in all pkgconfig invocations. A missing --personality flag would result in pkgconf not finding libraries in some contexts. (ocaml/dune#11619, @MisterDA) - Fix: Evaluate `enabled_if` when computing the stubs for stanzas such as `foreign_library` (ocaml/dune#11707, @Alizter, @rgrinberg) - Fix $ dune describe pp for libraries in the presence of `(include_subdirs unqualified)` (ocaml/dune#11729, fixes ocaml/dune#10999, @rgrinberg) - Fix `$ dune subst` in sub directories of a git repository (ocaml/dune#11760, fixes ocaml/dune#11045, @Richard-Degenne) - Fix a crash involving `Path.drop_prefix` when using Melange on Windows (ocaml/dune#11767, @nojb) ### Added - Added detection and warning for common typos in package dependency constraints (ocaml/dune#11600, fixes ocaml/dune#11575, @kemsguy7) - Added `(extra_objects)` field to `(foreign_library)` stanza with `(:include)` support. (ocaml/dune#11683, @Alizter) ### Changed - Allow build RPC messages to be handled by dune's RPC server in eager watch mode (ocaml/dune#11622, @gridbugs) - Allow concurrent build with RPC server (ocaml/dune#11712, @gridbugs)
Signed-off-by: kemsguy7 <mattidungafa@gmail.com>
@gridbugs, Here's my draft PR for issue. #11575, please kindly review and give feedback let me know if I'm on track.