From 9180f88dc394f55d9c59071db1e3560dff4bf6ea Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Sat, 26 Aug 2017 14:00:58 +0100 Subject: [PATCH 1/5] Add Path.change_extension Signed-off-by: David Allsopp --- src/path.ml | 4 ++++ src/path.mli | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/path.ml b/src/path.ml index 5e6631006bd..a260a4cd075 100644 --- a/src/path.ml +++ b/src/path.ml @@ -411,3 +411,7 @@ let rm_rf = match Unix.lstat fn with | exception Unix.Unix_error(ENOENT, _, _) -> () | _ -> loop fn + +let change_extension ~ext t = + let t = try Filename.chop_extension t with Not_found -> t in + t ^ ext diff --git a/src/path.mli b/src/path.mli index e2a45fedb72..57bed82de1c 100644 --- a/src/path.mli +++ b/src/path.mli @@ -101,3 +101,6 @@ val rmdir : t -> unit val unlink : t -> unit val unlink_no_err : t -> unit val rm_rf : t -> unit + +(** Changes the extension of the filename (or adds an extension if there was none) *) +val change_extension : ext:string -> t -> t From 77c79ebff8aa0fe0ebadaf390814776db198e6c9 Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Sat, 26 Aug 2017 14:01:20 +0100 Subject: [PATCH 2/5] Ensure executables depend on object files Previously, in Mode.Native, executables depended on .cmx files only. This was fine when changes were detected by timestamp, but it is possible to semantically alter an .ml such that only the .o/.obj file alters. In this situation, Jbuilder would rebuild the .cmx file, but not relink the executable. Fixes #237. Signed-off-by: David Allsopp --- src/gen_rules.ml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gen_rules.ml b/src/gen_rules.ml index 699013ce8ea..df27dcad1da 100644 --- a/src/gen_rules.ml +++ b/src/gen_rules.ml @@ -440,8 +440,14 @@ module Gen(P : Params) = struct ~mode [String.capitalize_ascii name])) in + let objs (_, cm) = + if mode = Mode.Byte then + [] + else + List.map ~f:(Path.change_extension ~ext:ctx.ext_obj) cm + in SC.add_rule sctx - (libs_and_cm + ((libs_and_cm >>> Build.dyn_paths (Build.arr objs)) &&& Build.fanout (Ocaml_flags.get flags mode) From 1053d4e65aaf8fcd410ec26bc5eab7bad84e0a74 Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Sat, 26 Aug 2017 15:05:54 +0100 Subject: [PATCH 3/5] Ensure .cmxa files depend on object files Signed-off-by: David Allsopp --- src/gen_rules.ml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/gen_rules.ml b/src/gen_rules.ml index df27dcad1da..81298a71b40 100644 --- a/src/gen_rules.ml +++ b/src/gen_rules.ml @@ -86,6 +86,12 @@ module Gen(P : Params) = struct else fun x -> x in + let objs (cm, _, _, _) = + if mode = Mode.Byte then + [] + else + List.map ~f:(Path.change_extension ~ext:ctx.ext_obj) cm + in SC.add_rule sctx (Build.fanout4 (dep_graph >>> @@ -100,6 +106,8 @@ module Gen(P : Params) = struct (Ocaml_flags.get flags mode) (SC.expand_and_eval_set sctx ~scope ~dir lib.library_flags ~standard:[]) >>> + Build.dyn_paths (Build.arr objs) + >>> Build.run ~context:ctx (Dep compiler) ~extra_targets:( match mode with From da240468d0d1cd5de5742f612656ea3dc90a6033 Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Sat, 26 Aug 2017 15:06:32 +0100 Subject: [PATCH 4/5] Ensure .cmxs depends on archive file Signed-off-by: David Allsopp --- src/gen_rules.ml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gen_rules.ml b/src/gen_rules.ml index 81298a71b40..87d3d7e5078 100644 --- a/src/gen_rules.ml +++ b/src/gen_rules.ml @@ -384,6 +384,8 @@ module Gen(P : Params) = struct let src = lib_archive lib ~dir ~ext:(Mode.compiled_lib_ext Native) in let dst = lib_archive lib ~dir ~ext:".cmxs" in let build = + Build.dyn_paths (Build.arr (fun () -> [lib_archive lib ~dir ~ext:ctx.ext_lib])) + >>> Ocaml_flags.get flags Native >>> Build.run ~context:ctx From 6a3c51c35899fe346804d34497dee594690c0ef6 Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Sat, 26 Aug 2017 15:18:53 +0100 Subject: [PATCH 5/5] Ensure executables also depend on archive files Signed-off-by: David Allsopp --- src/gen_rules.ml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gen_rules.ml b/src/gen_rules.ml index 87d3d7e5078..80ac91c57af 100644 --- a/src/gen_rules.ml +++ b/src/gen_rules.ml @@ -450,11 +450,18 @@ module Gen(P : Params) = struct ~mode [String.capitalize_ascii name])) in - let objs (_, cm) = + let objs (libs, cm) = if mode = Mode.Byte then [] else - List.map ~f:(Path.change_extension ~ext:ctx.ext_obj) cm + let libs = + let f = function + | Lib.Internal (dir, lib) -> Some (Path.relative dir (lib.name ^ ctx.ext_lib)) + | External _ -> None + in + List.filter_map ~f libs + in + libs @ List.map ~f:(Path.change_extension ~ext:ctx.ext_obj) cm in SC.add_rule sctx ((libs_and_cm >>> Build.dyn_paths (Build.arr objs))