Split Preproressing.pp_and... in two functions

Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
This commit is contained in:
Jeremie Dimino 2018-05-25 12:01:02 +01:00 committed by Jérémie Dimino
parent 5c4027aff8
commit ac1c407cab
3 changed files with 85 additions and 74 deletions

View File

@ -555,8 +555,8 @@ module Gen(P : Install_rules.Params) = struct
in
(* Preprocess before adding the alias module as it doesn't need
preprocessing *)
let modules =
Preprocessing.pp_and_lint_modules sctx ~dir ~dep_kind ~modules ~scope
let pp =
Preprocessing.make sctx ~dir ~dep_kind ~scope
~preprocess:lib.buildable.preprocess
~preprocessor_deps:
(SC.Deps.interpret sctx ~scope ~dir
@ -564,6 +564,7 @@ module Gen(P : Install_rules.Params) = struct
~lint:lib.buildable.lint
~lib_name:(Some lib.name)
in
let modules = Preprocessing.pp_modules pp modules in
let modules =
match alias_module with
@ -817,13 +818,16 @@ module Gen(P : Install_rules.Params) = struct
SC.Deps.interpret sctx exes.buildable.preprocessor_deps
~scope ~dir
in
Preprocessing.pp_and_lint_modules sctx ~dir ~dep_kind:Required ~modules
let pp =
Preprocessing.make sctx ~dir ~dep_kind:Required
~scope
~preprocess:exes.buildable.preprocess
~preprocessor_deps
~lint:exes.buildable.lint
~lib_name:None
in
Preprocessing.pp_modules pp modules
in
let programs =
List.map exes.names ~f:(fun (loc, name) ->

View File

@ -293,9 +293,9 @@ let lint_module sctx ~dir ~dep_kind ~lint ~lib_name ~scope = Staged.stage (
fun ~(source : Module.t) ~ast ->
Per_module.get lint source.name ~source ~ast)
(* Generate rules to build the .pp files and return a new module map
where all filenames point to the .pp files *)
let pp_and_lint_modules sctx ~dir ~dep_kind ~modules ~lint ~preprocess
type t = (Module.t -> Module.t) Per_module.t
let make sctx ~dir ~dep_kind ~lint ~preprocess
~preprocessor_deps ~lib_name ~scope =
let preprocessor_deps =
Build.memoize "preprocessor deps" preprocessor_deps
@ -303,7 +303,6 @@ let pp_and_lint_modules sctx ~dir ~dep_kind ~modules ~lint ~preprocess
let lint_module =
Staged.unstage (lint_module sctx ~dir ~dep_kind ~lint ~lib_name ~scope)
in
let preprocess =
Per_module.map preprocess ~f:(function
| Preprocess.No_preprocessing ->
(fun m ->
@ -359,6 +358,7 @@ let pp_and_lint_modules sctx ~dir ~dep_kind ~modules ~lint ~preprocess
; A "-o"; Target dst
; Ml_kind.ppx_driver_flag kind; Dep src
])))))
in
let pp_modules t modules =
Module.Name.Map.map modules ~f:(fun (m : Module.t) ->
Per_module.get preprocess m.name m)
Per_module.get t m.name m)

View File

@ -2,18 +2,25 @@
open! Import
(** Setup pre-processing and linting rules and return the list of
pre-processed modules *)
val pp_and_lint_modules
(** Preprocessing object *)
type t
val make
: Super_context.t
-> dir:Path.t
-> dep_kind:Build.lib_dep_kind
-> modules:Module.t Module.Name.Map.t
-> lint:Jbuild.Preprocess_map.t
-> preprocess:Jbuild.Preprocess_map.t
-> preprocessor_deps:(unit, Path.t list) Build.t
-> lib_name:string option
-> scope:Scope.t
-> t
(** Setup the preprocessing rules for the following modules and
returns the translated modules *)
val pp_modules
: t
-> Module.t Module.Name.Map.t
-> Module.t Module.Name.Map.t
(** Get a path to a cached ppx driver *)