use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.
the class DependencyResolver method resolveRuleLabels.
/**
* Converts the given multimap of attributes to labels into a multi map of attributes to {@link
* Dependency} objects using the proper configuration transition for each attribute.
*
* @throws IllegalArgumentException if the {@code node} does not refer to a {@link Rule} instance
*/
public final Collection<Dependency> resolveRuleLabels(TargetAndConfiguration node, OrderedSetMultimap<Attribute, Label> depLabels, NestedSetBuilder<Label> rootCauses) throws InterruptedException, InconsistentAspectOrderException {
Preconditions.checkArgument(node.getTarget() instanceof Rule);
Rule rule = (Rule) node.getTarget();
OrderedSetMultimap<Attribute, Dependency> outgoingEdges = OrderedSetMultimap.create();
RuleResolver depResolver = new RuleResolver(rule, node.getConfiguration(), ImmutableList.<Aspect>of(), /*attributeMap=*/
null, rootCauses, outgoingEdges);
Map<Attribute, Collection<Label>> m = depLabels.asMap();
for (Map.Entry<Attribute, Collection<Label>> entry : depLabels.asMap().entrySet()) {
for (Label depLabel : entry.getValue()) {
depResolver.resolveDep(new AttributeAndOwner(entry.getKey()), depLabel);
}
}
return outgoingEdges.values();
}
use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.
the class DependencyResolver method requiredAspects.
private AspectCollection requiredAspects(Iterable<Aspect> aspectPath, AttributeAndOwner attributeAndOwner, final Target target, Rule originalRule) throws InconsistentAspectOrderException {
if (!(target instanceof Rule)) {
return AspectCollection.EMPTY;
}
if (attributeAndOwner.ownerAspect != null) {
// Do not propagate aspects along aspect attributes.
return AspectCollection.EMPTY;
}
ImmutableList.Builder<Aspect> filteredAspectPath = ImmutableList.builder();
ImmutableSet.Builder<AspectDescriptor> visibleAspects = ImmutableSet.builder();
Attribute attribute = attributeAndOwner.attribute;
collectOriginatingAspects(originalRule, attribute, (Rule) target, filteredAspectPath, visibleAspects);
collectPropagatingAspects(aspectPath, attribute, (Rule) target, filteredAspectPath, visibleAspects);
try {
return AspectCollection.create(filteredAspectPath.build(), visibleAspects.build());
} catch (AspectCycleOnPathException e) {
throw new InconsistentAspectOrderException(originalRule, attribute, target, e);
}
}
use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.
the class DependencyResolver method addExplicitDeps.
/**
* Adds new dependencies to the given rule under the given attribute name
*
* @param depResolver the resolver for this rule's deps
* @param attrName the name of the attribute to add dependency labels to
* @param labels the dependencies to add
*/
private void addExplicitDeps(RuleResolver depResolver, String attrName, Iterable<Label> labels) throws InterruptedException, InconsistentAspectOrderException {
Rule rule = depResolver.rule;
if (!rule.isAttrDefined(attrName, BuildType.LABEL_LIST) && !rule.isAttrDefined(attrName, BuildType.NODEP_LABEL_LIST)) {
return;
}
Attribute attribute = rule.getRuleClassObject().getAttributeByName(attrName);
for (Label label : labels) {
depResolver.resolveDep(new AttributeAndOwner(attribute), label);
}
}
use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.
the class MavenJarFunctionTest method testNoSha1.
@Test
public void testNoSha1() throws Exception {
Rule rule = scratchRule("external", "foo", "maven_jar(", " name = 'foo',", " artifact = 'x:y:z:1.1',", ")");
MavenDownloader downloader = new MavenDownloader(Mockito.mock(RepositoryCache.class));
try {
downloader.download("foo", WorkspaceAttributeMapper.of(rule), scratch.dir("/whatever"), TEST_SERVER);
fail("Expected failure to fetch artifact because of nonexistent server and not due to " + "lack of SHA.");
} catch (IOException expected) {
assertThat(expected.getMessage()).contains("Failed to fetch Maven dependency:");
}
}
use of com.google.devtools.build.lib.packages.Rule in project bazel by bazelbuild.
the class MavenJarFunctionTest method testInvalidSha1.
@Test
public void testInvalidSha1() throws Exception {
Rule rule = scratchRule("external", "foo", "maven_jar(", " name = 'foo',", " artifact = 'x:y:z:1.1',", " sha1 = '12345',", ")");
MavenDownloader downloader = new MavenDownloader(Mockito.mock(RepositoryCache.class));
try {
downloader.download("foo", WorkspaceAttributeMapper.of(rule), scratch.dir("/whatever"), TEST_SERVER);
fail("Invalid sha1 should have thrown.");
} catch (IOException expected) {
assertThat(expected.getMessage()).contains("Invalid SHA-1 for maven_jar foo");
}
}
Aggregations