Search in sources :

Example 6 with InvalidConfigurationException

use of com.google.devtools.build.lib.analysis.config.InvalidConfigurationException in project bazel by bazelbuild.

the class ConfiguredTargetFunction method checkForMissingFragments.

/**
   * Diagnostic helper method for dynamic configurations: checks the config fragments required by
   * a dep against the fragments in its actual configuration. If any are missing, triggers a
   * descriptive "missing fragments" error.
   */
private static void checkForMissingFragments(Environment env, TargetAndConfiguration ctgValue, String attribute, Dependency dep, Set<Class<? extends BuildConfiguration.Fragment>> expectedDepFragments) throws DependencyEvaluationException {
    Set<String> ctgFragmentNames = new HashSet<>();
    for (BuildConfiguration.Fragment fragment : ctgValue.getConfiguration().getAllFragments().values()) {
        ctgFragmentNames.add(fragment.getClass().getSimpleName());
    }
    Set<String> depFragmentNames = new HashSet<>();
    for (Class<? extends BuildConfiguration.Fragment> fragmentClass : expectedDepFragments) {
        depFragmentNames.add(fragmentClass.getSimpleName());
    }
    Set<String> missing = Sets.difference(depFragmentNames, ctgFragmentNames);
    if (!missing.isEmpty()) {
        String msg = String.format("%s: dependency %s from attribute \"%s\" is missing required config fragments: %s", ctgValue.getLabel(), dep.getLabel(), attribute, Joiner.on(", ").join(missing));
        env.getListener().handle(Event.error(msg));
        throw new DependencyEvaluationException(new InvalidConfigurationException(msg));
    }
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) HashSet(java.util.HashSet) InvalidConfigurationException(com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)

Example 7 with InvalidConfigurationException

use of com.google.devtools.build.lib.analysis.config.InvalidConfigurationException in project bazel by bazelbuild.

the class BuildConfigurationFunction method compute.

@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException, BuildConfigurationFunctionException {
    BuildConfigurationValue.Key key = (BuildConfigurationValue.Key) skyKey.argument();
    Set<Fragment> fragments;
    try {
        fragments = getConfigurationFragments(key, env);
    } catch (InvalidConfigurationException e) {
        throw new BuildConfigurationFunctionException(e);
    }
    if (fragments == null) {
        return null;
    }
    ClassToInstanceMap<Fragment> fragmentsMap = MutableClassToInstanceMap.create();
    for (Fragment fragment : fragments) {
        fragmentsMap.put(fragment.getClass(), fragment);
    }
    BuildConfiguration config = new BuildConfiguration(directories, fragmentsMap, key.getBuildOptions(), !key.actionsEnabled());
    // Unlike static configurations, dynamic configurations don't need to embed transition logic
    // within the configuration itself. However we still use this interface to provide a mapping
    // between Transition types (e.g. HOST) and the dynamic transitions that apply those
    // transitions. Once static configurations are cleaned out we won't need this interface
    // any more (all the centralized logic that maintains the transition logic can be distributed
    // to the actual rule code that uses it).
    config.setConfigurationTransitions(collectionFactory.getDynamicTransitionLogic(config));
    return new BuildConfigurationValue(config);
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) Fragment(com.google.devtools.build.lib.analysis.config.BuildConfiguration.Fragment) SkyKey(com.google.devtools.build.skyframe.SkyKey) InvalidConfigurationException(com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)

Example 8 with InvalidConfigurationException

use of com.google.devtools.build.lib.analysis.config.InvalidConfigurationException in project bazel by bazelbuild.

the class ConfigurationCollectionFunction method getHostConfiguration.

/** Returns the host configuration, or null on missing Skyframe deps. */
private BuildConfiguration getHostConfiguration(Environment env, BuildConfiguration targetConfiguration) throws InvalidConfigurationException, InterruptedException {
    if (targetConfiguration.useDynamicConfigurations()) {
        BuildOptions targetOptions = targetConfiguration.getOptions();
        BuildOptions hostOptions = targetOptions.get(BuildConfiguration.Options.class).useDistinctHostConfiguration ? HostTransition.INSTANCE.apply(targetConfiguration.getOptions()) : targetOptions;
        SkyKey hostConfigKey = BuildConfigurationValue.key(targetConfiguration.trimConfigurations() ? targetConfiguration.fragmentClasses() : ((ConfiguredRuleClassProvider) ruleClassProvider).getAllFragments(), hostOptions);
        BuildConfigurationValue skyValHost = (BuildConfigurationValue) env.getValueOrThrow(hostConfigKey, InvalidConfigurationException.class);
        // Also preload the target configuration so the configured target functions for
        // top-level targets don't have to waste cycles from a missing Skyframe dep.
        SkyKey targetConfigKey = BuildConfigurationValue.key(targetConfiguration.fragmentClasses(), targetOptions);
        BuildConfigurationValue skyValTarget = (BuildConfigurationValue) env.getValueOrThrow(targetConfigKey, InvalidConfigurationException.class);
        if (skyValHost == null || skyValTarget == null) {
            return null;
        }
        return skyValHost.getConfiguration();
    } else {
        return targetConfiguration.getConfiguration(Attribute.ConfigurationTransition.HOST);
    }
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) SkyKey(com.google.devtools.build.skyframe.SkyKey) BuildOptions(com.google.devtools.build.lib.analysis.config.BuildOptions) ConfiguredRuleClassProvider(com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider) InvalidConfigurationException(com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)

Example 9 with InvalidConfigurationException

use of com.google.devtools.build.lib.analysis.config.InvalidConfigurationException in project bazel by bazelbuild.

the class JvmConfigurationLoader method createFromRuntimeSuite.

// TODO(b/34175492): eventually the Jvm fragement will containg only the label of a java_runtime
// rule, and all of the configuration will be accessed using JavaRuntimeProvider.
private static Jvm createFromRuntimeSuite(ConfigurationEnvironment lookup, Rule javaRuntimeSuite, String cpu) throws InvalidConfigurationException, InterruptedException, NoSuchTargetException, NoSuchPackageException {
    Label javaRuntimeLabel = selectRuntime(javaRuntimeSuite, cpu);
    Target javaRuntimeTarget = lookup.getTarget(javaRuntimeLabel);
    if (javaRuntimeTarget == null) {
        return null;
    }
    if (!(javaRuntimeTarget instanceof Rule)) {
        throw new InvalidConfigurationException(String.format("Invalid java_runtime '%s'", javaRuntimeLabel));
    }
    Rule javaRuntimeRule = (Rule) javaRuntimeTarget;
    if (!javaRuntimeRule.getRuleClass().equals("java_runtime")) {
        throw new InvalidConfigurationException(String.format("Expected a java_runtime rule, was '%s'", javaRuntimeRule.getRuleClass()));
    }
    RawAttributeMapper attributes = RawAttributeMapper.of(javaRuntimeRule);
    PathFragment javaHomePath = defaultJavaHome(javaRuntimeLabel);
    if (attributes.isAttributeValueExplicitlySpecified("java_home")) {
        javaHomePath = javaHomePath.getRelative(attributes.get("java_home", Type.STRING));
    }
    return new Jvm(javaHomePath, javaRuntimeLabel);
}
Also used : RawAttributeMapper(com.google.devtools.build.lib.packages.RawAttributeMapper) Target(com.google.devtools.build.lib.packages.Target) Label(com.google.devtools.build.lib.cmdline.Label) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Rule(com.google.devtools.build.lib.packages.Rule) InvalidConfigurationException(com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)

Example 10 with InvalidConfigurationException

use of com.google.devtools.build.lib.analysis.config.InvalidConfigurationException 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)

Aggregations

InvalidConfigurationException (com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)24 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)8 Label (com.google.devtools.build.lib.cmdline.Label)8 Nullable (javax.annotation.Nullable)7 Target (com.google.devtools.build.lib.packages.Target)6 SkyKey (com.google.devtools.build.skyframe.SkyKey)6 NoSuchThingException (com.google.devtools.build.lib.packages.NoSuchThingException)5 BuildOptions (com.google.devtools.build.lib.analysis.config.BuildOptions)4 Attribute (com.google.devtools.build.lib.packages.Attribute)4 Rule (com.google.devtools.build.lib.packages.Rule)4 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)3 InconsistentAspectOrderException (com.google.devtools.build.lib.analysis.DependencyResolver.InconsistentAspectOrderException)3 TargetAndConfiguration (com.google.devtools.build.lib.analysis.TargetAndConfiguration)3 Fragment (com.google.devtools.build.lib.analysis.config.BuildConfiguration.Fragment)3 ConfigMatchingProvider (com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider)3 Package (com.google.devtools.build.lib.packages.Package)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)2 Dependency (com.google.devtools.build.lib.analysis.Dependency)2