Search in sources :

Example 11 with NoSuchThingException

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

the class ConfiguredTargetFunction method resolveAspectDependencies.

/**
   * Given a list of {@link Dependency} objects, returns a multimap from the {@link SkyKey} of the
   * dependency to the {@link ConfiguredAspect} instances that should be merged into it.
   *
   * <p>Returns null if the required aspects are not computed yet.
   */
@Nullable
private static OrderedSetMultimap<SkyKey, ConfiguredAspect> resolveAspectDependencies(Environment env, Map<SkyKey, ConfiguredTarget> configuredTargetMap, Iterable<Dependency> deps, NestedSetBuilder<Package> transitivePackages) throws AspectCreationException, InterruptedException {
    OrderedSetMultimap<SkyKey, ConfiguredAspect> result = OrderedSetMultimap.create();
    Set<SkyKey> allAspectKeys = new HashSet<>();
    for (Dependency dep : deps) {
        allAspectKeys.addAll(getAspectKeys(dep).values());
    }
    Map<SkyKey, ValueOrException2<AspectCreationException, NoSuchThingException>> depAspects = env.getValuesOrThrow(allAspectKeys, AspectCreationException.class, NoSuchThingException.class);
    for (Dependency dep : deps) {
        SkyKey depKey = TO_KEYS.apply(dep);
        // twice.
        if (result.containsKey(depKey)) {
            continue;
        }
        Map<AspectDescriptor, SkyKey> aspectToKeys = getAspectKeys(dep);
        ConfiguredTarget depConfiguredTarget = configuredTargetMap.get(depKey);
        for (AspectDeps depAspect : dep.getAspects().getVisibleAspects()) {
            SkyKey aspectKey = aspectToKeys.get(depAspect.getAspect());
            AspectValue aspectValue;
            try {
                // TODO(ulfjack): Catch all thrown AspectCreationException and NoSuchThingException
                // instances and merge them into a single Exception to get full root cause data.
                aspectValue = (AspectValue) depAspects.get(aspectKey).get();
            } catch (NoSuchThingException e) {
                throw new AspectCreationException(String.format("Evaluation of aspect %s on %s failed: %s", depAspect.getAspect().getAspectClass().getName(), dep.getLabel(), e.toString()));
            }
            if (aspectValue == null) {
                // Dependent aspect has either not been computed yet or is in error.
                return null;
            }
            if (!aspectMatchesConfiguredTarget(depConfiguredTarget, aspectValue.getAspect())) {
                continue;
            }
            result.put(depKey, aspectValue.getConfiguredAspect());
            transitivePackages.addTransitive(aspectValue.getTransitivePackages());
        }
    }
    return result;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) ConfiguredAspect(com.google.devtools.build.lib.analysis.ConfiguredAspect) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) MergedConfiguredTarget(com.google.devtools.build.lib.analysis.MergedConfiguredTarget) Dependency(com.google.devtools.build.lib.analysis.Dependency) ValueOrException2(com.google.devtools.build.skyframe.ValueOrException2) AspectCreationException(com.google.devtools.build.lib.skyframe.AspectFunction.AspectCreationException) NoSuchThingException(com.google.devtools.build.lib.packages.NoSuchThingException) AspectDeps(com.google.devtools.build.lib.analysis.AspectCollection.AspectDeps) AspectDescriptor(com.google.devtools.build.lib.packages.AspectDescriptor) HashSet(java.util.HashSet) Nullable(javax.annotation.Nullable)

Example 12 with NoSuchThingException

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

the class RecursivePackageProviderBackedTargetPatternResolver method bulkGetTargetsInPackage.

private Map<PackageIdentifier, ResolvedTargets<Target>> bulkGetTargetsInPackage(String originalPattern, Iterable<PackageIdentifier> pkgIds, FilteringPolicy policy) throws InterruptedException {
    try {
        Map<PackageIdentifier, Package> pkgs = bulkGetPackages(pkgIds);
        if (pkgs.size() != Iterables.size(pkgIds)) {
            throw new IllegalStateException("Bulk package retrieval missing results: " + Sets.difference(ImmutableSet.copyOf(pkgIds), pkgs.keySet()));
        }
        ImmutableMap.Builder<PackageIdentifier, ResolvedTargets<Target>> result = ImmutableMap.builder();
        for (PackageIdentifier pkgId : pkgIds) {
            Package pkg = pkgs.get(pkgId);
            result.put(pkgId, TargetPatternResolverUtil.resolvePackageTargets(pkg, policy));
        }
        return result.build();
    } catch (NoSuchThingException e) {
        String message = TargetPatternResolverUtil.getParsingErrorMessage(e.getMessage(), originalPattern);
        throw new IllegalStateException("Mismatch: Expected given pkgIds to correspond to valid Packages. " + message, e);
    }
}
Also used : NoSuchThingException(com.google.devtools.build.lib.packages.NoSuchThingException) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) ResolvedTargets(com.google.devtools.build.lib.cmdline.ResolvedTargets) Package(com.google.devtools.build.lib.packages.Package) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 13 with NoSuchThingException

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

the class BuildView method getDirectPrerequisiteDependenciesForTesting.

@VisibleForTesting
public OrderedSetMultimap<Attribute, Dependency> getDirectPrerequisiteDependenciesForTesting(final ExtendedEventHandler eventHandler, final ConfiguredTarget ct, BuildConfigurationCollection configurations) throws EvalException, InvalidConfigurationException, InterruptedException, InconsistentAspectOrderException {
    if (!(ct.getTarget() instanceof Rule)) {
        return OrderedSetMultimap.create();
    }
    class SilentDependencyResolver extends DependencyResolver {

        @Override
        protected void invalidVisibilityReferenceHook(TargetAndConfiguration node, Label label) {
            throw new RuntimeException("bad visibility on " + label + " during testing unexpected");
        }

        @Override
        protected void invalidPackageGroupReferenceHook(TargetAndConfiguration node, Label label) {
            throw new RuntimeException("bad package group on " + label + " during testing unexpected");
        }

        @Override
        protected void missingEdgeHook(Target from, Label to, NoSuchThingException e) {
            throw new RuntimeException("missing dependency from " + from.getLabel() + " to " + to + ": " + e.getMessage(), e);
        }

        @Override
        protected Target getTarget(Target from, Label label, NestedSetBuilder<Label> rootCauses) throws InterruptedException {
            try {
                return skyframeExecutor.getPackageManager().getTarget(eventHandler, label);
            } catch (NoSuchThingException e) {
                throw new IllegalStateException(e);
            }
        }

        @Override
        protected List<BuildConfiguration> getConfigurations(Set<Class<? extends BuildConfiguration.Fragment>> fragments, Iterable<BuildOptions> buildOptions) {
            Preconditions.checkArgument(ct.getConfiguration().fragmentClasses().equals(fragments));
            Dependency asDep = Dependency.withTransitionAndAspects(ct.getLabel(), Attribute.ConfigurationTransition.NONE, AspectCollection.EMPTY);
            ImmutableList.Builder<BuildConfiguration> builder = ImmutableList.builder();
            for (BuildOptions options : buildOptions) {
                builder.add(Iterables.getOnlyElement(skyframeExecutor.getConfigurations(eventHandler, options, ImmutableList.<Dependency>of(asDep)).values()));
            }
            return builder.build();
        }
    }
    DependencyResolver dependencyResolver = new SilentDependencyResolver();
    TargetAndConfiguration ctgNode = new TargetAndConfiguration(ct.getTarget(), ct.getConfiguration());
    return dependencyResolver.dependentNodeMap(ctgNode, configurations.getHostConfiguration(), /*aspect=*/
    null, getConfigurableAttributeKeysForTesting(eventHandler, ctgNode));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) NestedSet(com.google.devtools.build.lib.collect.nestedset.NestedSet) ImmutableList(com.google.common.collect.ImmutableList) Label(com.google.devtools.build.lib.cmdline.Label) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) Target(com.google.devtools.build.lib.packages.Target) NoSuchThingException(com.google.devtools.build.lib.packages.NoSuchThingException) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) BuildOptions(com.google.devtools.build.lib.analysis.config.BuildOptions) Rule(com.google.devtools.build.lib.packages.Rule) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

NoSuchThingException (com.google.devtools.build.lib.packages.NoSuchThingException)13 Target (com.google.devtools.build.lib.packages.Target)9 Label (com.google.devtools.build.lib.cmdline.Label)7 Rule (com.google.devtools.build.lib.packages.Rule)7 InvalidConfigurationException (com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)5 HashSet (java.util.HashSet)4 Nullable (javax.annotation.Nullable)4 Package (com.google.devtools.build.lib.packages.Package)3 SkyKey (com.google.devtools.build.skyframe.SkyKey)3 OutputFile (com.google.devtools.build.lib.packages.OutputFile)2 Path (com.google.devtools.build.lib.vfs.Path)2 LinkedHashSet (java.util.LinkedHashSet)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 AspectDeps (com.google.devtools.build.lib.analysis.AspectCollection.AspectDeps)1 BlazeDirectories (com.google.devtools.build.lib.analysis.BlazeDirectories)1 ConfiguredAspect (com.google.devtools.build.lib.analysis.ConfiguredAspect)1 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)1