From fda3c7f6809eb4dd4f27c2ca18235c15d3209480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Sun, 21 Jan 2018 22:36:30 +0100 Subject: [PATCH] Implement #427 --- src/gen_rules.ml | 37 ++++++++++-------- src/lib.ml | 14 +++++-- src/lib.mli | 4 +- src/merlin.ml | 16 ++++++-- src/merlin.mli | 1 + src/module.ml | 14 +++---- src/module.mli | 6 +-- src/module_compilation.ml | 38 ++++++++++--------- src/module_compilation.mli | 2 + src/odoc.ml | 13 ++++--- test/blackbox-tests/test-cases/c-stubs/run.t | 4 +- .../test-cases/copy_files/run.t | 4 +- .../test-cases/cross-compilation/run.t | 8 ++-- .../test-cases/gen-opam-install-file/run.t | 6 +-- .../test-cases/github25/root/run.t | 8 ++-- .../test-cases/multiple-private-libs/run.t | 4 +- test/blackbox-tests/test-cases/odoc/run.t | 4 +- .../test-cases/ppx-rewriter/run.t | 4 +- .../blackbox-tests/test-cases/scope-bug/run.t | 20 +++++----- .../test-cases/scope-ppx-bug/run.t | 12 +++--- test/blackbox-tests/test-cases/utop/run.t | 2 +- test/unit-tests/expect_test.mll | 3 +- test/unit-tests/jbuild | 12 ++---- 23 files changed, 131 insertions(+), 105 deletions(-) diff --git a/src/gen_rules.ml b/src/gen_rules.ml index c0ae9829..f6f19ce5 100644 --- a/src/gen_rules.ml +++ b/src/gen_rules.ml @@ -333,7 +333,7 @@ Add it to your jbuild file to remove this warning. in List.map cclibs ~f - let build_lib (lib : Library.t) ~scope ~flags ~dir ~mode ~top_sorted_modules = + let build_lib (lib : Library.t) ~scope ~flags ~dir ~obj_dir ~mode ~top_sorted_modules = Option.iter (Context.compiler ctx mode) ~f:(fun compiler -> let target = lib_archive lib ~dir ~ext:(Mode.compiled_lib_ext mode) in let stubs_flags = @@ -361,7 +361,7 @@ Add it to your jbuild file to remove this warning. SC.add_rule sctx (Build.fanout4 (top_sorted_modules >>^ List.map ~f:(fun m -> - Module.cm_file m ~dir (Mode.cm_kind mode))) + Module.cm_file m ~obj_dir (Mode.cm_kind mode))) (SC.expand_and_eval_set sctx ~scope ~dir lib.c_library_flags ~standard:[]) (Ocaml_flags.get flags mode) (SC.expand_and_eval_set sctx ~scope ~dir lib.library_flags ~standard:[]) @@ -401,7 +401,7 @@ Add it to your jbuild file to remove this warning. (Ok ctx.ocamlc) [ As (Utils.g ()) ; Dyn (fun (c_flags, libs) -> - S [ Lib.c_include_flags libs + S [ Lib.c_include_flags libs ~stdlib_dir:ctx.stdlib_dir ; Arg_spec.quote_args "-ccopt" c_flags ]) ; A "-o"; Target dst @@ -434,7 +434,7 @@ Add it to your jbuild file to remove this warning. ([ S [A "-I"; Path ctx.stdlib_dir] ; As (SC.cxx_flags sctx) ; Dyn (fun (cxx_flags, libs) -> - S [ Lib.c_include_flags libs + S [ Lib.c_include_flags libs ~stdlib_dir:ctx.stdlib_dir ; As cxx_flags ]) ] @ output_param @ @@ -450,6 +450,7 @@ Add it to your jbuild file to remove this warning. let library_rules (lib : Library.t) ~dir ~files ~(scope : Lib_db.Scope.t With_required_by.t) = + let obj_dir = Lib.lib_obj_dir dir lib in let dep_kind = if lib.optional then Build.Optional else Required in let flags = Ocaml_flags.make lib.buildable sctx ~scope:scope.data ~dir in let { modules; main_module_name; alias_module } = modules_by_lib ~dir lib in @@ -503,7 +504,7 @@ Add it to your jbuild file to remove this warning. let dynlink = lib.dynlink in let js_of_ocaml = lib.buildable.js_of_ocaml in Module_compilation.build_modules sctx - ~js_of_ocaml ~dynlink ~flags ~scope:scope.data ~dir ~dep_graphs + ~js_of_ocaml ~dynlink ~flags ~scope:scope.data ~dir ~obj_dir ~dep_graphs ~modules ~requires ~alias_module; Option.iter alias_module ~f:(fun m -> let flags = Ocaml_flags.default () in @@ -514,6 +515,7 @@ Add it to your jbuild file to remove this warning. ~flags:(Ocaml_flags.append_common flags ["-w"; "-49"]) ~scope:scope.data ~dir + ~obj_dir ~dep_graphs:(Ocamldep.Dep_graphs.dummy m) ~requires:( let requires = @@ -592,7 +594,7 @@ Add it to your jbuild file to remove this warning. List.iter Cm_kind.all ~f:(fun cm_kind -> let files = String_map.fold modules ~init:[] ~f:(fun ~key:_ ~data:m acc -> - Module.cm_file m ~dir cm_kind :: acc) + Module.cm_file m ~obj_dir cm_kind :: acc) in SC.Libs.setup_file_deps_alias sctx (dir, lib) ~ext:(Cm_kind.ext cm_kind) files); @@ -606,7 +608,7 @@ Add it to your jbuild file to remove this warning. Ocamldep.Dep_graph.top_closed dep_graphs.impl (String_map.values modules)) in List.iter Mode.all ~f:(fun mode -> - build_lib lib ~scope:scope.data ~flags ~dir ~mode ~top_sorted_modules); + build_lib lib ~scope:scope.data ~flags ~dir ~obj_dir ~mode ~top_sorted_modules); (* Build *.cma.js *) SC.add_rules sctx ( let src = lib_archive lib ~dir ~ext:(Mode.compiled_lib_ext Mode.Byte) in @@ -662,13 +664,14 @@ Add it to your jbuild file to remove this warning. ; preprocess = Buildable.single_preprocess lib.buildable ; libname = Some lib.name ; source_dirs = Path.Set.empty + ; objs_dirs = Path.Set.singleton obj_dir } (* +-----------------------------------------------------------------+ | Executables stuff | +-----------------------------------------------------------------+ *) - let build_exe ~js_of_ocaml ~flags ~scope ~dir ~requires ~name ~mode + let build_exe ~js_of_ocaml ~flags ~scope ~dir ~obj_dir ~requires ~name ~mode ~top_sorted_modules ~link_flags ~force_custom_bytecode = let exe_ext = Mode.exe_ext mode in let mode, link_custom, compiler = @@ -682,7 +685,7 @@ Add it to your jbuild file to remove this warning. (requires >>> Build.dyn_paths (Build.arr (Lib.archive_files ~mode ~ext_lib:ctx.ext_lib))) (top_sorted_modules >>^ List.map ~f:(fun m -> - Module.cm_file m ~dir (Mode.cm_kind mode))) + Module.cm_file m ~obj_dir (Mode.cm_kind mode))) in let objs (libs, cm) = if mode = Mode.Byte then @@ -723,6 +726,8 @@ Add it to your jbuild file to remove this warning. let executables_rules (exes : Executables.t) ~dir ~all_modules ~(scope : Lib_db.Scope.t With_required_by.t) = + let item = List.hd exes.names in + let obj_dir = dir in let dep_kind = Build.Required in let flags = Ocaml_flags.make exes.buildable sctx ~scope:scope.data ~dir in let modules = @@ -749,7 +754,6 @@ Add it to your jbuild file to remove this warning. ~lib_name:None in - let item = List.hd exes.names in let dep_graphs = Ocamldep.rules sctx ~dir ~modules ~alias_module:None ~lib_interface_module:None @@ -768,7 +772,7 @@ Add it to your jbuild file to remove this warning. (* CR-someday jdimino: this should probably say [~dynlink:false] *) Module_compilation.build_modules sctx ~js_of_ocaml:exes.buildable.js_of_ocaml - ~dynlink:true ~flags ~scope:scope.data ~dir ~dep_graphs ~modules + ~dynlink:true ~flags ~scope:scope.data ~dir ~obj_dir ~dep_graphs ~modules ~requires ~alias_module:None; List.iter programs ~f:(fun (name, unit) -> @@ -778,7 +782,7 @@ Add it to your jbuild file to remove this warning. in List.iter Mode.all ~f:(fun mode -> build_exe ~js_of_ocaml:exes.buildable.js_of_ocaml ~flags ~scope:scope.data - ~dir ~requires ~name ~mode ~top_sorted_modules + ~dir ~obj_dir ~requires ~name ~mode ~top_sorted_modules ~link_flags:exes.link_flags ~force_custom_bytecode:(mode = Native && not exes.modes.native))); { Merlin. @@ -787,6 +791,7 @@ Add it to your jbuild file to remove this warning. ; preprocess = Buildable.single_preprocess exes.buildable ; libname = None ; source_dirs = Path.Set.empty + ; objs_dirs = Path.Set.singleton obj_dir } (* +-----------------------------------------------------------------+ @@ -855,6 +860,7 @@ Add it to your jbuild file to remove this warning. ; preprocess = Jbuild.Preprocess.No_preprocessing ; libname = None ; source_dirs = Path.Set.singleton src_dir + ; objs_dirs = Path.Set.empty } | _ -> None) |> Merlin.merge_all @@ -948,6 +954,7 @@ Add it to your jbuild file to remove this warning. +-----------------------------------------------------------------+ *) let lib_install_files ~dir ~sub_dir (lib : Library.t) = + let obj_dir = Lib.lib_obj_dir dir lib in let make_entry section fn = Install.Entry.make section fn ?dst:(Option.map sub_dir ~f:(fun d -> sprintf "%s/%s" d (Path.basename fn))) @@ -959,9 +966,9 @@ Add it to your jbuild file to remove this warning. List.concat [ List.concat_map modules ~f:(fun m -> List.concat - [ [ Module.cm_file m ~dir Cmi ] - ; if_ native [ Module.cm_file m ~dir Cmx ] - ; List.filter_map Ml_kind.all ~f:(Module.cmt_file m ~dir) + [ [ Module.cm_file m ~obj_dir Cmi ] + ; if_ native [ Module.cm_file m ~obj_dir Cmx ] + ; List.filter_map Ml_kind.all ~f:(Module.cmt_file m ~obj_dir) ; [ match Module.file m ~dir Intf with | Some fn -> fn | None -> Path.relative dir m.impl.name ] diff --git a/src/lib.ml b/src/lib.ml index ffdf37ea..fe4d13de 100644 --- a/src/lib.ml +++ b/src/lib.ml @@ -19,13 +19,20 @@ end include T module Set = Set.Make(T) +let lib_obj_dir dir lib = + Path.relative dir ("." ^ lib.Jbuild.Library.name ^ ".objs") + let dir = function | Internal (dir, _) -> dir | External pkg -> pkg.dir +let obj_dir = function + | Internal (dir, lib) -> lib_obj_dir dir lib + | External pkg -> pkg.dir + let include_paths ts ~stdlib_dir = List.fold_left ts ~init:Path.Set.empty ~f:(fun acc t -> - Path.Set.add (dir t) acc) + Path.Set.add (obj_dir t) acc) |> Path.Set.remove stdlib_dir let include_flags ts ~stdlib_dir = @@ -33,10 +40,11 @@ let include_flags ts ~stdlib_dir = Arg_spec.S (List.concat_map (Path.Set.elements dirs) ~f:(fun dir -> [Arg_spec.A "-I"; Path dir])) -let c_include_flags ts = +let c_include_flags ts ~stdlib_dir = let dirs = List.fold_left ts ~init:Path.Set.empty ~f:(fun acc t -> Path.Set.add (dir t) acc) + |> Path.Set.remove stdlib_dir in Arg_spec.S (List.concat_map (Path.Set.elements dirs) ~f:(fun dir -> [Arg_spec.A "-I"; Path dir])) @@ -52,7 +60,7 @@ let describe = function let link_flags ts ~mode ~stdlib_dir = Arg_spec.S - (include_flags ts ~stdlib_dir :: + (c_include_flags ts ~stdlib_dir :: List.map ts ~f:(fun t -> match t with | External pkg -> diff --git a/src/lib.mli b/src/lib.mli index 7e527d23..b5dff615 100644 --- a/src/lib.mli +++ b/src/lib.mli @@ -10,12 +10,14 @@ type t = module Set : Set.S with type elt := t +val lib_obj_dir : Path.t -> Jbuild.Library.t -> Path.t + (*val deps : t -> string list*) val include_paths : t list -> stdlib_dir:Path.t -> Path.Set.t val include_flags : t list -> stdlib_dir:Path.t -> _ Arg_spec.t -val c_include_flags : t list -> _ Arg_spec.t +val c_include_flags : t list -> stdlib_dir:Path.t -> _ Arg_spec.t val link_flags : t list -> mode:Mode.t -> stdlib_dir:Path.t -> _ Arg_spec.t diff --git a/src/merlin.ml b/src/merlin.ml index b95ea275..0a865974 100644 --- a/src/merlin.ml +++ b/src/merlin.ml @@ -10,6 +10,7 @@ type t = ; preprocess : Jbuild.Preprocess.t ; libname : string option ; source_dirs: Path.Set.t + ; objs_dirs : Path.Set.t } let ppx_flags sctx ~dir:_ ~scope ~src_dir:_ { preprocess; libname; _ } = @@ -50,12 +51,12 @@ let dot_merlin sctx ~dir ~scope ({ requires; flags; _ } as t) = let internals, externals = List.fold_left libs ~init:([], []) ~f:(fun (internals, externals) -> function - | Lib.Internal (path, _) -> + | Lib.Internal (path, lib) -> let spath = Path.drop_optional_build_context path |> Path.reach ~from:remaindir in - let bpath = Path.reach path ~from:remaindir in + let bpath = Path.reach (Lib.lib_obj_dir path lib) ~from:remaindir in ("S " ^ spath) :: ("B " ^ bpath) :: internals, externals | Lib.External pkg -> internals, ("PKG " ^ pkg.name) :: externals @@ -67,6 +68,12 @@ let dot_merlin sctx ~dir ~scope ({ requires; flags; _ } as t) = ("S " ^ path)::acc ) in + let objs_dirs = + Path.Set.fold t.objs_dirs ~init:[] ~f:(fun path acc -> + let path = Path.reach path ~from:remaindir in + ("B " ^ path)::acc + ) + in let flags = match flags with | [] -> [] @@ -76,8 +83,8 @@ let dot_merlin sctx ~dir ~scope ({ requires; flags; _ } as t) = in let dot_merlin = List.concat - [ [ "B " ^ (Path.reach dir ~from:remaindir) ] - ; source_dirs + [ source_dirs + ; objs_dirs ; internals ; externals ; flags @@ -111,6 +118,7 @@ let merge_two a b = | Some _ as x -> x | None -> b.libname) ; source_dirs = Path.Set.union a.source_dirs b.source_dirs + ; objs_dirs = Path.Set.union a.objs_dirs b.objs_dirs } let merge_all = function diff --git a/src/merlin.mli b/src/merlin.mli index 4baa6d04..4fb828e3 100644 --- a/src/merlin.mli +++ b/src/merlin.mli @@ -6,6 +6,7 @@ type t = ; preprocess : Jbuild.Preprocess.t ; libname : string option ; source_dirs: Path.Set.t + ; objs_dirs : Path.Set.t } val merge_all : t list -> t option diff --git a/src/module.ml b/src/module.ml index ed7b8c60..d7195dd0 100644 --- a/src/module.ml +++ b/src/module.ml @@ -43,19 +43,19 @@ let file t ~dir (kind : Ml_kind.t) = let cm_source t ~dir kind = file t ~dir (Cm_kind.source kind) -let cm_file t ~dir kind = Path.relative dir (t.obj_name ^ Cm_kind.ext kind) +let cm_file t ~obj_dir kind = Path.relative obj_dir (t.obj_name ^ Cm_kind.ext kind) -let cmt_file t ~dir (kind : Ml_kind.t) = +let cmt_file t ~obj_dir (kind : Ml_kind.t) = match kind with - | Impl -> Some (Path.relative dir (t.obj_name ^ ".cmt")) - | Intf -> Option.map t.intf ~f:(fun _ -> Path.relative dir (t.obj_name ^ ".cmti")) + | Impl -> Some (Path.relative obj_dir (t.obj_name ^ ".cmt")) + | Intf -> Option.map t.intf ~f:(fun _ -> Path.relative obj_dir (t.obj_name ^ ".cmti")) let odoc_file t ~doc_dir = Path.relative doc_dir (t.obj_name ^ ".odoc") -let cmti_file t ~dir = +let cmti_file t ~obj_dir = match t.intf with - | None -> Path.relative dir (t.obj_name ^ ".cmt") - | Some _ -> Path.relative dir (t.obj_name ^ ".cmti") + | None -> Path.relative obj_dir (t.obj_name ^ ".cmt") + | Some _ -> Path.relative obj_dir (t.obj_name ^ ".cmti") let iter t ~f = f Ml_kind.Impl t.impl; diff --git a/src/module.mli b/src/module.mli index a11c5de4..0c335099 100644 --- a/src/module.mli +++ b/src/module.mli @@ -30,12 +30,12 @@ val real_unit_name : t -> string val file : t -> dir:Path.t -> Ml_kind.t -> Path.t option val cm_source : t -> dir:Path.t -> Cm_kind.t -> Path.t option -val cm_file : t -> dir:Path.t -> Cm_kind.t -> Path.t -val cmt_file : t -> dir:Path.t -> Ml_kind.t -> Path.t option +val cm_file : t -> obj_dir:Path.t -> Cm_kind.t -> Path.t +val cmt_file : t -> obj_dir:Path.t -> Ml_kind.t -> Path.t option val odoc_file : t -> doc_dir:Path.t -> Path.t (** Either the .cmti, or .cmt if the module has no interface *) -val cmti_file : t -> dir:Path.t -> Path.t +val cmti_file : t -> obj_dir:Path.t -> Path.t val iter : t -> f:(Ml_kind.t -> File.t -> unit) -> unit diff --git a/src/module_compilation.ml b/src/module_compilation.ml index 1c467fdc..16f29546 100644 --- a/src/module_compilation.ml +++ b/src/module_compilation.ml @@ -5,19 +5,19 @@ open! No_io module SC = Super_context let build_cm sctx ?sandbox ~dynlink ~flags ~cm_kind ~dep_graphs - ~requires ~dir ~alias_module (m : Module.t) = + ~requires ~dir ~obj_dir ~alias_module (m : Module.t) = let ctx = SC.context sctx in Option.iter (Mode.of_cm_kind cm_kind |> Context.compiler ctx) ~f:(fun compiler -> Option.iter (Module.cm_source ~dir m cm_kind) ~f:(fun src -> let ml_kind = Cm_kind.source cm_kind in - let dst = Module.cm_file m ~dir cm_kind in + let dst = Module.cm_file m ~obj_dir cm_kind in let extra_args, extra_deps, extra_targets = match cm_kind, m.intf with (* If there is no mli, [ocamlY -c file.ml] produces both the .cmY and .cmi. We choose to use ocamlc to produce the cmi and to produce the cmx we have to wait to avoid race conditions. *) - | Cmo, None -> [], [], [Module.cm_file m ~dir Cmi] + | Cmo, None -> [], [], [Module.cm_file m ~obj_dir Cmi] | Cmx, None -> (* Change [-intf-suffix] so that the compiler thinks the cmi exists and reads it instead of re-creating it, which @@ -25,15 +25,15 @@ let build_cm sctx ?sandbox ~dynlink ~flags ~cm_kind ~dep_graphs ([ "-intf-suffix" ; Filename.extension m.impl.name ], - [Module.cm_file m ~dir Cmi], []) + [Module.cm_file m ~obj_dir Cmi], []) | Cmi, None -> assert false | Cmi, Some _ -> [], [], [] (* We need the .cmi to build either the .cmo or .cmx *) - | (Cmo | Cmx), Some _ -> [], [Module.cm_file m ~dir Cmi], [] + | (Cmo | Cmx), Some _ -> [], [Module.cm_file m ~obj_dir Cmi], [] in let extra_targets = match cm_kind with - | Cmx -> Path.relative dir (m.obj_name ^ ctx.ext_obj) :: extra_targets + | Cmx -> Path.change_extension ~ext:ctx.ext_obj (Module.cm_file m ~obj_dir Cmx) :: extra_targets | Cmi | Cmo -> extra_targets in let dep_graph = Ml_kind.Dict.get dep_graphs ml_kind in @@ -43,14 +43,16 @@ let build_cm sctx ?sandbox ~dynlink ~flags ~cm_kind ~dep_graphs List.concat_map deps ~f:(fun m -> match cm_kind with - | Cmi | Cmo -> [Module.cm_file m ~dir Cmi] - | Cmx -> [Module.cm_file m ~dir Cmi; Module.cm_file m ~dir Cmx])) + | Cmi | Cmo -> [Module.cm_file m ~obj_dir Cmi] + | Cmx -> [ Module.cm_file m ~obj_dir Cmi + ; Module.cm_file m ~obj_dir Cmx + ])) in let extra_targets, cmt_args = match cm_kind with | Cmx -> (extra_targets, Arg_spec.S []) | Cmi | Cmo -> - let fn = Option.value_exn (Module.cmt_file m ~dir ml_kind) in + let fn = Option.value_exn (Module.cmt_file m ~obj_dir ml_kind) in (fn :: extra_targets, A "-bin-annot") in SC.add_rule sctx ?sandbox @@ -66,7 +68,7 @@ let build_cm sctx ?sandbox ~dynlink ~flags ~cm_kind ~dep_graphs ; As extra_args ; if dynlink || cm_kind <> Cmx then As [] else A "-nodynlink" ; A "-no-alias-deps" - ; A "-I"; Path dir + ; A "-I"; Path obj_dir ; (match alias_module with | None -> S [] | Some (m : Module.t) -> As ["-open"; m.name]) @@ -74,18 +76,18 @@ let build_cm sctx ?sandbox ~dynlink ~flags ~cm_kind ~dep_graphs ; A "-c"; Ml_kind.flag ml_kind; Dep src ]))) -let build_module sctx ?sandbox ~dynlink ~js_of_ocaml ~flags m ~scope ~dir ~dep_graphs - ~requires ~alias_module = +let build_module sctx ?sandbox ~dynlink ~js_of_ocaml ~flags m ~scope ~dir + ~obj_dir ~dep_graphs ~requires ~alias_module = List.iter Cm_kind.all ~f:(fun cm_kind -> let requires = Cm_kind.Dict.get requires cm_kind in - build_cm sctx ?sandbox ~dynlink ~flags ~dir ~dep_graphs m ~cm_kind + build_cm sctx ?sandbox ~dynlink ~flags ~dir ~obj_dir ~dep_graphs m ~cm_kind ~requires ~alias_module); (* Build *.cmo.js *) - let src = Module.cm_file m ~dir Cm_kind.Cmo in + let src = Module.cm_file m ~obj_dir Cm_kind.Cmo in SC.add_rules sctx (Js_of_ocaml_rules.build_cm sctx ~scope ~dir ~js_of_ocaml ~src) -let build_modules sctx ~dynlink ~js_of_ocaml ~flags ~scope ~dir ~dep_graphs - ~modules ~requires ~alias_module = +let build_modules sctx ~dynlink ~js_of_ocaml ~flags ~scope ~dir ~obj_dir + ~dep_graphs ~modules ~requires ~alias_module = let cmi_requires = Build.memoize "cmi library dependencies" (requires @@ -109,5 +111,5 @@ let build_modules sctx ~dynlink ~js_of_ocaml ~flags ~scope ~dir ~dep_graphs | None -> modules | Some (m : Module.t) -> String_map.remove m.name modules) ~f:(fun ~key:_ ~data:m -> - build_module sctx m ~dynlink ~js_of_ocaml ~flags ~scope ~dir ~dep_graphs - ~requires ~alias_module) + build_module sctx m ~dynlink ~js_of_ocaml ~flags ~scope ~dir ~obj_dir + ~dep_graphs ~requires ~alias_module) diff --git a/src/module_compilation.mli b/src/module_compilation.mli index 5759022d..929e26fb 100644 --- a/src/module_compilation.mli +++ b/src/module_compilation.mli @@ -15,6 +15,7 @@ val build_module -> Module.t -> scope:Lib_db.Scope.t -> dir:Path.t + -> obj_dir:Path.t -> dep_graphs:Ocamldep.Dep_graphs.t -> requires:(unit, Lib.t list) Build.t Cm_kind.Dict.t -> alias_module:Module.t option @@ -28,6 +29,7 @@ val build_modules -> flags:Ocaml_flags.t -> scope:Lib_db.Scope.t -> dir:Path.t + -> obj_dir:Path.t -> dep_graphs:Ocamldep.Dep_graphs.t -> modules:Module.t String_map.t -> requires:(unit, Lib.t list) Build.t diff --git a/src/odoc.ml b/src/odoc.ml index 3743eabf..01ca517b 100644 --- a/src/odoc.ml +++ b/src/odoc.ml @@ -41,9 +41,9 @@ module Module_or_mld = struct | Mld m -> Mld.odoc_file ~doc_dir m | Module m -> Module.odoc_file ~doc_dir m - let odoc_input ~dir ~doc_dir = function + let odoc_input ~obj_dir ~doc_dir = function | Mld m -> Mld.odoc_input ~doc_dir m - | Module m -> Module.cmti_file m ~dir + | Module m -> Module.cmti_file m ~obj_dir let html_dir ~doc_dir = function | Mld _ -> doc_dir @@ -70,7 +70,7 @@ let module_or_mld_deps (m : Module_or_mld.t) ~doc_dir Ocamldep.Dep_graph.deps_of dep_graphs.impl m) >>^ List.map ~f:(Module.odoc_file ~doc_dir)) -let compile sctx (m : Module_or_mld.t) ~odoc ~dir ~includes ~dep_graphs +let compile sctx (m : Module_or_mld.t) ~odoc ~dir ~obj_dir ~includes ~dep_graphs ~doc_dir ~lib_unique_name = let context = SC.context sctx in let odoc_file = Module_or_mld.odoc_file m ~doc_dir in @@ -85,7 +85,7 @@ let compile sctx (m : Module_or_mld.t) ~odoc ~dir ~includes ~dep_graphs ; Dyn (fun x -> x) ; As ["--pkg"; lib_unique_name] ; A "-o"; Target odoc_file - ; Dep (Module_or_mld.odoc_input m ~dir ~doc_dir) + ; Dep (Module_or_mld.odoc_input m ~obj_dir ~doc_dir) ]); (m, odoc_file) @@ -160,6 +160,7 @@ let toplevel_index ~doc_dir = doc_dir ++ "index.html" let setup_library_rules sctx (lib : Library.t) ~dir ~modules ~mld_files ~requires ~(dep_graphs:Ocamldep.Dep_graph.t Ml_kind.Dict.t) = let doc_dir = SC.Doc.dir sctx (dir, lib) in + let obj_dir = Lib.lib_obj_dir dir lib in let lib_unique_name = SC.unique_library_name sctx (Internal (dir, lib)) in let lib_name = Library.best_name lib in let odoc = get_odoc sctx in @@ -175,12 +176,12 @@ let setup_library_rules sctx (lib : Library.t) ~dir ~modules ~mld_files in let mld_and_odoc_files = List.map mld_files ~f:(fun m -> - compile sctx ~odoc ~dir ~includes ~dep_graphs + compile sctx ~odoc ~dir ~obj_dir ~includes ~dep_graphs ~doc_dir ~lib_unique_name (Mld m)) in let modules_and_odoc_files = List.map (String_map.values modules) ~f:(fun m -> - compile sctx ~odoc ~dir ~includes ~dep_graphs + compile sctx ~odoc ~dir ~obj_dir ~includes ~dep_graphs ~doc_dir ~lib_unique_name (Module m)) in let inputs_and_odoc_files = modules_and_odoc_files @ mld_and_odoc_files in diff --git a/test/blackbox-tests/test-cases/c-stubs/run.t b/test/blackbox-tests/test-cases/c-stubs/run.t index cc0065e5..b1b10d54 100644 --- a/test/blackbox-tests/test-cases/c-stubs/run.t +++ b/test/blackbox-tests/test-cases/c-stubs/run.t @@ -4,9 +4,9 @@ ocamldep q/q.ml.d ocamldep q/q.mli.d ocamlmklib q/dllq_stubs.so,q/libq_stubs.a - ocamlc q/q.{cmi,cmti} + ocamlc q/.q.objs/q.{cmi,cmti} ocamlc qnativerun/run.{cmi,cmo,cmt} - ocamlopt q/q.{cmx,o} + ocamlopt q/.q.objs/q.{cmx,o} ocamlopt qnativerun/run.{cmx,o} ocamlopt q/q.{a,cmxa} ocamlopt qnativerun/run.exe diff --git a/test/blackbox-tests/test-cases/copy_files/run.t b/test/blackbox-tests/test-cases/copy_files/run.t index e146ccbf..e1e07e84 100644 --- a/test/blackbox-tests/test-cases/copy_files/run.t +++ b/test/blackbox-tests/test-cases/copy_files/run.t @@ -4,10 +4,10 @@ ocamldep lexer1.ml.d ocamldep dummy.ml.d ocamlc bar.o - ocamlc dummy.{cmi,cmo,cmt} + ocamlc .foo.objs/dummy.{cmi,cmo,cmt} ocamlmklib dllfoo_stubs.so,libfoo_stubs.a ocamlc lexer1.{cmi,cmo,cmt} - ocamlopt dummy.{cmx,o} + ocamlopt .foo.objs/dummy.{cmx,o} ocamlc test.{cmi,cmo,cmt} ocamlopt lexer1.{cmx,o} ocamlopt foo.{a,cmxa} diff --git a/test/blackbox-tests/test-cases/cross-compilation/run.t b/test/blackbox-tests/test-cases/cross-compilation/run.t index 1de19e05..c875b297 100644 --- a/test/blackbox-tests/test-cases/cross-compilation/run.t +++ b/test/blackbox-tests/test-cases/cross-compilation/run.t @@ -2,16 +2,16 @@ ocamldep bin/blah.ml.d [default.foo] ocamldep lib/p.ml.d [default.foo] ocamldep bin/blah.ml.d - ocamlc lib/p.{cmi,cmo,cmt} [default.foo] + ocamlc lib/.p.objs/p.{cmi,cmo,cmt} [default.foo] ocamldep lib/p.ml.d - ocamlopt lib/p.{cmx,o} [default.foo] + ocamlopt lib/.p.objs/p.{cmx,o} [default.foo] ocamlc bin/blah.{cmi,cmo,cmt} [default.foo] ocamlc lib/p.cma [default.foo] - ocamlc lib/p.{cmi,cmo,cmt} + ocamlc lib/.p.objs/p.{cmi,cmo,cmt} ocamlopt lib/p.{a,cmxa} [default.foo] ocamlopt bin/blah.{cmx,o} [default.foo] ocamlc bin/blah.{cmi,cmo,cmt} - ocamlopt lib/p.{cmx,o} + ocamlopt lib/.p.objs/p.{cmx,o} ocamlopt lib/p.cmxs [default.foo] ocamlopt bin/blah.exe [default.foo] ocamlopt bin/blah.{cmx,o} diff --git a/test/blackbox-tests/test-cases/gen-opam-install-file/run.t b/test/blackbox-tests/test-cases/gen-opam-install-file/run.t index c1cfb86a..6afb2386 100644 --- a/test/blackbox-tests/test-cases/gen-opam-install-file/run.t +++ b/test/blackbox-tests/test-cases/gen-opam-install-file/run.t @@ -2,10 +2,10 @@ ocamldep bar.ml.d ocamldep foo_byte.ml.d ocamldep foo.ml.d - ocamlc foo_byte.{cmi,cmo,cmt} - ocamlc foo.{cmi,cmo,cmt} + ocamlc .foo_byte.objs/foo_byte.{cmi,cmo,cmt} + ocamlc .foo.objs/foo.{cmi,cmo,cmt} ocamlc foo_byte.cma - ocamlopt foo.{cmx,o} + ocamlopt .foo.objs/foo.{cmx,o} ocamlc bar.{cmi,cmo,cmt} ocamlc foo.cma ocamlopt foo.{a,cmxa} diff --git a/test/blackbox-tests/test-cases/github25/root/run.t b/test/blackbox-tests/test-cases/github25/root/run.t index b6ff191a..fb9c3087 100644 --- a/test/blackbox-tests/test-cases/github25/root/run.t +++ b/test/blackbox-tests/test-cases/github25/root/run.t @@ -7,8 +7,8 @@ problem. So jbuilder shouldn't crash because of "plop.ca-marche-pas" We need ocamlfind to run this test $ $JBUILDER build -j1 @install --display short --root . --only hello - ocamlc hello.{cmi,cmo,cmt} - ocamlopt hello.{cmx,o} + ocamlc .hello.objs/hello.{cmi,cmo,cmt} + ocamlopt .hello.objs/hello.{cmx,o} ocamlc hello.cma ocamlopt hello.{a,cmxa} ocamlopt hello.cmxs @@ -21,6 +21,6 @@ We need ocamlfind to run this test Hint: try: jbuilder external-lib-deps --missing --root . --only-packages pas-de-bol @install ocamldep a.ml.d ocamldep b.ml.d - ocamlc pas_de_bol.{cmi,cmo,cmt} - ocamlopt pas_de_bol.{cmx,o} + ocamlc .pas_de_bol.objs/pas_de_bol.{cmi,cmo,cmt} + ocamlopt .pas_de_bol.objs/pas_de_bol.{cmx,o} [1] diff --git a/test/blackbox-tests/test-cases/multiple-private-libs/run.t b/test/blackbox-tests/test-cases/multiple-private-libs/run.t index e94f982e..d63b4e07 100644 --- a/test/blackbox-tests/test-cases/multiple-private-libs/run.t +++ b/test/blackbox-tests/test-cases/multiple-private-libs/run.t @@ -6,8 +6,8 @@ This test checks that there is no clash when two private libraries have the same ocamldep a/test.ml.d odoc _doc/test@b/page-index.odoc ocamldep b/test.ml.d - ocamlc a/test.{cmi,cmo,cmt} - ocamlc b/test.{cmi,cmo,cmt} + ocamlc a/.test.objs/test.{cmi,cmo,cmt} + ocamlc b/.test.objs/test.{cmi,cmo,cmt} odoc _doc/test@a/test.odoc odoc _doc/test@b/test.odoc odoc _doc/test@a/index.html diff --git a/test/blackbox-tests/test-cases/odoc/run.t b/test/blackbox-tests/test-cases/odoc/run.t index 1d6919b9..4247759f 100644 --- a/test/blackbox-tests/test-cases/odoc/run.t +++ b/test/blackbox-tests/test-cases/odoc/run.t @@ -6,8 +6,8 @@ odoc _doc/foo/page-index.odoc odoc _doc/foo/page-test.odoc odoc _doc/odoc.css - ocamlc foo_byte.{cmi,cmo,cmt} - ocamlc foo.{cmi,cmo,cmt} + ocamlc .foo_byte.objs/foo_byte.{cmi,cmo,cmt} + ocamlc .foo.objs/foo.{cmi,cmo,cmt} odoc _doc/foo.byte/foo_byte.odoc odoc _doc/foo/foo.odoc odoc _doc/foo.byte/index.html diff --git a/test/blackbox-tests/test-cases/ppx-rewriter/run.t b/test/blackbox-tests/test-cases/ppx-rewriter/run.t index e96cf4d6..a436b903 100644 --- a/test/blackbox-tests/test-cases/ppx-rewriter/run.t +++ b/test/blackbox-tests/test-cases/ppx-rewriter/run.t @@ -1,7 +1,7 @@ $ $JBUILDER build ./w_omp_driver.exe -j1 --display short --root . ocamldep ppx/fooppx.ml.d - ocamlc ppx/fooppx.{cmi,cmo,cmt} - ocamlopt ppx/fooppx.{cmx,o} + ocamlc ppx/.fooppx.objs/fooppx.{cmi,cmo,cmt} + ocamlopt ppx/.fooppx.objs/fooppx.{cmx,o} ocamlopt ppx/fooppx.{a,cmxa} ocamlopt .ppx/fooppx@/ppx.exe ppx w_omp_driver.pp.ml diff --git a/test/blackbox-tests/test-cases/scope-bug/run.t b/test/blackbox-tests/test-cases/scope-bug/run.t index c3a1ea75..66b3b909 100644 --- a/test/blackbox-tests/test-cases/scope-bug/run.t +++ b/test/blackbox-tests/test-cases/scope-bug/run.t @@ -1,23 +1,23 @@ $ $JBUILDER build -j1 --display short --root . @install ocamldep alib/alib.ml.d ocamldep alib/main.ml.d - ocamlc alib/alib__.{cmi,cmo,cmt} + ocamlc alib/.alib.objs/alib__.{cmi,cmo,cmt} ocamldep blib/blib.ml.d ocamldep blib/sub/sub.ml.d - ocamlopt alib/alib__.{cmx,o} - ocamlc blib/sub/sub.{cmi,cmo,cmt} - ocamlopt blib/sub/sub.{cmx,o} - ocamlc blib/blib.{cmi,cmo,cmt} + ocamlopt alib/.alib.objs/alib__.{cmx,o} + ocamlc blib/sub/.sub.objs/sub.{cmi,cmo,cmt} + ocamlopt blib/sub/.sub.objs/sub.{cmx,o} + ocamlc blib/.blib.objs/blib.{cmi,cmo,cmt} ocamlc blib/sub/sub.cma ocamlopt blib/sub/sub.{a,cmxa} - ocamlopt blib/blib.{cmx,o} - ocamlc alib/alib.{cmi,cmo,cmt} - ocamlc alib/alib__Main.{cmi,cmo,cmt} + ocamlopt blib/.blib.objs/blib.{cmx,o} + ocamlc alib/.alib.objs/alib.{cmi,cmo,cmt} + ocamlc alib/.alib.objs/alib__Main.{cmi,cmo,cmt} ocamlc blib/blib.cma ocamlopt blib/sub/sub.cmxs ocamlopt blib/blib.{a,cmxa} - ocamlopt alib/alib.{cmx,o} - ocamlopt alib/alib__Main.{cmx,o} + ocamlopt alib/.alib.objs/alib.{cmx,o} + ocamlopt alib/.alib.objs/alib__Main.{cmx,o} ocamlc alib/alib.cma ocamlopt blib/blib.cmxs ocamlopt alib/alib.{a,cmxa} 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 93b4c55b..f9573571 100644 --- a/test/blackbox-tests/test-cases/scope-ppx-bug/run.t +++ b/test/blackbox-tests/test-cases/scope-ppx-bug/run.t @@ -1,9 +1,9 @@ $ $JBUILDER build -j1 --display short --root . @install - ocamlc a/ppx/a.{cmi,cmo,cmt} - ocamlc a/kernel/a_kernel.{cmi,cmo,cmt} - ocamlopt a/ppx/a.{cmx,o} + ocamlc a/ppx/.a.objs/a.{cmi,cmo,cmt} + ocamlc a/kernel/.a_kernel.objs/a_kernel.{cmi,cmo,cmt} + ocamlopt a/ppx/.a.objs/a.{cmx,o} ocamlc a/ppx/a.cma - ocamlopt a/kernel/a_kernel.{cmx,o} + ocamlopt a/kernel/.a_kernel.objs/a_kernel.{cmx,o} ocamlc a/kernel/a_kernel.cma ocamlopt a/ppx/a.{a,cmxa} ocamlopt a/kernel/a_kernel.{a,cmxa} @@ -13,8 +13,8 @@ ocamlopt .ppx/a/ppx.exe ppx b/b.pp.ml ocamldep b/b.pp.ml.d - ocamlc b/b.{cmi,cmo,cmt} - ocamlopt b/b.{cmx,o} + ocamlc b/.b.objs/b.{cmi,cmo,cmt} + ocamlopt b/.b.objs/b.{cmx,o} ocamlc b/b.cma ocamlopt b/b.{a,cmxa} ocamlopt b/b.cmxs diff --git a/test/blackbox-tests/test-cases/utop/run.t b/test/blackbox-tests/test-cases/utop/run.t index 30dd85a0..fe75da9d 100644 --- a/test/blackbox-tests/test-cases/utop/run.t +++ b/test/blackbox-tests/test-cases/utop/run.t @@ -1,7 +1,7 @@ $ $JBUILDER utop -j1 --display short --root . forutop -- init_forutop.ml ocamldep forutop/.utop/utop.ml.d ocamldep forutop/forutop.ml.d - ocamlc forutop/forutop.{cmi,cmo,cmt} + ocamlc forutop/.forutop.objs/forutop.{cmi,cmo,cmt} ocamlc forutop/.utop/utop.{cmi,cmo,cmt} ocamlc forutop/forutop.cma ocamlc forutop/.utop/utop.exe diff --git a/test/unit-tests/expect_test.mll b/test/unit-tests/expect_test.mll index d93957cb..87a280ec 100644 --- a/test/unit-tests/expect_test.mll +++ b/test/unit-tests/expect_test.mll @@ -44,8 +44,7 @@ let main () = Toploop.initialize_toplevel_env (); List.iter - [ "src" - ; "vendor/re" + [ "src/.jbuilder.objs" ] ~f:Topdirs.dir_directory; diff --git a/test/unit-tests/jbuild b/test/unit-tests/jbuild index f7a03f8f..df82d5f9 100644 --- a/test/unit-tests/jbuild +++ b/test/unit-tests/jbuild @@ -12,8 +12,7 @@ (alias ((name runtest) (deps (tests.mlt - (glob_files ${SCOPE_ROOT}/src/*.cmi) - (glob_files ${SCOPE_ROOT}/vendor/re/*.cmi) + (glob_files ${SCOPE_ROOT}/src/.jbuilder.objs/*.cmi) (files_recursively_in findlib-db))) (action (chdir ${SCOPE_ROOT} (progn @@ -23,8 +22,7 @@ (alias ((name runtest) (deps (filename.mlt - (glob_files ${SCOPE_ROOT}/src/*.cmi) - (glob_files ${SCOPE_ROOT}/vendor/re/*.cmi))) + (glob_files ${SCOPE_ROOT}/src/.jbuilder.objs/*.cmi))) (action (chdir ${SCOPE_ROOT} (progn (run ${exe:expect_test.exe} ${<}) @@ -33,8 +31,7 @@ (alias ((name runtest) (deps (import_dot_map.mlt - (glob_files ${SCOPE_ROOT}/src/*.cmi) - (glob_files ${SCOPE_ROOT}/vendor/re/*.cmi))) + (glob_files ${SCOPE_ROOT}/src/.jbuilder.objs/*.cmi))) (action (chdir ${SCOPE_ROOT} (progn (run ${exe:expect_test.exe} ${<}) @@ -43,8 +40,7 @@ (alias ((name runtest) (deps (action.mlt - (glob_files ${SCOPE_ROOT}/src/*.cmi) - (glob_files ${SCOPE_ROOT}/vendor/re/*.cmi))) + (glob_files ${SCOPE_ROOT}/src/.jbuilder.objs/*.cmi))) (action (chdir ${SCOPE_ROOT} (progn (run ${exe:expect_test.exe} ${<})