private LicensesProvider initializeLicensesProvider() { if (!ruleContext.getConfiguration().checkLicenses()) { return LicensesProviderImpl.EMPTY; } NestedSetBuilder<TargetLicense> builder = NestedSetBuilder.linkOrder(); BuildConfiguration configuration = ruleContext.getConfiguration(); Rule rule = ruleContext.getRule(); License toolOutputLicense = rule.getToolOutputLicense(ruleContext.attributes()); if (configuration.isHostConfiguration() && toolOutputLicense != null) { if (toolOutputLicense != License.NO_LICENSE) { builder.add(new TargetLicense(rule.getLabel(), toolOutputLicense)); } } else { if (rule.getLicense() != License.NO_LICENSE) { builder.add(new TargetLicense(rule.getLabel(), rule.getLicense())); } for (TransitiveInfoCollection dep : ruleContext.getConfiguredTargetMap().values()) { LicensesProvider provider = dep.getProvider(LicensesProvider.class); if (provider != null) { builder.addTransitive(provider.getTransitiveLicenses()); } } } return new LicensesProviderImpl(builder.build()); }
/** * Returns ids for dependent nodes of a given node, sorted by attribute. Note that some * dependencies do not have a corresponding attribute here, and we use the null attribute to * represent those edges. Visibility attributes are only visited if {@code visitVisibility} is * {@code true}. * * <p>If {@code aspect} is null, returns the dependent nodes of the configured target node * representing the given target and configuration, otherwise that of the aspect node accompanying * the aforementioned configured target node for the specified aspect. * * <p>The values are not simply labels because this also implements the first step of applying * configuration transitions, namely, split transitions. This needs to be done before the labels * are resolved because late bound attributes depend on the configuration. A good example for this * is @{code :cc_toolchain}. * * <p>The long-term goal is that most configuration transitions be applied here. However, in order * to do that, we first have to eliminate transitions that depend on the rule class of the * dependency. */ public final ListMultimap<Attribute, Dependency> dependentNodeMap( TargetAndConfiguration node, BuildConfiguration hostConfig, AspectDefinition aspect, AspectParameters aspectParameters, Set<ConfigMatchingProvider> configConditions) throws EvalException, InterruptedException { Target target = node.getTarget(); BuildConfiguration config = node.getConfiguration(); ListMultimap<Attribute, Dependency> outgoingEdges = ArrayListMultimap.create(); if (target instanceof OutputFile) { Preconditions.checkNotNull(config); visitTargetVisibility(node, outgoingEdges.get(null)); Rule rule = ((OutputFile) target).getGeneratingRule(); outgoingEdges.put(null, new Dependency(rule.getLabel(), config)); } else if (target instanceof InputFile) { visitTargetVisibility(node, outgoingEdges.get(null)); } else if (target instanceof EnvironmentGroup) { visitTargetVisibility(node, outgoingEdges.get(null)); } else if (target instanceof Rule) { Preconditions.checkNotNull(config); visitTargetVisibility(node, outgoingEdges.get(null)); Rule rule = (Rule) target; ListMultimap<Attribute, LabelAndConfiguration> labelMap = resolveAttributes(rule, aspect, config, hostConfig, configConditions); visitRule(rule, aspect, aspectParameters, labelMap, outgoingEdges); } else if (target instanceof PackageGroup) { visitPackageGroup(node, (PackageGroup) target, outgoingEdges.get(null)); } else { throw new IllegalStateException(target.getLabel().toString()); } return outgoingEdges; }
@Override public void setUp() throws Exception { super.setUp(); rule = createRule( "x", "myrule", "cc_binary(name = 'myrule',", " srcs = ['a', 'b', 'c'])"); RuleClass ruleClass = rule.getRuleClassObject(); mapper = new TestMapper(pkg, ruleClass, rule.getLabel(), rule.getAttributeContainer()); }
public void testRuleProperties() throws Exception { assertEquals(rule.getName(), mapper.getName()); assertEquals(rule.getLabel(), mapper.getLabel()); }