Skip to content

Commit

Permalink
chore(buck2): upgrade dependent_targets BXL script with API changes
Browse files Browse the repository at this point in the history
Signed-off-by: Fletcher Nichol <[email protected]>
  • Loading branch information
fnichol committed Jan 3, 2025
1 parent 9aceed9 commit d4f9207
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions bxl/dependent_targets.bxl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# It finds and then filters targets in Buck2 and can be ran locally via:
# bxl dependent_targets <flags>
# 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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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):
Expand All @@ -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),
Expand All @@ -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)
Expand Down

0 comments on commit d4f9207

Please sign in to comment.