66# of this source tree. You may select, at your option, one of the
77# above-listed licenses.
88
9+ load("@prelude//bxl:lazy.bxl", "batch_apply_lazy_catch_each")
910load("@prelude//cxx:cxx_toolchain_types.bzl", "CxxToolchainInfo")
1011load("gen_filters.bxl", "gen_filters")
1112load("gen_sln.bxl", "gen_sln")
@@ -68,7 +69,7 @@ def _main(bxl_ctx):
6869 https://buck2.build/docs/developers/dynamic_output/#dynamic-output
6970 """
7071 actions = bxl_ctx.bxl_actions().actions
71- targets = [] # list[TargetLabel ]. Target list from command line after target pattern expansion.
72+ targets = [] # list[ConfiguredTargetNode ]. Configured target list from command line after target pattern expansion.
7273 explicit_targets = {} # dict[TargetLabel, True]. Explicit target list from command line, i.e., not from target pattern expansion.
7374 for ulabel in bxl_ctx.cli_args.target:
7475 # Add explicit cell name when it's omitted as otherwise BXL will use cell name of BXL script, i.e., prelude.
@@ -78,23 +79,40 @@ def _main(bxl_ctx):
7879 elif ulabel.startswith("//"):
7980 ulabel = "fbsource" + ulabel
8081
82+ is_explicit_target = ":" in ulabel
83+
84+ # Using bxl_ctx.configured_targets on a wildcard target label will cause all targets to fail
85+ # if one of the targets is incompatible. We are using unconfigured_target_nodes_keep_going
86+ # to filter out the incompatible targets first.
87+ success_targets, error_map = bxl_ctx.lazy.unconfigured_target_nodes_keep_going(ulabel).resolve()
88+
89+ # Handle errors
90+ for package_path, _ in error_map.items():
91+ log_debug("Failed to configure target {}, skipping", package_path, bxl_ctx = bxl_ctx)
92+
8193 # Pass along modifiers as required by API to get same configuration as buck2 build.
8294 # bxl_ctx.modifiers includes modifiers from both command line and mode file.
83- ctargets = bxl_ctx.configured_targets(ulabel, modifiers = bxl_ctx.modifiers)
84- if ctargets == None:
85- pass
86- elif isinstance(ctargets, bxl.ConfiguredTargetSet):
87- targets += [node.label.raw_target() for node in ctargets]
88- else:
89- targets.append(ctargets.label.raw_target())
90- if ":" in ulabel:
91- explicit_targets[ctargets.label.raw_target()] = True
92-
95+ def configured_target_with_modifiers(target: bxl.UnconfiguredTargetNode) -> bxl.Lazy:
96+ return bxl_ctx.lazy.configured_target_node(target, modifiers = bxl_ctx.modifiers)
97+
98+ utargets = list(success_targets)
99+
100+ results = batch_apply_lazy_catch_each(bxl_ctx, configured_target_with_modifiers, utargets)
101+ for unode, res in zip(utargets, results):
102+ if res.is_ok():
103+ cnode = res.unwrap()
104+ targets.append(cnode)
105+ if is_explicit_target:
106+ explicit_targets[cnode.label.raw_target()] = True
107+ else:
108+ log_debug("Failed to configure target {}, skipping", unode, bxl_ctx = bxl_ctx)
109+
110+ target_set = bxl.ctarget_set(targets)
93111 missing_mode_hashes = [m for m in bxl_ctx.cli_args.mode_files if m not in (bxl_ctx.cli_args.mode_hashes or {})]
94112 if len(bxl_ctx.cli_args.mode_files) > 1 and missing_mode_hashes:
95113 warning("Missing mode hashes for following mode files: " + str(missing_mode_hashes))
96114
97- deps = get_deps(bxl_ctx, targets ) # list[bxl.ConfiguredTargetNode]
115+ deps = get_deps(bxl_ctx, target_set ) # list[bxl.ConfiguredTargetNode]
98116 # print(deps)
99117
100118 target_exclude_patterns = [_normalize_include_exclude_pattern(p) for p in bxl_ctx.cli_args.target_exclude_pattern]
0 commit comments