Skip to content

Commit

Permalink
Fix #5264
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
Co-authored-by: Andrey Mokhov <andrey.mokhov@gmail.com>
  • Loading branch information
2 people authored and Jérémie Dimino committed Dec 8, 2021
1 parent 06fbdd1 commit 2418f62
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 31 deletions.
56 changes: 46 additions & 10 deletions src/dune_rules/expander.ml
Original file line number Diff line number Diff line change
Expand Up @@ -529,16 +529,52 @@ let expand_pform_gen ~(context : Context.t) ~bindings ~dir ~source
let p =
let open Memo.Build.O in
Resolve.Build.peek p >>| function
| Ok p ->
if
(not lib_exec) || (not Sys.win32)
|| Filename.extension s = ".exe"
then
dep p
else
let p_exe = Path.extend_basename p ~suffix:".exe" in
Action_builder.if_file_exists p_exe ~then_:(dep p_exe)
~else_:(dep p)
| Ok p -> (
match file with
| ""
| "." ->
let lang_version =
Dune_project.dune_version (Scope.project t.scope)
in
if lang_version < (3, 0) then
Action_builder.return [ Value.Path p ]
else
User_error.raise
~loc:(Dune_lang.Template.Pform.loc source)
[ Pp.textf
"The form %%{%s:<libname>:%s} is no longer \
supported since version 3.0 of the Dune \
language."
(if lib_private then
"lib-private"
else
"lib")
file
]
~hints:
[ (match Lib_name.to_string lib with
| "ctypes" ->
Pp.text
"Did you know that Dune 3.0 supports ctypes \
natively? See the manual for more details."
| _ ->
Pp.textf
"If you are trying to use this form to refer \
to include a directory, you should instead \
use (foreign_stubs (include_dirs (lib %s))). \
See the manual for more details."
(Lib_name.to_string lib))
]
| _ ->
if
(not lib_exec) || (not Sys.win32)
|| Filename.extension s = ".exe"
then
dep p
else
let p_exe = Path.extend_basename p ~suffix:".exe" in
Action_builder.if_file_exists p_exe ~then_:(dep p_exe)
~else_:(dep p))
| Error () ->
let p =
if lib_private then
Expand Down
45 changes: 24 additions & 21 deletions test/blackbox-tests/test-cases/github5264.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,43 @@ syntax in lang Dune < 3.0.

$ cat > dune <<'EOF'
> (library (name ctypes))
> (library (name other))
> (rule
> (alias a)
> (action (run echo %{lib:ctypes:})))
> (action (run echo %{lib-private:ctypes:})))
> (rule
> (alias b)
> (action (run echo %{lib:ctypes:})))
> (action (run echo %{lib-private:other:.})))
> EOF
At the moment, we get a bad error with all language versions:
We still support it with older version of the language, for backward
compatibility purposes:
$ echo '(lang dune 2.9)' > dune-project
$ dune build @a
Error: File unavailable: /home/dim/.opam/4.13.1/lib/ctypes
This is not a regular file (S_DIR)
-> required by %{lib:ctypes:} at dune:4
-> required by alias a in dune:2
[1]
.
$ dune build @b
Error: File unavailable: /home/dim/.opam/4.13.1/lib/ctypes
This is not a regular file (S_DIR)
-> required by %{lib:ctypes:} at dune:7
-> required by alias b in dune:5
[1]
.
But we are more strict since 3.0:
$ echo '(lang dune 3.0)' > dune-project
$ dune build @a
Error: File unavailable: /home/dim/.opam/4.13.1/lib/ctypes
This is not a regular file (S_DIR)
-> required by %{lib:ctypes:} at dune:4
-> required by alias a in dune:2
File "dune", line 5, characters 19-41:
5 | (action (run echo %{lib-private:ctypes:})))
^^^^^^^^^^^^^^^^^^^^^^
Error: The form %{lib-private:<libname>:} is no longer supported since
version 3.0 of the Dune language.
Hint: Did you know that Dune 3.0 supports ctypes natively? See the manual for
more details.
[1]
$ dune build @b
Error: File unavailable: /home/dim/.opam/4.13.1/lib/ctypes
This is not a regular file (S_DIR)
-> required by %{lib:ctypes:} at dune:7
-> required by alias b in dune:5
File "dune", line 8, characters 19-41:
8 | (action (run echo %{lib-private:other:.})))
^^^^^^^^^^^^^^^^^^^^^^
Error: The form %{lib-private:<libname>:.} is no longer supported since
version 3.0 of the Dune language.
Hint: If you are trying to use this form to refer to an include directory,
you should instead use (foreign_stubs (include_dirs (lib other))). See the
manual for more details.
[1]

0 comments on commit 2418f62

Please sign in to comment.