Search in sources :

Example 6 with NoSuchThingException

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

the class RedirectChaser method followRedirects.

/**
   * Follows the 'srcs' attribute of the given label recursively. Keeps repeating as long as the
   * labels are either <code>alias</code> or <code>bind</code> rules.
   *
   * @param env for loading the packages
   * @param label the label to start at
   * @param name user-meaningful description of the content being resolved
   * @return the label which cannot be further resolved
   * @throws InvalidConfigurationException if something goes wrong
   */
@Nullable
public static Label followRedirects(ConfigurationEnvironment env, Label label, String name) throws InvalidConfigurationException, InterruptedException {
    Label oldLabel = null;
    Set<Label> visitedLabels = new HashSet<>();
    visitedLabels.add(label);
    try {
        while (true) {
            Target possibleRedirect = env.getTarget(label);
            if (possibleRedirect == null) {
                return null;
            }
            Label newLabel = getBindOrAliasRedirect(possibleRedirect);
            if (newLabel == null) {
                return label;
            }
            newLabel = label.resolveRepositoryRelative(newLabel);
            oldLabel = label;
            label = newLabel;
            if (!visitedLabels.add(label)) {
                throw new InvalidConfigurationException("The " + name + " points to a rule which " + "recursively references itself. The label " + label + " is part of the loop");
            }
        }
    } catch (NoSuchThingException e) {
        String prefix = oldLabel == null ? "" : "in target '" + oldLabel + "': ";
        throw new InvalidConfigurationException(prefix + e.getMessage(), e);
    }
}
Also used : Target(com.google.devtools.build.lib.packages.Target) NoSuchThingException(com.google.devtools.build.lib.packages.NoSuchThingException) Label(com.google.devtools.build.lib.cmdline.Label) HashSet(java.util.HashSet) InvalidConfigurationException(com.google.devtools.build.lib.analysis.config.InvalidConfigurationException) Nullable(javax.annotation.Nullable)

Example 7 with NoSuchThingException

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

the class SkyframeExecutor method createConfigurations.

/**
   * Asks the Skyframe evaluator to build the value for BuildConfigurationCollection and returns the
   * result. Also invalidates {@link PrecomputedValue#BLAZE_DIRECTORIES} if it has changed.
   */
public BuildConfigurationCollection createConfigurations(ExtendedEventHandler eventHandler, ConfigurationFactory configurationFactory, BuildOptions buildOptions, Set<String> multiCpu, boolean keepGoing) throws InvalidConfigurationException, InterruptedException {
    this.configurationFactory.set(configurationFactory);
    this.configurationFragments.set(ImmutableList.copyOf(configurationFactory.getFactories()));
    SkyKey skyKey = ConfigurationCollectionValue.key(buildOptions, ImmutableSortedSet.copyOf(multiCpu));
    EvaluationResult<ConfigurationCollectionValue> result = buildDriver.evaluate(Arrays.asList(skyKey), keepGoing, DEFAULT_THREAD_COUNT, eventHandler);
    if (result.hasError()) {
        Throwable e = result.getError(skyKey).getException();
        // Wrap loading failed exceptions
        if (e instanceof NoSuchThingException) {
            e = new InvalidConfigurationException(e);
        }
        Throwables.propagateIfInstanceOf(e, InvalidConfigurationException.class);
        throw new IllegalStateException("Unknown error during ConfigurationCollectionValue evaluation", e);
    }
    ConfigurationCollectionValue configurationValue = result.get(skyKey);
    return configurationValue.getConfigurationCollection();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) NoSuchThingException(com.google.devtools.build.lib.packages.NoSuchThingException) InvalidConfigurationException(com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)

Example 8 with NoSuchThingException

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

the class PreciseAspectResolver method computeAspectDependencies.

@Override
public ImmutableMultimap<Attribute, Label> computeAspectDependencies(Target target, DependencyFilter dependencyFilter) throws InterruptedException {
    Multimap<Attribute, Label> result = LinkedListMultimap.create();
    if (target instanceof Rule) {
        Multimap<Attribute, Label> transitions = ((Rule) target).getTransitions(DependencyFilter.NO_NODEP_ATTRIBUTES);
        for (Entry<Attribute, Label> entry : transitions.entries()) {
            Target toTarget;
            try {
                toTarget = packageProvider.getTarget(eventHandler, entry.getValue());
                result.putAll(AspectDefinition.visitAspectsIfRequired(target, entry.getKey(), toTarget, dependencyFilter));
            } catch (NoSuchThingException e) {
            // Do nothing. One of target direct deps has an error. The dependency on the BUILD file
            // (or one of the files included in it) will be reported in the query result of :BUILD.
            }
        }
    }
    return ImmutableMultimap.copyOf(result);
}
Also used : Target(com.google.devtools.build.lib.packages.Target) NoSuchThingException(com.google.devtools.build.lib.packages.NoSuchThingException) 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 9 with NoSuchThingException

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

the class CrosstoolConfigurationLoader method getCrosstoolProtoFromCrosstoolFile.

private static CrosstoolProto getCrosstoolProtoFromCrosstoolFile(ConfigurationEnvironment env, Label crosstoolTop) throws IOException, InvalidConfigurationException, InterruptedException {
    final Path path;
    try {
        Package containingPackage = env.getTarget(crosstoolTop.getLocalTargetLabel("BUILD")).getPackage();
        if (containingPackage == null) {
            return null;
        }
        path = env.getPath(containingPackage, CROSSTOOL_CONFIGURATION_FILENAME);
    } catch (LabelSyntaxException e) {
        throw new InvalidConfigurationException(e);
    } catch (NoSuchThingException e) {
        // Handled later
        return null;
    }
    if (path == null || !path.exists()) {
        return null;
    }
    return new CrosstoolProto(path.getDigest(), "CROSSTOOL file " + path.getPathString()) {

        @Override
        public String getContents() throws IOException {
            try (InputStream inputStream = path.getInputStream()) {
                return new String(FileSystemUtils.readContentAsLatin1(inputStream));
            }
        }
    };
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) NoSuchThingException(com.google.devtools.build.lib.packages.NoSuchThingException) LabelSyntaxException(com.google.devtools.build.lib.cmdline.LabelSyntaxException) InputStream(java.io.InputStream) Package(com.google.devtools.build.lib.packages.Package) InvalidConfigurationException(com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)

Example 10 with NoSuchThingException

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

the class JvmConfigurationLoader method createDefault.

@Nullable
private static Jvm createDefault(ConfigurationEnvironment lookup, String javaHome, String cpu) throws InvalidConfigurationException, LabelSyntaxException, InterruptedException {
    try {
        Label label = Label.parseAbsolute(javaHome);
        label = RedirectChaser.followRedirects(lookup, label, "jdk");
        if (label == null) {
            return null;
        }
        Target javaHomeTarget = lookup.getTarget(label);
        if (javaHomeTarget instanceof Rule) {
            if (!((Rule) javaHomeTarget).getRuleClass().equals("java_runtime_suite")) {
                throw new InvalidConfigurationException("Unexpected javabase rule kind '" + ((Rule) javaHomeTarget).getRuleClass() + "'");
            }
            return createFromRuntimeSuite(lookup, (Rule) javaHomeTarget, cpu);
        }
        throw new InvalidConfigurationException("No JVM target found under " + javaHome + " that would work for " + cpu);
    } catch (NoSuchThingException e) {
        lookup.getEventHandler().handle(Event.error(e.getMessage()));
        throw new InvalidConfigurationException(e.getMessage(), e);
    }
}
Also used : Target(com.google.devtools.build.lib.packages.Target) NoSuchThingException(com.google.devtools.build.lib.packages.NoSuchThingException) Label(com.google.devtools.build.lib.cmdline.Label) Rule(com.google.devtools.build.lib.packages.Rule) InvalidConfigurationException(com.google.devtools.build.lib.analysis.config.InvalidConfigurationException) Nullable(javax.annotation.Nullable)

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