diff --git a/src/gen_rules.ml b/src/gen_rules.ml index a2b5934f..8d2beadc 100644 --- a/src/gen_rules.ml +++ b/src/gen_rules.ml @@ -548,7 +548,7 @@ module Gen(P : Install_rules.Params) = struct (* Preprocess before adding the alias module as it doesn't need preprocessing *) let pp = - Preprocessing.make sctx ~dir ~dep_kind ~scope + Preprocessing.make sctx ~dir ~obj_dir ~dep_kind ~scope ~preprocess:lib.buildable.preprocess ~preprocessor_deps: (SC.Deps.interpret sctx ~scope ~dir @@ -805,6 +805,11 @@ module Gen(P : Install_rules.Params) = struct let executables_rules ~dir ~all_modules ~dir_kind ~modules_partitioner ~scope ~compile_info (exes : Executables.t) = + (* Use "eobjs" rather than "objs" to avoid a potential conflict + with a library of the same name *) + let obj_dir = + Utils.executable_object_directory ~dir (List.hd exes.names |> snd) + in let requires = Lib.Compile.requires compile_info in let modules = parse_modules ~all_modules ~buildable:exes.buildable @@ -815,7 +820,7 @@ module Gen(P : Install_rules.Params) = struct ~scope ~dir in let pp = - Preprocessing.make sctx ~dir ~dep_kind:Required + Preprocessing.make sctx ~dir ~obj_dir ~dep_kind:Required ~scope ~preprocess:exes.buildable.preprocess ~preprocessor_deps @@ -874,12 +879,6 @@ module Gen(P : Install_rules.Params) = struct ~standard:(Build.return []) in - (* Use "eobjs" rather than "objs" to avoid a potential conflict - with a library of the same name *) - let obj_dir = - Utils.executable_object_directory ~dir (List.hd programs).name - in - let cctx = Compilation_context.create () ~super_context:sctx diff --git a/src/preprocessing.ml b/src/preprocessing.ml index daef1ef7..f01cd68c 100644 --- a/src/preprocessing.ml +++ b/src/preprocessing.ml @@ -4,9 +4,11 @@ open Jbuild module SC = Super_context -let pped_module m ~f = +let pped_module m ~obj_dir ~f = Module.map_files m ~f:(fun kind file -> - let pp_fname = Path.extend_basename file.path ~suffix:".pp" in + let pp_fname = + Path.relative obj_dir (Path.basename file.path ^ ".pp") + in f kind file.path pp_fname; { file with path = pp_fname }) @@ -401,7 +403,7 @@ let cookie_library_name lib_name = (* Generate rules for the reason modules in [modules] and return a a new module with only OCaml sources *) -let setup_reason_rules sctx (m : Module.t) = +let setup_reason_rules sctx ~obj_dir (m : Module.t) = let ctx = SC.context sctx in let refmt = Artifacts.binary (SC.artifacts sctx) "refmt" ~hint:"opam install reason" in @@ -420,7 +422,7 @@ let setup_reason_rules sctx (m : Module.t) = let ml = { Module.File. syntax = OCaml - ; path = Path.extend_basename f.path ~suffix:".ast" + ; path = Path.relative obj_dir (Path.basename f.path ^ ".ast") } in SC.add_rule sctx (rule f.path ml.path); @@ -510,7 +512,7 @@ type t = (Module.t -> lint:bool -> Module.t) Per_module.t let dummy = Per_module.for_all (fun m ~lint:_ -> m) -let make sctx ~dir ~dep_kind ~lint ~preprocess +let make sctx ~dir ~obj_dir ~dep_kind ~lint ~preprocess ~preprocessor_deps ~lib_name ~scope ~dir_kind = let preprocessor_deps = Build.memoize "preprocessor deps" preprocessor_deps @@ -522,13 +524,13 @@ let make sctx ~dir ~dep_kind ~lint ~preprocess Per_module.map preprocess ~f:(function | Preprocess.No_preprocessing -> (fun m ~lint -> - let ast = setup_reason_rules sctx m in + let ast = setup_reason_rules sctx m ~obj_dir in if lint then lint_module ~ast ~source:m; ast) | Action (loc, action) -> (fun m ~lint -> let ast = - pped_module m ~f:(fun _kind src dst -> + pped_module m ~obj_dir ~f:(fun _kind src dst -> let bindings = Pform.Map.input_file src in SC.add_rule sctx (preprocessor_deps @@ -547,8 +549,9 @@ let make sctx ~dir ~dep_kind ~lint ~preprocess ~dep_kind ~bindings ~targets:(Static [dst]) + ~targets_dir:obj_dir ~scope)) - |> setup_reason_rules sctx in + |> setup_reason_rules sctx ~obj_dir in if lint then lint_module ~ast ~source:m; ast) | Pps { loc; pps; flags } -> @@ -574,9 +577,9 @@ let make sctx ~dir ~dep_kind ~lint ~preprocess ~standard:(Build.return []))) in (fun m ~lint -> - let ast = setup_reason_rules sctx m in + let ast = setup_reason_rules sctx m ~obj_dir in if lint then lint_module ~ast ~source:m; - pped_module ast ~f:(fun kind src dst -> + pped_module ast ~obj_dir ~f:(fun kind src dst -> SC.add_rule sctx (promote_correction ~suffix:corrected_suffix (Option.value_exn (Module.file m kind)) diff --git a/src/preprocessing.mli b/src/preprocessing.mli index 024f116a..022ea4e5 100644 --- a/src/preprocessing.mli +++ b/src/preprocessing.mli @@ -10,6 +10,7 @@ val dummy : t val make : Super_context.t -> dir:Path.t + -> obj_dir:Path.t -> dep_kind:Build.lib_dep_kind -> lint:Jbuild.Preprocess_map.t -> preprocess:Jbuild.Preprocess_map.t diff --git a/src/super_context.ml b/src/super_context.ml index 96b8f7c1..2dd6f8ce 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -772,8 +772,8 @@ module Action = struct Exn.code_error "Unexpected variable in step2" ["var", String_with_vars.Var.sexp_of_t pform])) - let run sctx ~loc ~bindings t ~dir ~dep_kind - ~targets:targets_written_by_user ~scope + let run sctx ~loc ~bindings ~dir ~dep_kind + ~targets:targets_written_by_user ~scope ?(targets_dir=dir) t : (Path.t Bindings.t, Action.t) Build.t = let bindings = Pform.Map.superpose sctx.pforms bindings in let map_exe = map_exe sctx in @@ -824,7 +824,7 @@ module Action = struct in let targets = Path.Set.to_list targets in List.iter targets ~f:(fun target -> - if Path.parent_exn target <> dir then + if Path.parent_exn target <> targets_dir then Loc.fail loc "This action has targets in a different directory than the current \ one, this is not allowed by dune at the moment:\n%s" diff --git a/src/super_context.mli b/src/super_context.mli index 2dd5db94..0b37739e 100644 --- a/src/super_context.mli +++ b/src/super_context.mli @@ -240,11 +240,12 @@ module Action : sig : t -> loc:Loc.t -> bindings:Pform.Map.t - -> Action.Unexpanded.t -> dir:Path.t -> dep_kind:Build.lib_dep_kind -> targets:targets -> scope:Scope.t + -> ?targets_dir:Path.t (* default: dir *) + -> Action.Unexpanded.t -> (Path.t Bindings.t, Action.t) Build.t end diff --git a/test/blackbox-tests/test-cases/dune-ppx-driver-system/run.t b/test/blackbox-tests/test-cases/dune-ppx-driver-system/run.t index 5f5fedcc..67cca07e 100644 --- a/test/blackbox-tests/test-cases/dune-ppx-driver-system/run.t +++ b/test/blackbox-tests/test-cases/dune-ppx-driver-system/run.t @@ -41,7 +41,7 @@ Same, but with error pointing to .ppx Test the argument syntax $ dune build test_ppx_args.cma - ppx test_ppx_args.ml.pp + ppx .test_ppx_args.objs/test_ppx_args.ml.pp .ppx/driver_print_args@foo/ppx.exe -arg1 -arg2 @@ -50,9 +50,9 @@ Test the argument syntax --cookie library-name="test_ppx_args" -o - test_ppx_args.ml.pp + .test_ppx_args.objs/test_ppx_args.ml.pp --impl test_ppx_args.ml Error: Rule failed to generate the following targets: - - test_ppx_args.ml.pp + - .test_ppx_args.objs/test_ppx_args.ml.pp [1] diff --git a/test/blackbox-tests/test-cases/js_of_ocaml/run.t b/test/blackbox-tests/test-cases/js_of_ocaml/run.t index cfae4289..09260e82 100644 --- a/test/blackbox-tests/test-cases/js_of_ocaml/run.t +++ b/test/blackbox-tests/test-cases/js_of_ocaml/run.t @@ -2,17 +2,17 @@ ocamlc lib/stubs$ext_obj ocamlmklib lib/dllx_stubs$ext_dll,lib/libx_stubs$ext_lib ocamlopt .ppx/js_of_ocaml-ppx/ppx.exe - ppx lib/x.ml.pp + ppx lib/.x.objs/x.ml.pp ocamldep lib/.x.objs/x.ml.pp.d ocamlc lib/.x.objs/x__.{cmi,cmo,cmt} ocamlopt lib/.x.objs/x__.{cmx,o} - ppx lib/y.ml.pp + ppx lib/.x.objs/y.ml.pp ocamldep lib/.x.objs/y.ml.pp.d ocamlc lib/.x.objs/x__Y.{cmi,cmo,cmt} ocamlopt lib/.x.objs/x__Y.{cmx,o} - ppx bin/technologic.ml.pp + ppx bin/.technologic.eobjs/technologic.ml.pp ocamldep bin/.technologic.eobjs/technologic.ml.pp.d - ppx bin/z.ml.pp + ppx bin/.technologic.eobjs/z.ml.pp ocamldep bin/.technologic.eobjs/z.ml.pp.d js_of_ocaml .js/js_of_ocaml/js_of_ocaml.cma.js js_of_ocaml lib/.x.objs/x__Y.cmo.js diff --git a/test/blackbox-tests/test-cases/ppx-rewriter/run.t b/test/blackbox-tests/test-cases/ppx-rewriter/run.t index 911b3a66..c1b34fbf 100644 --- a/test/blackbox-tests/test-cases/ppx-rewriter/run.t +++ b/test/blackbox-tests/test-cases/ppx-rewriter/run.t @@ -4,7 +4,7 @@ ocamlopt ppx/.fooppx.objs/fooppx.{cmx,o} ocamlopt ppx/fooppx.{a,cmxa} ocamlopt .ppx/jbuild/fooppx/ppx.exe - ppx w_omp_driver.ml.pp + ppx .w_omp_driver.eobjs/w_omp_driver.ml.pp ocamldep .w_omp_driver.eobjs/w_omp_driver.ml.pp.d ocamlc .w_omp_driver.eobjs/w_omp_driver.{cmi,cmo,cmt} ocamlopt .w_omp_driver.eobjs/w_omp_driver.{cmx,o} diff --git a/test/blackbox-tests/test-cases/private-public-overlap/run.t b/test/blackbox-tests/test-cases/private-public-overlap/run.t index 81516c4f..6f1f6d07 100644 --- a/test/blackbox-tests/test-cases/private-public-overlap/run.t +++ b/test/blackbox-tests/test-cases/private-public-overlap/run.t @@ -15,7 +15,7 @@ On the other hand, public libraries may have private preprocessors ocamlopt .ppx_internal.objs/ppx_internal.{cmx,o} ocamlopt ppx_internal.{a,cmxa} ocamlopt .ppx/jbuild/ppx_internal@mylib/ppx.exe - ppx mylib.ml.pp + ppx .mylib.objs/mylib.ml.pp ocamldep .mylib.objs/mylib.ml.pp.d ocamlc .mylib.objs/mylib.{cmi,cmo,cmt} ocamlopt .mylib.objs/mylib.{cmx,o} @@ -33,7 +33,7 @@ Unless they introduce private runtime dependencies: ocamlopt .private_ppx.objs/private_ppx.{cmx,o} ocamlopt private_ppx.{a,cmxa} ocamlopt .ppx/jbuild/private_ppx@mylib/ppx.exe - ppx mylib.ml.pp + ppx .mylib.objs/mylib.ml.pp ocamldep .mylib.objs/mylib.ml.pp.d [1] diff --git a/test/blackbox-tests/test-cases/scope-ppx-bug/run.t b/test/blackbox-tests/test-cases/scope-ppx-bug/run.t index 9f9c86d0..5b5b6819 100644 --- a/test/blackbox-tests/test-cases/scope-ppx-bug/run.t +++ b/test/blackbox-tests/test-cases/scope-ppx-bug/run.t @@ -11,7 +11,7 @@ ocamlc a/kernel/a_kernel.cma ocamlopt .ppx/jbuild/a.kernel/ppx.exe ocamlopt .ppx/jbuild/a/ppx.exe - ppx b/b.ml.pp + ppx b/.b.objs/b.ml.pp ocamldep b/.b.objs/b.ml.pp.d ocamlc b/.b.objs/b.{cmi,cmo,cmt} ocamlopt b/.b.objs/b.{cmx,o}