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));
}
}
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);
}
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);
}
}
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);
}
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);
}
}
Aggregations