From cecedc04b132139a023572ceea364ec28a193547 Mon Sep 17 00:00:00 2001 From: Etienne Millon Date: Mon, 17 Oct 2022 10:04:41 +0200 Subject: [PATCH] Compute sign hook lazily Signed-off-by: Etienne Millon --- src/dune_rules/artifact_substitution.ml | 12 ++++++------ src/dune_rules/artifact_substitution.mli | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/dune_rules/artifact_substitution.ml b/src/dune_rules/artifact_substitution.ml index 1d92e765cdb2..f027ccbb074a 100644 --- a/src/dune_rules/artifact_substitution.ml +++ b/src/dune_rules/artifact_substitution.ml @@ -48,7 +48,7 @@ type conf = ; get_location : Section.t -> Package.Name.t -> Path.t ; get_config_path : configpath -> Path.t option ; hardcoded_ocaml_path : hardcoded_ocaml_path - ; sign_hook : (Path.t -> unit Fiber.t) option + ; sign_hook : (Path.t -> unit Fiber.t) option Lazy.t } let mac_codesign_hook ~codesign path = @@ -74,7 +74,7 @@ let conf_of_context (context : Context.t option) = ; get_location = (fun _ _ -> Code_error.raise "no context available" []) ; get_config_path = (fun _ -> Code_error.raise "no context available" []) ; hardcoded_ocaml_path = Hardcoded [] - ; sign_hook = None + ; sign_hook = lazy None } | Some context -> let get_location = Install.Section.Paths.get_local_location context.name in @@ -87,7 +87,7 @@ let conf_of_context (context : Context.t option) = let install_dir = Path.build (Path.Build.relative install_dir "lib") in Hardcoded (install_dir :: context.default_ocamlpath) in - let sign_hook = sign_hook_of_context context in + let sign_hook = lazy (sign_hook_of_context context) in { get_vcs = Source_tree.nearest_vcs ; get_location ; get_config_path @@ -111,7 +111,7 @@ let conf_for_install ~relocatable ~default_ocamlpath ~stdlib_dir ~roots ~context | Sourceroot -> None | Stdlib -> Some stdlib_dir in - let sign_hook = sign_hook_of_context context in + let sign_hook = lazy (sign_hook_of_context context) in { get_location; get_vcs; get_config_path; hardcoded_ocaml_path; sign_hook } let conf_dummy = @@ -119,7 +119,7 @@ let conf_dummy = ; get_location = (fun _ _ -> Path.root) ; get_config_path = (fun _ -> None) ; hardcoded_ocaml_path = Hardcoded [] - ; sign_hook = None + ; sign_hook = lazy None } let to_dyn = function @@ -570,7 +570,7 @@ let copy_file_non_atomic ~conf ?chmod ~src ~dst () = let run_sign_hook conf ~has_subst file = match (conf.sign_hook, has_subst) with - | Some hook, true -> hook file + | (lazy (Some hook)), true -> hook file | _ -> Fiber.return () (** This is just an optimisation: skip the renaming if the destination exists diff --git a/src/dune_rules/artifact_substitution.mli b/src/dune_rules/artifact_substitution.mli index ec11e947c5b2..5cb166d24b2d 100644 --- a/src/dune_rules/artifact_substitution.mli +++ b/src/dune_rules/artifact_substitution.mli @@ -26,7 +26,7 @@ type conf = private ; get_config_path : configpath -> Path.t option ; hardcoded_ocaml_path : hardcoded_ocaml_path (** Initial prefix of installation when relocatable chosen *) - ; sign_hook : (Path.t -> unit Fiber.t) option + ; sign_hook : (Path.t -> unit Fiber.t) option Lazy.t (** Called on binary after if has been edited *) }