Search in sources :

Example 46 with Rule

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();
}
Also used : Attribute(com.google.devtools.build.lib.packages.Attribute) Label(com.google.devtools.build.lib.cmdline.Label) Collection(java.util.Collection) Rule(com.google.devtools.build.lib.packages.Rule) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) AttributeMap(com.google.devtools.build.lib.packages.AttributeMap)

Example 47 with Rule

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);
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Attribute(com.google.devtools.build.lib.packages.Attribute) AspectCycleOnPathException(com.google.devtools.build.lib.analysis.AspectCollection.AspectCycleOnPathException) ImmutableList(com.google.common.collect.ImmutableList) AspectDescriptor(com.google.devtools.build.lib.packages.AspectDescriptor) Rule(com.google.devtools.build.lib.packages.Rule) Aspect(com.google.devtools.build.lib.packages.Aspect)

Example 48 with Rule

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);
    }
}
Also used : Attribute(com.google.devtools.build.lib.packages.Attribute) Label(com.google.devtools.build.lib.cmdline.Label) Rule(com.google.devtools.build.lib.packages.Rule)

Example 49 with Rule

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:");
    }
}
Also used : RepositoryCache(com.google.devtools.build.lib.bazel.repository.cache.RepositoryCache) Rule(com.google.devtools.build.lib.packages.Rule) IOException(java.io.IOException) Test(org.junit.Test)

Example 50 with Rule

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");
    }
}
Also used : RepositoryCache(com.google.devtools.build.lib.bazel.repository.cache.RepositoryCache) Rule(com.google.devtools.build.lib.packages.Rule) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Rule (com.google.devtools.build.lib.packages.Rule)79 Test (org.junit.Test)27 Label (com.google.devtools.build.lib.cmdline.Label)26 Attribute (com.google.devtools.build.lib.packages.Attribute)20 Target (com.google.devtools.build.lib.packages.Target)19 Nullable (javax.annotation.Nullable)10 RawAttributeMapper (com.google.devtools.build.lib.packages.RawAttributeMapper)9 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)9 OutputFile (com.google.devtools.build.lib.packages.OutputFile)8 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)7 NoSuchThingException (com.google.devtools.build.lib.packages.NoSuchThingException)7 SkyKey (com.google.devtools.build.skyframe.SkyKey)7 ImmutableList (com.google.common.collect.ImmutableList)6 InputFile (com.google.devtools.build.lib.packages.InputFile)6 IOException (java.io.IOException)6 LinkedHashSet (java.util.LinkedHashSet)6 AggregatingAttributeMapper (com.google.devtools.build.lib.packages.AggregatingAttributeMapper)5 Package (com.google.devtools.build.lib.packages.Package)5 Artifact (com.google.devtools.build.lib.actions.Artifact)4 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)4