use of com.google.devtools.build.lib.cmdline.LabelSyntaxException in project bazel by bazelbuild.
the class SkyQueryEnvironment method getBuildFiles.
@ThreadSafe
@Override
public Set<Target> getBuildFiles(QueryExpression caller, Set<Target> nodes, boolean buildFiles, boolean subincludes, boolean loads) throws QueryException {
Set<Target> dependentFiles = new LinkedHashSet<>();
Set<Package> seenPackages = new HashSet<>();
// Keep track of seen labels, to avoid adding a fake subinclude label that also exists as a
// real target.
Set<Label> seenLabels = new HashSet<>();
// extensions) for package "pkg", to "buildfiles".
for (Target x : nodes) {
Package pkg = x.getPackage();
if (seenPackages.add(pkg)) {
if (buildFiles) {
addIfUniqueLabel(pkg.getBuildFile(), seenLabels, dependentFiles);
}
List<Label> extensions = new ArrayList<>();
if (subincludes) {
extensions.addAll(pkg.getSubincludeLabels());
}
if (loads) {
extensions.addAll(pkg.getSkylarkFileDependencies());
}
for (Label subinclude : extensions) {
addIfUniqueLabel(getSubincludeTarget(subinclude, pkg), seenLabels, dependentFiles);
if (buildFiles) {
// Also add the BUILD file of the subinclude.
try {
addIfUniqueLabel(getSubincludeTarget(subinclude.getLocalTargetLabel("BUILD"), pkg), seenLabels, dependentFiles);
} catch (LabelSyntaxException e) {
throw new AssertionError("BUILD should always parse as a target name", e);
}
}
}
}
}
return dependentFiles;
}
use of com.google.devtools.build.lib.cmdline.LabelSyntaxException in project bazel by bazelbuild.
the class HeaderDiscovery method discoverInputsFromDotdFiles.
/**
* Returns a collection with additional input artifacts relevant to the action by reading the
* dynamically-discovered dependency information from the .d file after the action has run.
*
* <p>Artifacts are considered inputs but not "mandatory" inputs.
*
* @throws ActionExecutionException iff the .d is missing (when required), malformed, or has
* unresolvable included artifacts.
*/
@VisibleForTesting
@ThreadCompatible
public NestedSet<Artifact> discoverInputsFromDotdFiles(Path execRoot, ArtifactResolver artifactResolver) throws ActionExecutionException {
NestedSetBuilder<Artifact> inputs = NestedSetBuilder.stableOrder();
if (dotdFile == null) {
return inputs.build();
}
List<Path> systemIncludePrefixes = permittedSystemIncludePrefixes;
// Check inclusions.
IncludeProblems problems = new IncludeProblems();
for (Path execPath : depSet.getDependencies()) {
PathFragment execPathFragment = execPath.asFragment();
if (execPathFragment.isAbsolute()) {
// Absolute includes from system paths are ignored.
if (FileSystemUtils.startsWithAny(execPath, systemIncludePrefixes)) {
continue;
}
// the build with an error.
if (execPath.startsWith(execRoot)) {
// funky but tolerable path
execPathFragment = execPath.relativeTo(execRoot);
} else {
problems.add(execPathFragment.getPathString());
continue;
}
}
Artifact artifact = allowedDerivedInputsMap.get(execPathFragment);
if (artifact == null) {
try {
RepositoryName repository = PackageIdentifier.discoverFromExecPath(execPathFragment, false).getRepository();
artifact = artifactResolver.resolveSourceArtifact(execPathFragment, repository);
} catch (LabelSyntaxException e) {
throw new ActionExecutionException(String.format("Could not find the external repository for %s", execPathFragment), e, action, false);
}
}
if (artifact != null) {
inputs.add(artifact);
// to the set of actual inputs.
if (specialInputsHandler != null) {
inputs.addAll(specialInputsHandler.getInputsForIncludedFile(artifact, artifactResolver));
}
} else {
// Abort if we see files that we can't resolve, likely caused by
// undeclared includes or illegal include constructs.
problems.add(execPathFragment.getPathString());
}
}
if (shouldValidateInclusions) {
problems.assertProblemFree(action, sourceFile);
}
return inputs.build();
}
use of com.google.devtools.build.lib.cmdline.LabelSyntaxException 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.cmdline.LabelSyntaxException in project bazel by bazelbuild.
the class JavaOptions method getTranslationLabels.
private Set<Label> getTranslationLabels() {
Set<Label> result = new LinkedHashSet<>();
for (String s : translationTargets) {
try {
Label label = Label.parseAbsolute(s);
result.add(label);
} catch (LabelSyntaxException e) {
// We ignore this exception here - it will cause an error message at a later time.
}
}
return result;
}
use of com.google.devtools.build.lib.cmdline.LabelSyntaxException in project bazel by bazelbuild.
the class LocalRepositoryLookupFunction method maybeCheckWorkspaceForRepository.
/**
* Checks whether the directory exists and is a workspace root. Returns {@link Optional#absent()}
* if Skyframe needs to re-run, {@link Optional#of(LocalRepositoryLookupValue)} otherwise.
*/
private Optional<LocalRepositoryLookupValue> maybeCheckWorkspaceForRepository(Environment env, final RootedPath directory) throws InterruptedException, LocalRepositoryLookupFunctionException {
// Look up the main WORKSPACE file by the external package, to find all repositories.
PackageLookupValue externalPackageLookupValue;
try {
externalPackageLookupValue = (PackageLookupValue) env.getValueOrThrow(PackageLookupValue.key(Label.EXTERNAL_PACKAGE_IDENTIFIER), BuildFileNotFoundException.class, InconsistentFilesystemException.class);
if (externalPackageLookupValue == null) {
return Optional.absent();
}
} catch (BuildFileNotFoundException e) {
throw new LocalRepositoryLookupFunctionException(new ErrorDeterminingRepositoryException("BuildFileNotFoundException while loading the //external package", e), Transience.PERSISTENT);
} catch (InconsistentFilesystemException e) {
throw new LocalRepositoryLookupFunctionException(new ErrorDeterminingRepositoryException("InconsistentFilesystemException while loading the //external package", e), Transience.PERSISTENT);
}
RootedPath workspacePath = externalPackageLookupValue.getRootedPath(Label.EXTERNAL_PACKAGE_IDENTIFIER);
SkyKey workspaceKey = WorkspaceFileValue.key(workspacePath);
do {
WorkspaceFileValue value;
try {
value = (WorkspaceFileValue) env.getValueOrThrow(workspaceKey, PackageFunctionException.class, NameConflictException.class);
if (value == null) {
return Optional.absent();
}
} catch (PackageFunctionException e) {
// TODO(jcater): When WFF is rewritten to not throw a PFE, update this.
throw new LocalRepositoryLookupFunctionException(new ErrorDeterminingRepositoryException("PackageFunctionException while loading the root WORKSPACE file", e), Transience.PERSISTENT);
} catch (NameConflictException e) {
throw new LocalRepositoryLookupFunctionException(new ErrorDeterminingRepositoryException("NameConflictException while loading the root WORKSPACE file", e), Transience.PERSISTENT);
}
Package externalPackage = value.getPackage();
if (externalPackage.containsErrors()) {
Event.replayEventsOn(env.getListener(), externalPackage.getEvents());
}
// Find all local_repository rules in the WORKSPACE, and check if any have a "path" attribute
// the same as the requested directory.
Iterable<Rule> localRepositories = externalPackage.getRulesMatchingRuleClass(LocalRepositoryRule.NAME);
Rule rule = Iterables.find(localRepositories, new Predicate<Rule>() {
@Override
public boolean apply(@Nullable Rule rule) {
AggregatingAttributeMapper mapper = AggregatingAttributeMapper.of(rule);
PathFragment pathAttr = new PathFragment(mapper.get("path", Type.STRING));
return directory.getRelativePath().equals(pathAttr);
}
}, null);
if (rule != null) {
try {
return Optional.of(LocalRepositoryLookupValue.success(RepositoryName.create("@" + rule.getName())));
} catch (LabelSyntaxException e) {
// validated.
throw new LocalRepositoryLookupFunctionException(new ErrorDeterminingRepositoryException("LabelSyntaxException while creating the repository name from the rule " + rule.getName(), e), Transience.PERSISTENT);
}
}
workspaceKey = value.next();
// TODO(bazel-team): This loop can be quadratic in the number of load() statements, consider
// rewriting or unrolling.
} while (workspaceKey != null);
return Optional.of(LocalRepositoryLookupValue.notFound());
}
Aggregations