diff --git a/src/dune_rules/expander.ml b/src/dune_rules/expander.ml index d026505a405..d05e57eb3f2 100644 --- a/src/dune_rules/expander.ml +++ b/src/dune_rules/expander.ml @@ -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::%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 diff --git a/test/blackbox-tests/test-cases/github5264.t b/test/blackbox-tests/test-cases/github5264.t index 0741875917d..df00ed1265c 100644 --- a/test/blackbox-tests/test-cases/github5264.t +++ b/test/blackbox-tests/test-cases/github5264.t @@ -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::} 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::.} 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]