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 about unused preprocessor_deps #2660

Merged
merged 7 commits into from
Sep 25, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Trigger a warning when preprocessor_deps would be ignored
Signed-off-by: Jules Aguillon <juloo.dsi@gmail.com>
  • Loading branch information
Julow committed Sep 20, 2019
commit 06c6553fdf385d8c441b46a1fe9a2bb3704472c7
10 changes: 6 additions & 4 deletions src/dune/cinaps.ml
Original file line number Diff line number Diff line change
@@ -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,8 +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:t.preprocessor_deps
~lib_name:None ~scope
~preprocessor_deps:t.preprocessor_deps ~lib_name:None ~scope
in
let modules =
Modules.exe_unwrapped modules
4 changes: 2 additions & 2 deletions src/dune/dune_file.ml
Original file line number Diff line number Diff line change
@@ -562,7 +562,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
@@ -579,7 +579,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)
2 changes: 1 addition & 1 deletion src/dune/dune_file.mli
Original file line number Diff line number Diff line change
@@ -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
26 changes: 20 additions & 6 deletions src/dune/preprocessing.ml
Original file line number Diff line number Diff line change
@@ -566,21 +566,35 @@ 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 =
SC.Deps.interpret sctx preprocessor_deps ~expander
|> Build.memoize "preprocessor deps"
let loc, deps = preprocessor_deps in
if (not (is_preprocessing preprocess)) && not (List.is_empty deps) then
User_warning.emit ~loc
[ 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
2 changes: 1 addition & 1 deletion src/dune/preprocessing.mli
Original file line number Diff line number Diff line change
@@ -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:Dune_file.Dep_conf.t list
-> preprocessor_deps:Loc.t * Dune_file.Dep_conf.t list
-> lib_name:Lib_name.Local.t option
-> scope:Scope.t
-> t
5 changes: 5 additions & 0 deletions test/blackbox-tests/test-cases/unused-preprocessor-deps/run.t
Original file line number Diff line number Diff line change
@@ -2,3 +2,8 @@
Should warn.

$ dune build
File "dune", line 4, characters 1-39:
4 | (preprocessor_deps does-not-exist.txt))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Warning: This preprocessor_deps field will be ignored because no preprocessor
is configured.