diff --git a/source/buck/buck.mli b/source/buck/buck.mli index 9844fb9f4a5..4645ea002e6 100644 --- a/source/buck/buck.mli +++ b/source/buck/buck.mli @@ -544,7 +544,7 @@ module Builder : sig (** {1 Build} *) - (** The return type for incremental builds. It contains a build map, a list of buck targets that + (** The result type for incremental builds. It contains a build map, a list of buck targets that are successfully included in the build, and a list of artifact files whose contents may be altered by the build . *) module IncrementalBuildResult : sig @@ -555,6 +555,14 @@ module Builder : sig } end + (** A type representing the result of builds, along with some metadata about the build + (Buck2-only). *) + type build_result_t = (Interface.BuildResult.t, string) Interface.WithMetadata.t + + (** A type representing the result of incremental builds, along with some metadata about the + build (Buck2-only). *) + type incremental_build_result_t = (IncrementalBuildResult.t, string) Interface.WithMetadata.t + (** Given a list of buck target specificaitons to build, construct a build map for the targets and create a Python link tree at the given artifact root according to the build map. Return the constructed build map along with a list of targets that are covered by the build map. @@ -578,7 +586,7 @@ module Builder : sig Note this API does not ensure the artifact root to be empty before the build starts. If cleaness of the artifact directory is desirable, it is expected that the caller would take care of that before its invocation. *) - val build : targets:string list -> t -> Interface.BuildResult.t Lwt.t + val build : targets:string list -> t -> build_result_t Lwt.t (** Given a build map, create the corresponding Python link tree at the given artifact root accordingly. @@ -615,7 +623,7 @@ module Builder : sig : old_build_map:BuildMap.t -> targets:string list -> t -> - IncrementalBuildResult.t Lwt.t + incremental_build_result_t Lwt.t (** Given a list of normalized targets to build, fully construct a new build map for the targets and incrementally update the Python link tree at the given artifact root according to how @@ -633,7 +641,7 @@ module Builder : sig : old_build_map:BuildMap.t -> targets:Target.t list -> t -> - IncrementalBuildResult.t Lwt.t + incremental_build_result_t Lwt.t (** Given a list of normalized targets and changed/removed files, incrementally construct a new build map for the targets and incrementally update the Python link tree at the given @@ -653,7 +661,7 @@ module Builder : sig changed_paths:PyrePath.t list -> removed_paths:PyrePath.t list -> t -> - IncrementalBuildResult.t Lwt.t + incremental_build_result_t Lwt.t (** {1 Lookup} *) diff --git a/source/buck/builder.ml b/source/buck/builder.ml index 1c921655cfa..3a7230cd09a 100644 --- a/source/buck/builder.ml +++ b/source/buck/builder.ml @@ -75,6 +75,10 @@ module Classic = struct } end + type build_result_t = (Interface.BuildResult.t, string) Interface.WithMetadata.t + + type incremental_build_result_t = (IncrementalBuildResult.t, string) Interface.WithMetadata.t + let restore ~source_root ~artifact_root build_map = let open Lwt.Infix in Artifacts.populate ~source_root ~artifact_root build_map @@ -92,19 +96,19 @@ module Classic = struct type t = { - build: string list -> Interface.BuildResult.t Lwt.t; + build: string list -> build_result_t Lwt.t; restore: BuildMap.t -> unit Lwt.t; full_incremental_build: - old_build_map:BuildMap.t -> string list -> IncrementalBuildResult.t Lwt.t; + old_build_map:BuildMap.t -> string list -> incremental_build_result_t Lwt.t; incremental_build_with_normalized_targets: - old_build_map:BuildMap.t -> BuckTarget.t list -> IncrementalBuildResult.t Lwt.t; + old_build_map:BuildMap.t -> BuckTarget.t list -> incremental_build_result_t Lwt.t; fast_incremental_build_with_normalized_targets: old_build_map:BuildMap.t -> old_build_map_index:BuildMap.Indexed.t -> changed_paths:PyrePath.t list -> removed_paths:PyrePath.t list -> BuckTarget.t list -> - IncrementalBuildResult.t Lwt.t; + incremental_build_result_t Lwt.t; lookup_source: index:BuildMap.Indexed.t -> PyrePath.t -> PyrePath.t option; lookup_artifact: index:BuildMap.Indexed.t -> PyrePath.t -> PyrePath.t list; identifier: string; @@ -121,7 +125,7 @@ module Classic = struct Artifacts.populate ~source_root ~artifact_root build_map >>= function | Result.Error message -> raise (LinkTreeConstructionError message) - | Result.Ok () -> Lwt.return build_result + | Result.Ok () -> Lwt.return (Interface.WithMetadata.create build_result) let full_incremental_build ~interface ~source_root ~artifact_root ~old_build_map targets = @@ -132,7 +136,9 @@ module Classic = struct >>= fun { Interface.BuildResult.targets; build_map } -> do_incremental_build ~source_root ~artifact_root ~old_build_map ~new_build_map:build_map () >>= fun changed_artifacts -> - Lwt.return { IncrementalBuildResult.targets; build_map; changed_artifacts } + Lwt.return + (Interface.WithMetadata.create + { IncrementalBuildResult.targets; build_map; changed_artifacts }) let incremental_build_with_normalized_targets @@ -147,7 +153,9 @@ module Classic = struct >>= fun { Interface.BuildResult.targets; build_map } -> do_incremental_build ~source_root ~artifact_root ~old_build_map ~new_build_map:build_map () >>= fun changed_artifacts -> - Lwt.return { IncrementalBuildResult.targets; build_map; changed_artifacts } + Lwt.return + (Interface.WithMetadata.create + { IncrementalBuildResult.targets; build_map; changed_artifacts }) let compute_difference_from_removed_relative_paths ~build_map_index removed_paths = @@ -264,28 +272,34 @@ module Classic = struct let open Lwt.Infix in update_artifacts ~source_root ~artifact_root difference >>= fun changed_artifacts -> - Lwt.return { IncrementalBuildResult.targets; build_map; changed_artifacts } + Lwt.return + (Interface.WithMetadata.create + { IncrementalBuildResult.targets; build_map; changed_artifacts }) end module V2 = struct let build ~interface ~source_root ~artifact_root targets = let open Lwt.Infix in Interface.V2.construct_build_map interface targets - >>= fun { Interface.WithMetadata.data = build_map; metadata = _ } -> + >>= fun { Interface.WithMetadata.data = build_map; metadata } -> Log.info "Constructing Python link-tree for type checking..."; Artifacts.populate ~source_root ~artifact_root build_map >>= function | Result.Error message -> raise (LinkTreeConstructionError message) - | Result.Ok () -> Lwt.return { Interface.BuildResult.targets; build_map } + | Result.Ok () -> + Lwt.return Interface.(WithMetadata.create { BuildResult.targets; build_map } ?metadata) let full_incremental_build ~interface ~source_root ~artifact_root ~old_build_map targets = let open Lwt.Infix in Interface.V2.construct_build_map interface targets - >>= fun { Interface.WithMetadata.data = build_map; metadata = _ } -> + >>= fun { Interface.WithMetadata.data = build_map; metadata } -> do_incremental_build ~source_root ~artifact_root ~old_build_map ~new_build_map:build_map () >>= fun changed_artifacts -> - Lwt.return { IncrementalBuildResult.targets; build_map; changed_artifacts } + Lwt.return + (Interface.WithMetadata.create + { IncrementalBuildResult.targets; build_map; changed_artifacts } + ?metadata) end let create ~source_root ~artifact_root interface = diff --git a/source/server/buildSystem.ml b/source/server/buildSystem.ml index af526c1cf9a..4979b35339c 100644 --- a/source/server/buildSystem.ml +++ b/source/server/buildSystem.ml @@ -45,6 +45,7 @@ let create_for_testing module ClassicBuckBuilder = Buck.Builder.Classic +module WithMetadata = Buck.Interface.WithMetadata module BuckBuildSystem = struct module State = struct @@ -77,7 +78,11 @@ module BuckBuildSystem = struct let create_from_scratch ~builder ~targets () = let open Lwt.Infix in ClassicBuckBuilder.build builder ~targets - >>= fun { Buck.Interface.BuildResult.targets = normalized_targets; build_map } -> + >>= fun Buck.Interface. + { + WithMetadata.data = { BuildResult.targets = normalized_targets; build_map }; + metadata = _; + } -> Lwt.return (create ~targets ~builder ~normalized_targets ~build_map ()) @@ -176,9 +181,13 @@ module BuckBuildSystem = struct let rebuild_and_update_state rebuild () = rebuild state.builder >>= fun { - ClassicBuckBuilder.IncrementalBuildResult.targets = normalized_targets; - build_map; - changed_artifacts; + WithMetadata.data = + { + ClassicBuckBuilder.IncrementalBuildResult.targets = normalized_targets; + build_map; + changed_artifacts; + }; + metadata = _; } -> State.update ~normalized_targets ~build_map state; Lwt.return changed_artifacts