diff --git a/src/dune/cinaps.ml b/src/dune/cinaps.ml index 2c56acb5dda..1a8a1df5c7e 100644 --- a/src/dune/cinaps.ml +++ b/src/dune/cinaps.ml @@ -7,7 +7,7 @@ type t = ; files : Predicate_lang.t ; libraries : Lib_dep.t list ; preprocess : Dune_file.Preprocess_map.t - ; preprocessor_deps : Dune_file.Dep_conf.t list + ; preprocessor_deps : Loc.t * Dune_file.Dep_conf.t list ; flags : Ocaml_flags.Spec.t } @@ -26,7 +26,10 @@ let decode = field "preprocess" Dune_file.Preprocess_map.decode ~default:Dune_file.Preprocess_map.default and+ preprocessor_deps = - field "preprocessor_deps" (repeat Dune_file.Dep_conf.decode) ~default:[] + located + (field "preprocessor_deps" + (repeat Dune_file.Dep_conf.decode) + ~default:[]) and+ libraries = field "libraries" (Dune_file.Lib_deps.decode ~allow_re_export:false) @@ -79,9 +82,7 @@ let gen_rules sctx t ~dir ~scope = let preprocess = Preprocessing.make sctx ~dir ~expander ~dep_kind:Required ~lint:Dune_file.Preprocess_map.no_preprocessing ~preprocess:t.preprocess - ~preprocessor_deps: - (Super_context.Deps.interpret sctx ~expander t.preprocessor_deps) - ~lib_name:None ~scope + ~preprocessor_deps:t.preprocessor_deps ~lib_name:None ~scope in let modules = Modules.exe_unwrapped modules diff --git a/src/dune/dune_file.ml b/src/dune/dune_file.ml index 3094234f7a2..fe21762bc1b 100644 --- a/src/dune/dune_file.ml +++ b/src/dune/dune_file.ml @@ -537,7 +537,7 @@ module Buildable = struct ; c_names : Ordered_set_lang.t option ; cxx_names : Ordered_set_lang.t option ; preprocess : Preprocess_map.t - ; preprocessor_deps : Dep_conf.t list + ; preprocessor_deps : Loc.t * Dep_conf.t list ; lint : Preprocess_map.t ; flags : Ocaml_flags.Spec.t ; js_of_ocaml : Js_of_ocaml.t @@ -554,7 +554,7 @@ module Buildable = struct and+ preprocess = field "preprocess" Preprocess_map.decode ~default:Preprocess_map.default and+ preprocessor_deps = - field "preprocessor_deps" (repeat Dep_conf.decode) ~default:[] + located (field "preprocessor_deps" (repeat Dep_conf.decode) ~default:[]) and+ lint = field "lint" Lint.decode ~default:Lint.default and+ c_flags = Dune_env.Stanza.c_flags ~since:since_c and+ c_names = field_o "c_names" (check_c Ordered_set_lang.decode) diff --git a/src/dune/dune_file.mli b/src/dune/dune_file.mli index 4ee038e875c..5a6c33a7c14 100644 --- a/src/dune/dune_file.mli +++ b/src/dune/dune_file.mli @@ -116,7 +116,7 @@ module Buildable : sig ; c_names : Ordered_set_lang.t option ; cxx_names : Ordered_set_lang.t option ; preprocess : Preprocess_map.t - ; preprocessor_deps : Dep_conf.t list + ; preprocessor_deps : Loc.t * Dep_conf.t list ; lint : Lint.t ; flags : Ocaml_flags.Spec.t ; js_of_ocaml : Js_of_ocaml.t diff --git a/src/dune/exe_rules.ml b/src/dune/exe_rules.ml index be67c5405b4..fd4d11dbbf2 100644 --- a/src/dune/exe_rules.ml +++ b/src/dune/exe_rules.ml @@ -14,12 +14,10 @@ let executables_rules ~sctx ~dir ~expander ~dir_contents ~scope ~compile_info let modules = Dir_contents.modules_of_executables dir_contents ~first_exe ~obj_dir in - let preprocessor_deps = - SC.Deps.interpret sctx exes.buildable.preprocessor_deps ~expander - in let pp = Preprocessing.make sctx ~dir ~dep_kind:Required ~scope ~expander - ~preprocess:exes.buildable.preprocess ~preprocessor_deps + ~preprocess:exes.buildable.preprocess + ~preprocessor_deps:exes.buildable.preprocessor_deps ~lint:exes.buildable.lint ~lib_name:None in let modules = diff --git a/src/dune/lib_rules.ml b/src/dune/lib_rules.ml index 825f731f24e..860fd6d2eb3 100644 --- a/src/dune/lib_rules.ml +++ b/src/dune/lib_rules.ml @@ -278,9 +278,7 @@ let cctx (lib : Library.t) ~sctx ~source_modules ~dir ~expander ~scope let pp = Preprocessing.make sctx ~dir ~dep_kind ~scope ~preprocess:lib.buildable.preprocess ~expander - ~preprocessor_deps: - (Super_context.Deps.interpret sctx ~expander - lib.buildable.preprocessor_deps) + ~preprocessor_deps:lib.buildable.preprocessor_deps ~lint:lib.buildable.lint ~lib_name:(Some (snd lib.name)) in diff --git a/src/dune/preprocessing.ml b/src/dune/preprocessing.ml index c5ddb6ea2e3..ea5d9fff1b3 100644 --- a/src/dune/preprocessing.ml +++ b/src/dune/preprocessing.ml @@ -566,20 +566,36 @@ type t = (Module.t -> lint:bool -> Module.t) Per_module.t let dummy = Per_module.for_all (fun m ~lint:_ -> m) +let is_preprocessing t = + Per_module.fold t ~init:true ~f:(fun p acc -> + match p with + | Preprocess.Without_future_syntax.No_preprocessing -> false + | _ -> acc) + let make sctx ~dir ~expander ~dep_kind ~lint ~preprocess ~preprocessor_deps ~lib_name ~scope = + let preprocess = + Per_module.map preprocess ~f:(fun pp -> + Dune_file.Preprocess.remove_future_syntax ~for_:Compiler pp + (Super_context.context sctx).version) + in let preprocessor_deps = - Build.memoize "preprocessor deps" preprocessor_deps + let loc, deps = preprocessor_deps in + ( if not (is_preprocessing preprocess) && not (List.is_empty deps) then + let is_error = Dune_project.dune_version (Scope.project scope) >= (2, 0) in + User_warning.emit ~loc ~is_error + [ Pp.text + "This preprocessor_deps field will be ignored because no \ + preprocessor is configured." + ] ); + SC.Deps.interpret sctx deps ~expander |> Build.memoize "preprocessor deps" in let lint_module = Staged.unstage (lint_module sctx ~dir ~expander ~dep_kind ~lint ~lib_name ~scope) in Per_module.map preprocess ~f:(fun pp -> - match - Dune_file.Preprocess.remove_future_syntax ~for_:Compiler pp - (Super_context.context sctx).version - with + match pp with | No_preprocessing -> fun m ~lint -> let ast = setup_dialect_rules sctx ~dir ~dep_kind ~expander m in diff --git a/src/dune/preprocessing.mli b/src/dune/preprocessing.mli index 845093cc530..3aee81bb281 100644 --- a/src/dune/preprocessing.mli +++ b/src/dune/preprocessing.mli @@ -15,7 +15,7 @@ val make : -> dep_kind:Lib_deps_info.Kind.t -> lint:Dune_file.Preprocess_map.t -> preprocess:Dune_file.Preprocess_map.t - -> preprocessor_deps:unit Build.t + -> preprocessor_deps:Loc.t * Dune_file.Dep_conf.t list -> lib_name:Lib_name.Local.t option -> scope:Scope.t -> t diff --git a/test/blackbox-tests/dune.inc b/test/blackbox-tests/dune.inc index 00bc67a53ea..df76133cf73 100644 --- a/test/blackbox-tests/dune.inc +++ b/test/blackbox-tests/dune.inc @@ -1606,6 +1606,14 @@ test-cases/unreadable-src (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))) +(alias + (name unused-preprocessor-deps) + (deps (package dune) (source_tree test-cases/unused-preprocessor-deps)) + (action + (chdir + test-cases/unused-preprocessor-deps + (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))) + (alias (name upgrader) (deps (package dune) (source_tree test-cases/upgrader)) @@ -2003,6 +2011,7 @@ (alias trace-file) (alias transitive-deps-mode) (alias unreadable-src) + (alias unused-preprocessor-deps) (alias upgrader) (alias use-meta) (alias variables-for-artifacts) @@ -2199,6 +2208,7 @@ (alias trace-file) (alias transitive-deps-mode) (alias unreadable-src) + (alias unused-preprocessor-deps) (alias upgrader) (alias variables-for-artifacts) (alias variant-dep-stack) diff --git a/test/blackbox-tests/test-cases/unused-preprocessor-deps/dune b/test/blackbox-tests/test-cases/unused-preprocessor-deps/dune new file mode 100644 index 00000000000..9a5f8e74b38 --- /dev/null +++ b/test/blackbox-tests/test-cases/unused-preprocessor-deps/dune @@ -0,0 +1,11 @@ +(executable + (name a) + (modules a) + ;(preprocess (pps ppx_deriving.std)) + (preprocessor_deps does-not-exist.txt)) + +(library + (name b) + (modules b) + (preprocess future_syntax) + (preprocessor_deps does-not-exist.txt)) diff --git a/test/blackbox-tests/test-cases/unused-preprocessor-deps/run.t b/test/blackbox-tests/test-cases/unused-preprocessor-deps/run.t new file mode 100644 index 00000000000..9272b0feee9 --- /dev/null +++ b/test/blackbox-tests/test-cases/unused-preprocessor-deps/run.t @@ -0,0 +1,27 @@ +`preprocessor_deps` is provided without `preprocess` and is ignored. +Should warn. + + $ touch a.ml b.ml + + $ echo "(lang dune 1.11)" > dune-project + $ echo "(allow_approximate_merlin)" >> dune-project + $ dune build + File "dune", line 5, characters 1-39: + 5 | (preprocessor_deps does-not-exist.txt)) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + Warning: This preprocessor_deps field will be ignored because no preprocessor + is configured. + File "dune", line 11, characters 1-39: + 11 | (preprocessor_deps does-not-exist.txt)) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + Warning: This preprocessor_deps field will be ignored because no preprocessor + is configured. + + $ echo "(lang dune 2.0)" > dune-project + $ dune build + File "dune", line 5, characters 1-39: + 5 | (preprocessor_deps does-not-exist.txt)) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + Error: This preprocessor_deps field will be ignored because no preprocessor + is configured. + [1]