TargetSet
A set-like object for managing buck2 target nodes.
It can be obtained from several functions in bxl.Context and
bxl.UqueryContext/bxl.CqueryContext/bxl.AqueryContext,
among other places.
The node kind is part of the type, written bxl.TargetSet[<node type>]:
bxl.TargetSet[bxl.ConfiguredTargetNode], also available asbxl.ConfiguredTargetSet, containsConfiguredTargetNodesbxl.TargetSet[bxl.UnconfiguredTargetNode], also available asbxl.UnconfiguredTargetSet, containsUnconfiguredTargetNodesbxl.TargetSet[bxl.ActionQueryNode]containsActionQueryNodes
bxl.TargetSet on its own matches a target set of any kind. type() returns "target_set" for all of them.
It provides common set operations for target nodes. It supports iteration, indexing, addition (union), subtraction (difference), equality comparison, and intersection operations.
Operations:
+: Union of two TargetSets-: Difference between two TargetSets==: Equality comparison&: Intersection of two TargetSets[]: Index accesslen(): Number of targets in setiter(): Iteration over targets- constructor:
bxl.ctarget_set()forConfiguredTargetSetandbxl.utarget_set()forUnconfiguredTargetSet
Example:
# Combine sets
all_targets = targets1 + targets2 # Union
# Remove targets
remaining = targets1 - targets2 # Difference
# Check if sets are equal
if targets1 == targets2:
print("Sets contain same targets")
# Iterate through targets
for target in targets1:
print(target)
# Get target by index
first_target = targets1[0]
# Get number of targets
count = len(targets1)
# Intersection of sets
common = targets1 & targets2