Skip to content

Commit 1101dcd

Browse files
Zhaopu Wangmeta-codesync[bot]
authored andcommitted
Fix incompatible target blocking generation
Summary: This command `fbpython arvr/tools/buck/vsgo --vs2022 --no-open --mode_files arvr/apps/hsr/mode/vsgo_dev --generated_folder=C:\\open\\generated_projects //arvr/projects/hsr/... //arvr/apps/hsr/demo/... //arvr/apps/hsr/example/... //arvr/apps/hsr/holodeck/...` is blocking hsr stable because a newly introduced incompatible target blocked the generation. Properly handle this in vsgo Reviewed By: autozimu Differential Revision: D85915868 fbshipit-source-id: f5b5bb7494348fa0bc87c6d44eddaeb387db0c04
1 parent 5a2bb42 commit 1101dcd

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

prelude/ide_integrations/visual_studio/get_deps.bxl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@
88

99
load("utils.bxl", "flatten_lists", "log_debug")
1010

11-
def get_deps(bxl_ctx, targets: list[TargetLabel]) -> typing.Iterable:
11+
def get_deps(bxl_ctx, targets: bxl.ConfiguredTargetSet) -> typing.Iterable:
1212
log_debug("# Getting dependencies for {}", targets, bxl_ctx = bxl_ctx)
1313

14-
# Pass along modifiers as required by API to get same configuration as buck2 build.
15-
# bxl_ctx.modifiers includes modifiers from both command line and mode file.
16-
configured_targets = bxl_ctx.configured_targets(targets, modifiers = bxl_ctx.modifiers)
17-
1814
# -1 or large value for unbounded traversal https://fburl.com/code/7vtwh6bu
1915
# Return dependencies in DFS post-order.
20-
deps = bxl_ctx.cquery().deps(configured_targets, -1, "target_deps()")
16+
deps = bxl_ctx.cquery().deps(targets, -1, "target_deps()")
2117

2218
# Skip special targets that are going to cause trouble in generation and not useful in final solution.
2319
block_list = {

prelude/ide_integrations/visual_studio/main.bxl

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
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")
910
load("@prelude//cxx:cxx_toolchain_types.bzl", "CxxToolchainInfo")
1011
load("gen_filters.bxl", "gen_filters")
1112
load("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

Comments
 (0)