From 4dc8d2456f123bfc571394291d93d71fc2f3a460 Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Sun, 25 Feb 2018 22:04:46 +0000 Subject: [PATCH] Pass obj_dir explicitely to Exe.build_and_link and don't return it The only place where we used the default value was gen_rules --- src/exe.ml | 18 ++++-------------- src/exe.mli | 14 +++++++------- src/gen_rules.ml | 26 +++++++++++++++----------- src/utop.ml | 22 ++++++++++------------ 4 files changed, 36 insertions(+), 44 deletions(-) diff --git a/src/exe.ml b/src/exe.ml index 3eba2146..f836797d 100644 --- a/src/exe.ml +++ b/src/exe.ml @@ -112,7 +112,7 @@ let link_exe SC.add_rules sctx (List.map rules ~f:(fun r -> libs_and_cm_and_flags >>> r)) let build_and_link_many - ?obj_dir ~dir ~programs ~modules + ~dir ~obj_dir ~programs ~modules ~scope ~linkages ?(requires=Build.return []) @@ -122,14 +122,6 @@ let build_and_link_many ?(js_of_ocaml=Jbuild.Js_of_ocaml.default) sctx = - let item = (List.hd programs).Program.name in - let obj_dir = - match obj_dir with - (* Use "eobjs" rather than "objs" to avoid a potential conflict with a - library of the same name *) - | None -> Path.relative dir ("." ^ item ^ ".eobjs") - | Some d -> d - in let modules = String_map.map modules ~f:(Module.set_obj_name ~wrapper:None) in @@ -162,9 +154,7 @@ let build_and_link_many ~top_sorted_modules ~js_of_ocaml ~flags - ?link_flags)); + ?link_flags)) - obj_dir - -let build_and_link ?obj_dir ~dir ~program = - build_and_link_many ?obj_dir ~dir ~programs:[program] +let build_and_link ~dir ~obj_dir ~program = + build_and_link_many ~dir ~obj_dir ~programs:[program] diff --git a/src/exe.mli b/src/exe.mli index 7605bb85..18a46baf 100644 --- a/src/exe.mli +++ b/src/exe.mli @@ -34,11 +34,11 @@ end (** {1 High-level functions} *) -(** Build and link one or more executables. Return the object directory. *) +(** Build and link one or more executables *) val build_and_link - : ?obj_dir:Path.t - -> dir:Path.t + : dir:Path.t + -> obj_dir:Path.t -> program:Program.t -> modules:Module.t String_map.t -> scope:Scope.t @@ -49,11 +49,11 @@ val build_and_link -> ?link_flags:(unit, string list) Build.t -> ?js_of_ocaml:Jbuild.Js_of_ocaml.t -> Super_context.t - -> Path.t + -> unit val build_and_link_many - : ?obj_dir:Path.t - -> dir:Path.t + : dir:Path.t + -> obj_dir:Path.t -> programs:Program.t list -> modules:Module.t String_map.t -> scope:Scope.t @@ -64,7 +64,7 @@ val build_and_link_many -> ?link_flags:(unit, string list) Build.t -> ?js_of_ocaml:Jbuild.Js_of_ocaml.t -> Super_context.t - -> Path.t + -> unit (** {1 Low-level functions} *) diff --git a/src/gen_rules.ml b/src/gen_rules.ml index 7f0c8d83..6e066f8c 100644 --- a/src/gen_rules.ml +++ b/src/gen_rules.ml @@ -813,19 +813,23 @@ module Gen(P : Params) = struct compile_info in + (* Use "eobjs" rather than "objs" to avoid a potential conflict + with a library of the same name *) let obj_dir = - Exe.build_and_link_many sctx - ~dir - ~programs - ~modules - ~already_used - ~scope - ~linkages - ~requires - ~flags - ~link_flags - ~js_of_ocaml:exes.buildable.js_of_ocaml + Path.relative dir ("." ^ (List.hd programs).name ^ ".eobjs") in + Exe.build_and_link_many sctx + ~dir + ~obj_dir + ~programs + ~modules + ~already_used + ~scope + ~linkages + ~requires + ~flags + ~link_flags + ~js_of_ocaml:exes.buildable.js_of_ocaml; { Merlin. requires = real_requires diff --git a/src/utop.ml b/src/utop.ml index 794e25ee..d8cca6e8 100644 --- a/src/utop.ml +++ b/src/utop.ml @@ -68,16 +68,14 @@ let setup sctx ~dir ~(libs : Library.t list) ~scope = |> Lib.Compile.make |> Super_context.Libs.requires sctx ~dir ~has_dot_merlin:false in - let (_obj_dir : Path.t) = - Exe.build_and_link sctx - ~dir:utop_exe_dir - ~obj_dir:utop_exe_dir - ~program:{ name = exe_name ; main_module_name } - ~modules - ~scope - ~linkages:[Exe.Linkage.custom] - ~requires - ~flags:(Ocaml_flags.append_common (Ocaml_flags.default ()) ["-w"; "-24"]) - ~link_flags:(Build.return ["-linkall"; "-warn-error"; "-31"]) - in + Exe.build_and_link sctx + ~dir:utop_exe_dir + ~obj_dir:utop_exe_dir + ~program:{ name = exe_name ; main_module_name } + ~modules + ~scope + ~linkages:[Exe.Linkage.custom] + ~requires + ~flags:(Ocaml_flags.append_common (Ocaml_flags.default ()) ["-w"; "-24"]) + ~link_flags:(Build.return ["-linkall"; "-warn-error"; "-31"]); add_module_rules sctx ~dir:utop_exe_dir requires