use of com.google.devtools.build.lib.packages.Package in project bazel by bazelbuild.
the class BlazeQueryEnvironment method getBuildFiles.
// TODO(bazel-team): rename this to getDependentFiles when all implementations
// of QueryEnvironment is fixed.
@Override
public Set<Target> getBuildFiles(final 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(getNode(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);
// Also add the BUILD file of the subinclude.
if (buildFiles) {
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.packages.Package in project bazel by bazelbuild.
the class SkyQueryEnvironment method bulkGetPackages.
@ThreadSafe
public Map<PackageIdentifier, Package> bulkGetPackages(Iterable<PackageIdentifier> pkgIds) throws InterruptedException {
Set<SkyKey> pkgKeys = ImmutableSet.copyOf(PackageValue.keys(pkgIds));
ImmutableMap.Builder<PackageIdentifier, Package> pkgResults = ImmutableMap.builder();
Map<SkyKey, SkyValue> packages = graph.getSuccessfulValues(pkgKeys);
for (Map.Entry<SkyKey, SkyValue> pkgEntry : packages.entrySet()) {
PackageIdentifier pkgId = (PackageIdentifier) pkgEntry.getKey().argument();
PackageValue pkgValue = (PackageValue) pkgEntry.getValue();
pkgResults.put(pkgId, Preconditions.checkNotNull(pkgValue.getPackage(), pkgId));
}
return pkgResults.build();
}
use of com.google.devtools.build.lib.packages.Package in project bazel by bazelbuild.
the class TransitiveBaseTraversalFunction method loadTarget.
private LoadTargetResults loadTarget(Environment env, Label label) throws NoSuchTargetException, NoSuchPackageException, InterruptedException {
SkyKey packageKey = PackageValue.key(label.getPackageIdentifier());
SkyKey targetKey = TargetMarkerValue.key(label);
boolean packageLoadedSuccessfully;
Target target;
NoSuchTargetException errorLoadingTarget = null;
try {
TargetMarkerValue targetValue = getTargetMarkerValue(targetKey, env);
boolean targetValueMissing = targetValue == null;
Preconditions.checkState(targetValueMissing == env.valuesMissing(), targetKey);
if (targetValueMissing) {
return ValuesMissing.INSTANCE;
}
PackageValue packageValue = (PackageValue) env.getValueOrThrow(packageKey, NoSuchPackageException.class);
if (packageValue == null) {
return ValuesMissing.INSTANCE;
}
Package pkg = packageValue.getPackage();
if (pkg.containsErrors()) {
throw new BuildFileContainsErrorsException(label.getPackageIdentifier());
}
packageLoadedSuccessfully = true;
try {
target = pkg.getTarget(label.getName());
} catch (NoSuchTargetException unexpected) {
// was not present.
throw new IllegalStateException(unexpected);
}
} catch (NoSuchTargetException e) {
if (!e.hasTarget()) {
throw e;
}
// We know that a Target may be extracted, but we need to get it out of the Package
// (which is known to be in error).
PackageValue packageValue = (PackageValue) Preconditions.checkNotNull(env.getValue(packageKey), label);
Package pkg = packageValue.getPackage();
try {
target = pkg.getTarget(label.getName());
} catch (NoSuchTargetException nste) {
throw new IllegalStateException("Expected target to exist", nste);
}
errorLoadingTarget = e;
packageLoadedSuccessfully = false;
}
return new TargetAndErrorIfAnyImpl(packageLoadedSuccessfully, errorLoadingTarget, target);
}
use of com.google.devtools.build.lib.packages.Package in project bazel by bazelbuild.
the class TransitiveTargetFunction method getAspectLabels.
@Override
protected Collection<Label> getAspectLabels(Rule fromRule, Attribute attr, Label toLabel, ValueOrException2<NoSuchPackageException, NoSuchTargetException> toVal, final Environment env) throws InterruptedException {
SkyKey packageKey = PackageValue.key(toLabel.getPackageIdentifier());
try {
PackageValue pkgValue = (PackageValue) env.getValueOrThrow(packageKey, NoSuchPackageException.class);
if (pkgValue == null) {
return ImmutableList.of();
}
Package pkg = pkgValue.getPackage();
if (pkg.containsErrors()) {
// TransitiveTargetValue.
return ImmutableList.of();
}
Target dependedTarget = pkgValue.getPackage().getTarget(toLabel.getName());
return AspectDefinition.visitAspectsIfRequired(fromRule, attr, dependedTarget, DependencyFilter.ALL_DEPS).values();
} catch (NoSuchThingException e) {
// TransitiveTargetValue.
return ImmutableList.of();
}
}
use of com.google.devtools.build.lib.packages.Package in project bazel by bazelbuild.
the class WorkspaceNameFunction method compute.
@Override
@Nullable
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
SkyKey externalPackageKey = PackageValue.key(Label.EXTERNAL_PACKAGE_IDENTIFIER);
PackageValue externalPackageValue = (PackageValue) env.getValue(externalPackageKey);
if (externalPackageValue == null) {
return null;
}
Package externalPackage = externalPackageValue.getPackage();
return externalPackage.containsErrors() ? WorkspaceNameValue.withError() : WorkspaceNameValue.withName(externalPackage.getWorkspaceName());
}
Aggregations