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