From d4f9207c7066d14add14df8de43c07490e30e02a Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Fri, 3 Jan 2025 12:59:28 -0700 Subject: [PATCH] chore(buck2): upgrade `dependent_targets` BXL script with API changes Signed-off-by: Fletcher Nichol --- bxl/dependent_targets.bxl | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/bxl/dependent_targets.bxl b/bxl/dependent_targets.bxl index 2262a86742..8fce3d75e8 100644 --- a/bxl/dependent_targets.bxl +++ b/bxl/dependent_targets.bxl @@ -3,7 +3,7 @@ # It finds and then filters targets in Buck2 and can be ran locally via: # bxl dependent_targets # e.g. bxl dependent_targets --publish_rootfs true --modified_file app/web/Dockerfile -# it will list any applicable target of variant publish-rootfs when the file app/web/Dockerfile +# it will list any applicable target of variant publish-rootfs when the file app/web/Dockerfile def _dependent_targets_impl(ctx): targets = _compute_targets(ctx) @@ -102,7 +102,7 @@ dependent_targets = bxl_main( ) # Computes affected targets given various CLI file options. -def _compute_targets(ctx: bxl.Context) -> bxl.TargetSet: +def _compute_targets(ctx: bxl.Context) -> bxl.UnconfiguredTargetSet: targets = utarget_set() # Add affected targets if global project files are provided. @@ -148,7 +148,7 @@ def _compute_targets(ctx: bxl.Context) -> bxl.TargetSet: return targets # Filters a `TargetSet` given CLI boolean filter options. -def _filter_targets(ctx: bxl.Context, targets: bxl.TargetSet) -> bxl.TargetSet: +def _filter_targets(ctx: bxl.Context, targets: bxl.UnconfiguredTargetSet) -> bxl.UnconfiguredTargetSet: filtered = utarget_set() has_filtered = False @@ -204,7 +204,7 @@ def _filter_targets(ctx: bxl.Context, targets: bxl.TargetSet) -> bxl.TargetSet: # Every relevant `:release` target should become a `:promote` target as the promotions are triggered # from merge to the main branch whereas the releases are triggered in the merge queue pipeline. In # other words, every necessary release has a 1:1 promotion that needs to happen later. -def _filtered_promote_docker_targets(ctx: bxl.Context, targets: bxl.TargetSet) -> bxl.TargetSet: +def _filtered_promote_docker_targets(ctx: bxl.Context, targets: bxl.UnconfiguredTargetSet) -> bxl.UnconfiguredTargetSet: release_targets = ctx.uquery().kind("docker_image_release", targets) promote_target_strs = map( @@ -220,7 +220,7 @@ def _filtered_promote_docker_targets(ctx: bxl.Context, targets: bxl.TargetSet) - # Every relevant `:release` target should become a `:promote` target as the promotions are triggered # from merge to the main branch whereas the releases are triggered in the merge queue pipeline. In # other words, every necessary release has a 1:1 promotion that needs to happen later. -def _filtered_promote_docker_targets(ctx: bxl.Context, targets: bxl.TargetSet) -> bxl.TargetSet: +def _filtered_promote_docker_targets(ctx: bxl.Context, targets: bxl.UnconfiguredTargetSet) -> bxl.UnconfiguredTargetSet: release_targets = ctx.uquery().kind("docker_image_release", targets) promote_target_strs = map( @@ -232,27 +232,27 @@ def _filtered_promote_docker_targets(ctx: bxl.Context, targets: bxl.TargetSet) - return promote_targets # Computes a list of targets for all targets in the project. -def _dependent_global_file_targets(ctx: bxl.Context) -> bxl.TargetSet: +def _dependent_global_file_targets(ctx: bxl.Context) -> bxl.UnconfiguredTargetSet: results = utarget_set() for universe in ctx.cli_args.rdeps_universe: - results = results + ctx.uquery().eval(universe) + results = results + ctx.uquery().eval(universe) return results # Computes a list of targets for all targets affected by given `BUCK` files. -def _dependent_buck_file_targets(ctx: bxl.Context, buck_files: list[str]) -> bxl.TargetSet: +def _dependent_buck_file_targets(ctx: bxl.Context, buck_files: list[str]) -> bxl.UnconfiguredTargetSet: buck_target_strs = _buck_files_to_targets(buck_files) return _rdeps_for_targets(ctx, buck_target_strs) -def _dependent_prelude_file_targets(ctx: bxl.Context) -> bxl.TargetSet: +def _dependent_prelude_file_targets(ctx: bxl.Context) -> bxl.UnconfiguredTargetSet: # TODO(nick,fletcher): we need to figure this out. Use "rbuildfile" maybe? print("xxx TODO prelude files: {}".format(ctx.cli_args.prelude_file)) return utarget_set() # Computes a list of target strings for all targets affected by given deleted files. -def _dependent_deleted_file_targets(ctx: bxl.Context) -> bxl.TargetSet: +def _dependent_deleted_file_targets(ctx: bxl.Context) -> bxl.UnconfiguredTargetSet: buck_files = [] for deleted_file in ctx.cli_args.deleted_file: if ctx.fs.is_file(deleted_file): @@ -264,7 +264,7 @@ def _dependent_deleted_file_targets(ctx: bxl.Context) -> bxl.TargetSet: return _dependent_buck_file_targets(ctx, buck_files) # Computes a list of targets for all targets affected by given modified files. -def _dependent_modified_file_targets(ctx: bxl.Context) -> bxl.TargetSet: +def _dependent_modified_file_targets(ctx: bxl.Context) -> bxl.UnconfiguredTargetSet: modified_files = map( _normalize_target_str, filter(lambda e: ctx.fs.is_file(e), ctx.cli_args.modified_file), @@ -280,7 +280,7 @@ def _dependent_modified_file_targets(ctx: bxl.Context) -> bxl.TargetSet: return _rdeps_for_targets(ctx, map(lambda e: "{}".format(e.label), targets)) # Computes a list of targets which are reverse dependencies of given targets within a universe. -def _rdeps_for_targets(ctx: bxl.Context, targets: list[str]) -> bxl.TargetSet: +def _rdeps_for_targets(ctx: bxl.Context, targets: list[str]) -> bxl.UnconfiguredTargetSet: raw_universe = map(_normalize_target_str, ctx.cli_args.rdeps_universe) universe = ctx.unconfigured_targets(raw_universe) raw_targets = map(_normalize_target_str, targets)