From 1cb005bb50a2585b25bf3789f0977651ed5ebe93 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 25 Feb 2018 20:42:50 +0700 Subject: [PATCH] Add a way to customize obj dir for executables Use this function to simplify the obj dir for the utop runner --- src/exe.ml | 15 ++++++++++----- src/exe.mli | 6 ++++-- src/utop.ml | 1 + test/blackbox-tests/test-cases/utop/run.t | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/exe.ml b/src/exe.ml index 2b78ac15..7079bc11 100644 --- a/src/exe.ml +++ b/src/exe.ml @@ -112,6 +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 ~loc ~dir ~programs ~modules ~scope ~linkages @@ -127,9 +128,13 @@ let build_and_link_many sctx = let item = (List.hd programs).Program.name in - (* Use "eobjs" rather than "objs" to avoid a potential conflict with a library of the - same name *) - let obj_dir = Path.relative dir ("." ^ item ^ ".eobjs") 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 dep_kind = Build.Required in let modules = String_map.map modules ~f:(Module.set_obj_name ~wrapper:None) @@ -193,5 +198,5 @@ let build_and_link_many (obj_dir, real_requires) -let build_and_link ~loc ~dir ~program = - build_and_link_many ~loc ~dir ~programs:[program] +let build_and_link ?obj_dir ~loc ~dir ~program = + build_and_link_many ?obj_dir ~loc ~dir ~programs:[program] diff --git a/src/exe.mli b/src/exe.mli index b86082c3..78c3178d 100644 --- a/src/exe.mli +++ b/src/exe.mli @@ -38,7 +38,8 @@ end directory and the resolved list of library dependencies. *) val build_and_link - : loc:Loc.t + : ?obj_dir:Path.t + -> loc:Loc.t -> dir:Path.t -> program:Program.t -> modules:Module.t String_map.t @@ -57,7 +58,8 @@ val build_and_link -> Path.t * (unit, Lib.t list) Build.t val build_and_link_many - : loc:Loc.t + : ?obj_dir:Path.t + -> loc:Loc.t -> dir:Path.t -> programs:Program.t list -> modules:Module.t String_map.t diff --git a/src/utop.ml b/src/utop.ml index 58aaddb6..d4488681 100644 --- a/src/utop.ml +++ b/src/utop.ml @@ -66,6 +66,7 @@ let setup sctx ~dir ~(libs : Library.t list) ~scope = let _obj_dir, libs = Exe.build_and_link sctx ~loc + ~obj_dir:utop_exe_dir ~dir:utop_exe_dir ~program:{ name = exe_name ; main_module_name } ~modules diff --git a/test/blackbox-tests/test-cases/utop/run.t b/test/blackbox-tests/test-cases/utop/run.t index 28535726..fe75da9d 100644 --- a/test/blackbox-tests/test-cases/utop/run.t +++ b/test/blackbox-tests/test-cases/utop/run.t @@ -2,7 +2,7 @@ ocamldep forutop/.utop/utop.ml.d ocamldep forutop/forutop.ml.d ocamlc forutop/.forutop.objs/forutop.{cmi,cmo,cmt} - ocamlc forutop/.utop/.utop.eobjs/utop.{cmi,cmo,cmt} + ocamlc forutop/.utop/utop.{cmi,cmo,cmt} ocamlc forutop/forutop.cma ocamlc forutop/.utop/utop.exe hello in utop