Skip to content
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

Warn when lang versions have an ignored suffix #5040

Merged
2 commits merged into from
Nov 3, 2021
Merged
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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Unreleased
- Report cycles between virtual libraries and their implementation (#5050,
fixes #2896, @rgrinberg)

- Warn when lang versions have an ignored suffix. `(lang dune 2.3.4)` or `(lang
dune 2.3suffix)` were silently parsed as `2.3` and we know suggest to remove
the prefix. (#5040, @emillon)

- Allow users to specify dynamic dependencies in rules. For example `(deps
%{read:foo.gen})` (#4662, fixes #4089, @jeremiedimino)

Expand Down
11 changes: 9 additions & 2 deletions src/dune_lang/syntax.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ module Version = struct
let open Decoder in
raw >>| function
| Atom (loc, A s) -> (
match Scanf.sscanf s "%u.%u" (fun a b -> (a, b)) with
| Ok s -> s
match Scanf.sscanf s "%u.%u%s" (fun a b s -> ((a, b), s)) with
| Ok (v, "") -> v
| Ok (((a, b) as v), s) ->
let is_error = v >= (3, 0) in
User_warning.emit ~loc ~is_error
[ Pp.textf "The %S part is ignored here." s
; Pp.textf "This version is parsed as just %d.%d." a b
];
v
| Error () ->
User_error.raise ~loc [ Pp.text "Atom of the form NNN.NNN expected" ])
| sexp -> User_error.raise ~loc:(Ast.loc sexp) [ Pp.text "Atom expected" ]
Expand Down
54 changes: 54 additions & 0 deletions test/blackbox-tests/test-cases/lang-dune-warning.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
If (lang dune) does not use a valid format on a 2.x project, a warning is
emitted:

$ cat > dune-project << EOF
> (lang dune 2.3.0)
> EOF

$ dune build
File "dune-project", line 1, characters 11-16:
1 | (lang dune 2.3.0)
^^^^^
Warning: The ".0" part is ignored here.
This version is parsed as just 2.3.

$ cat > dune-project << EOF
> (lang dune 2.4suffix)
> EOF

$ dune build
File "dune-project", line 1, characters 11-20:
1 | (lang dune 2.4suffix)
^^^^^^^^^
Warning: The "suffix" part is ignored here.
This version is parsed as just 2.4.

If the version is valid, no warning is emitted:

$ cat > dune-project << EOF
> (lang dune 2.2)
> EOF

$ dune build

Starting with lang 3.0, the warning turns into an error.

$ cat > dune-project << EOF
> (lang dune 3.0suffix)
> EOF

$ dune build
File "dune-project", line 1, characters 11-20:
1 | (lang dune 3.0suffix)
^^^^^^^^^
Error: The "suffix" part is ignored here.
This version is parsed as just 3.0.
[1]

And without suffix it is accepted.

$ cat > dune-project << EOF
> (lang dune 3.0)
> EOF

$ dune build