use of com.google.devtools.build.lib.packages.AttributeMap 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.AttributeMap in project bazel by bazelbuild.
the class SdkMavenRepositoryTest method testGeneratedAarImport.
@Test
public void testGeneratedAarImport() throws Exception {
sdkMavenRepository.writeBuildFiles(workspaceDir);
Rule aarImport = getConfiguredTarget("//com.google.android:bar-1.0.0").getTarget().getAssociatedRule();
assertThat(aarImport.getRuleClass()).isEqualTo("aar_import");
AttributeMap attributes = RawAttributeMapper.of(aarImport);
assertThat(attributes.get("aar", BuildType.LABEL)).isEqualTo(Label.parseAbsoluteUnchecked("//:repo/com/google/android/bar/1.0.0/bar.aar"));
assertThat(attributes.get("exports", BuildType.LABEL_LIST)).containsExactly(Label.parseAbsoluteUnchecked("//com.google.android:foo-1.0.0"));
}
use of com.google.devtools.build.lib.packages.AttributeMap in project bazel by bazelbuild.
the class SdkMavenRepositoryTest method testGeneratedJavaImport.
@Test
public void testGeneratedJavaImport() throws Exception {
sdkMavenRepository.writeBuildFiles(workspaceDir);
Rule javaImport = getConfiguredTarget("//com.google.android:foo-1.0.0").getTarget().getAssociatedRule();
assertThat(javaImport.getRuleClass()).isEqualTo("java_import");
AttributeMap attributes = RawAttributeMapper.of(javaImport);
assertThat(attributes.get("jars", BuildType.LABEL_LIST)).containsExactly(Label.parseAbsoluteUnchecked("//:repo/com/google/android/foo/1.0.0/foo.jar"));
assertThat(attributes.get("exports", BuildType.LABEL_LIST)).isEmpty();
}
use of com.google.devtools.build.lib.packages.AttributeMap in project bazel by bazelbuild.
the class WorkspaceResolver method resolveTransitiveDependencies.
/**
* Calculates transitive dependencies of the given //external package.
*/
public void resolveTransitiveDependencies(Package externalPackage) {
Location location = Location.fromFile(externalPackage.getFilename());
for (Target target : externalPackage.getTargets()) {
// Targets are //external:foo.
if (target.getTargetKind().startsWith("maven_jar ")) {
RepositoryName repositoryName;
try {
repositoryName = RepositoryName.create("@" + target.getName());
} catch (LabelSyntaxException e) {
handler.handle(Event.error(location, "Invalid repository name for " + target + ": " + e.getMessage()));
return;
}
com.google.devtools.build.lib.packages.Rule workspaceRule = externalPackage.getRule(repositoryName.strippedName());
DefaultModelResolver modelResolver = resolver.getModelResolver();
AttributeMap attributeMap = AggregatingAttributeMapper.of(workspaceRule);
Rule rule;
try {
rule = new Rule(Resolver.getArtifact(attributeMap.get("artifact", Type.STRING)));
} catch (InvalidArtifactCoordinateException e) {
handler.handle(Event.error(location, "Couldn't get attribute: " + e.getMessage()));
return;
}
if (attributeMap.isAttributeValueExplicitlySpecified("repository")) {
modelResolver.addUserRepository(attributeMap.get("repository", Type.STRING));
rule.setRepository(attributeMap.get("repository", Type.STRING), handler);
}
if (attributeMap.isAttributeValueExplicitlySpecified("sha1")) {
rule.setSha1(attributeMap.get("sha1", Type.STRING));
} else {
rule.setSha1(resolver.downloadSha1(rule));
}
ModelSource modelSource;
try {
modelSource = modelResolver.resolveModel(rule.groupId(), rule.artifactId(), rule.version());
} catch (UnresolvableModelException e) {
handler.handle(Event.error("Could not resolve model for " + target + ": " + e.getMessage()));
continue;
}
resolver.addArtifact(rule, modelSource.getLocation());
resolver.resolveEffectiveModel(modelSource, Sets.<String>newHashSet(), rule);
} else if (!target.getTargetKind().startsWith("bind") && !target.getTargetKind().startsWith("source ")) {
handler.handle(Event.warn(location, "Cannot fetch transitive dependencies for " + target + " yet, skipping"));
}
}
}
use of com.google.devtools.build.lib.packages.AttributeMap in project bazel by bazelbuild.
the class AndroidCommon method getTransitivePrerequisites.
public static final <T extends TransitiveInfoProvider> Iterable<T> getTransitivePrerequisites(RuleContext ruleContext, Mode mode, final Class<T> classType) {
IterablesChain.Builder<T> builder = IterablesChain.builder();
AttributeMap attributes = ruleContext.attributes();
for (String attr : TRANSITIVE_ATTRIBUTES) {
if (attributes.has(attr, BuildType.LABEL_LIST)) {
builder.add(ruleContext.getPrerequisites(attr, mode, classType));
}
}
return builder.build();
}
Aggregations