Search in sources :

Example 16 with NoSuchTargetException

use of com.google.devtools.build.lib.packages.NoSuchTargetException in project bazel by bazelbuild.

the class TransitiveTargetFunction method processDeps.

@Override
void processDeps(TransitiveTargetValueBuilder builder, EventHandler eventHandler, TargetAndErrorIfAny targetAndErrorIfAny, Iterable<Entry<SkyKey, ValueOrException2<NoSuchPackageException, NoSuchTargetException>>> depEntries) throws InterruptedException {
    boolean successfulTransitiveLoading = builder.isSuccessfulTransitiveLoading();
    Target target = targetAndErrorIfAny.getTarget();
    NestedSetBuilder<Label> transitiveRootCauses = builder.getTransitiveRootCauses();
    for (Entry<SkyKey, ValueOrException2<NoSuchPackageException, NoSuchTargetException>> entry : depEntries) {
        Label depLabel = (Label) entry.getKey().argument();
        TransitiveTargetValue transitiveTargetValue;
        try {
            transitiveTargetValue = (TransitiveTargetValue) entry.getValue().get();
            if (transitiveTargetValue == null) {
                continue;
            }
        } catch (NoSuchPackageException | NoSuchTargetException e) {
            successfulTransitiveLoading = false;
            transitiveRootCauses.add(depLabel);
            maybeReportErrorAboutMissingEdge(target, depLabel, e, eventHandler);
            continue;
        }
        builder.getTransitiveSuccessfulPkgs().addTransitive(transitiveTargetValue.getTransitiveSuccessfulPackages());
        builder.getTransitiveUnsuccessfulPkgs().addTransitive(transitiveTargetValue.getTransitiveUnsuccessfulPackages());
        builder.getTransitiveTargets().addTransitive(transitiveTargetValue.getTransitiveTargets());
        NestedSet<Label> rootCauses = transitiveTargetValue.getTransitiveRootCauses();
        if (rootCauses != null) {
            successfulTransitiveLoading = false;
            transitiveRootCauses.addTransitive(rootCauses);
            if (transitiveTargetValue.getErrorLoadingTarget() != null) {
                maybeReportErrorAboutMissingEdge(target, depLabel, transitiveTargetValue.getErrorLoadingTarget(), eventHandler);
            }
        }
        NestedSet<Class<? extends Fragment>> depFragments = transitiveTargetValue.getTransitiveConfigFragments();
        Collection<Class<? extends Fragment>> depFragmentsAsCollection = depFragments.toCollection();
        // The simplest collection technique would be to unconditionally add all deps' nested
        // sets to the current target's nested set. But when there's large overlap between their
        // fragment needs, this produces unnecessarily bloated nested sets and a lot of references
        // that don't contribute anything unique to the required fragment set. So we optimize here
        // by completely skipping sets that don't offer anything new. More fine-tuned optimization
        // is possible, but this offers a good balance between simplicity and practical efficiency.
        Set<Class<? extends Fragment>> addedConfigFragments = builder.getConfigFragmentsFromDeps();
        if (!addedConfigFragments.containsAll(depFragmentsAsCollection)) {
            builder.getTransitiveConfigFragments().addTransitive(depFragments);
            addedConfigFragments.addAll(depFragmentsAsCollection);
        }
    }
    builder.setSuccessfulTransitiveLoading(successfulTransitiveLoading);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) Label(com.google.devtools.build.lib.cmdline.Label) ValueOrException2(com.google.devtools.build.skyframe.ValueOrException2) Fragment(com.google.devtools.build.lib.analysis.config.BuildConfiguration.Fragment) Target(com.google.devtools.build.lib.packages.Target) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException)

Example 17 with NoSuchTargetException

use of com.google.devtools.build.lib.packages.NoSuchTargetException in project bazel by bazelbuild.

the class TargetMarkerFunctionTest method testRuleWithError.

@Test
public void testRuleWithError() throws Exception {
    reporter.removeHandler(failFastHandler);
    scratch.file("a/BUILD", "genrule(name = 'conflict1', cmd = '', srcs = [], outs = ['conflict'])", "genrule(name = 'conflict2', cmd = '', srcs = [], outs = ['conflict'])");
    NoSuchTargetException exn = (NoSuchTargetException) getErrorFromTargetValue("@//a:conflict1");
    assertThat(exn.getMessage()).contains("Target '//a:conflict1' contains an error and its package is in error");
    assertEquals("//a:conflict1", exn.getLabel().toString());
    assertTrue(exn.hasTarget());
}
Also used : NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) Test(org.junit.Test)

Example 18 with NoSuchTargetException

use of com.google.devtools.build.lib.packages.NoSuchTargetException in project bazel by bazelbuild.

the class SkyQueryEnvironment method makeTargetsFromPackageKeyToTargetKeyMap.

@ThreadSafe
public Map<SkyKey, Target> makeTargetsFromPackageKeyToTargetKeyMap(Multimap<SkyKey, SkyKey> packageKeyToTargetKeyMap) throws InterruptedException {
    ImmutableMap.Builder<SkyKey, Target> result = ImmutableMap.builder();
    Set<SkyKey> processedTargets = new HashSet<>();
    Map<SkyKey, SkyValue> packageMap = graph.getSuccessfulValues(packageKeyToTargetKeyMap.keySet());
    for (Map.Entry<SkyKey, SkyValue> entry : packageMap.entrySet()) {
        for (SkyKey targetKey : packageKeyToTargetKeyMap.get(entry.getKey())) {
            if (processedTargets.add(targetKey)) {
                try {
                    result.put(targetKey, ((PackageValue) entry.getValue()).getPackage().getTarget((SKYKEY_TO_LABEL.apply(targetKey)).getName()));
                } catch (NoSuchTargetException e) {
                // Skip missing target.
                }
            }
        }
    }
    return result.build();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) SkyValue(com.google.devtools.build.skyframe.SkyValue) Target(com.google.devtools.build.lib.packages.Target) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) PackageValue(com.google.devtools.build.lib.skyframe.PackageValue) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashSet(java.util.LinkedHashSet) CompactHashSet(com.google.devtools.build.lib.collect.CompactHashSet) HashSet(java.util.HashSet) ThreadSafe(com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe)

Example 19 with NoSuchTargetException

use of com.google.devtools.build.lib.packages.NoSuchTargetException in project bazel by bazelbuild.

the class GenQuery method constructPackageMap.

/**
   * Precomputes the transitive closure of the scope. Returns two maps: one identifying the
   * successful packages, and the other identifying the valid targets. Breaks in the transitive
   * closure of the scope will cause the query to error out early.
   */
@Nullable
private static Pair<ImmutableMap<PackageIdentifier, Package>, ImmutableMap<Label, Target>> constructPackageMap(SkyFunction.Environment env, Collection<Target> scope) throws InterruptedException, BrokenQueryScopeException {
    // It is not necessary for correctness to construct intermediate NestedSets; we could iterate
    // over individual targets in scope immediately. However, creating a composite NestedSet first
    // saves us from iterating over the same sub-NestedSets multiple times.
    NestedSetBuilder<Label> validTargets = NestedSetBuilder.stableOrder();
    NestedSetBuilder<PackageIdentifier> successfulPackageNames = NestedSetBuilder.stableOrder();
    for (Target target : scope) {
        SkyKey key = TransitiveTargetValue.key(target.getLabel());
        TransitiveTargetValue transNode = (TransitiveTargetValue) env.getValue(key);
        if (transNode == null) {
            return null;
        }
        if (!transNode.getTransitiveUnsuccessfulPackages().isEmpty()) {
            // path, as otherwise this configured target would have failed earlier. See b/34132681.
            throw new BrokenQueryScopeException("errors were encountered while computing transitive closure of the scope.");
        }
        validTargets.addTransitive(transNode.getTransitiveTargets());
        successfulPackageNames.addTransitive(transNode.getTransitiveSuccessfulPackages());
    }
    // Construct the package id to package map for all successful packages.
    ImmutableMap.Builder<PackageIdentifier, Package> packageMapBuilder = ImmutableMap.builder();
    for (PackageIdentifier pkgId : successfulPackageNames.build()) {
        PackageValue pkg = (PackageValue) env.getValue(PackageValue.key(pkgId));
        Preconditions.checkNotNull(pkg, "package %s not preloaded", pkgId);
        Preconditions.checkState(!pkg.getPackage().containsErrors(), "package %s was found to both have and not have errors.", pkgId);
        packageMapBuilder.put(pkg.getPackage().getPackageIdentifier(), pkg.getPackage());
    }
    ImmutableMap<PackageIdentifier, Package> packageMap = packageMapBuilder.build();
    ImmutableMap.Builder<Label, Target> validTargetsMapBuilder = ImmutableMap.builder();
    for (Label label : validTargets.build()) {
        try {
            Target target = packageMap.get(label.getPackageIdentifier()).getTarget(label.getName());
            validTargetsMapBuilder.put(label, target);
        } catch (NoSuchTargetException e) {
            throw new IllegalStateException(e);
        }
    }
    return Pair.of(packageMap, validTargetsMapBuilder.build());
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) Label(com.google.devtools.build.lib.cmdline.Label) PackageValue(com.google.devtools.build.lib.skyframe.PackageValue) ImmutableMap(com.google.common.collect.ImmutableMap) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Target(com.google.devtools.build.lib.packages.Target) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) Package(com.google.devtools.build.lib.packages.Package) TransitiveTargetValue(com.google.devtools.build.lib.skyframe.TransitiveTargetValue) Nullable(javax.annotation.Nullable)

Example 20 with NoSuchTargetException

use of com.google.devtools.build.lib.packages.NoSuchTargetException in project bazel by bazelbuild.

the class CircularDependencyTest method testOneRuleImplicitCycleJava.

/**
   * Test to detect implicit input/output file overlap in rules.
   */
@Test
public void testOneRuleImplicitCycleJava() throws Exception {
    Package pkg = createScratchPackageForImplicitCycle("cycle", "java_library(name='jcyc',", "      srcs = ['libjcyc.jar', 'foo.java'])");
    try {
        pkg.getTarget("jcyc");
        fail();
    } catch (NoSuchTargetException e) {
    /* ok */
    }
    assertTrue(pkg.containsErrors());
    assertContainsEvent("rule 'jcyc' has file 'libjcyc.jar' as both an" + " input and an output");
}
Also used : NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) Package(com.google.devtools.build.lib.packages.Package) Test(org.junit.Test)

Aggregations

NoSuchTargetException (com.google.devtools.build.lib.packages.NoSuchTargetException)23 SkyKey (com.google.devtools.build.skyframe.SkyKey)13 Label (com.google.devtools.build.lib.cmdline.Label)12 Target (com.google.devtools.build.lib.packages.Target)12 NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)9 Package (com.google.devtools.build.lib.packages.Package)9 Test (org.junit.Test)6 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)5 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)4 Attribute (com.google.devtools.build.lib.packages.Attribute)4 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)4 HashMap (java.util.HashMap)4 Nullable (javax.annotation.Nullable)4 Rule (com.google.devtools.build.lib.packages.Rule)3 SkyValue (com.google.devtools.build.skyframe.SkyValue)3 ValueOrException2 (com.google.devtools.build.skyframe.ValueOrException2)3 LinkedHashSet (java.util.LinkedHashSet)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 InconsistentAspectOrderException (com.google.devtools.build.lib.analysis.DependencyResolver.InconsistentAspectOrderException)2 MergedConfiguredTarget (com.google.devtools.build.lib.analysis.MergedConfiguredTarget)2