use of com.google.devtools.build.lib.packages.NoSuchPackageException in project bazel by bazelbuild.
the class TargetMarkerFunction method computeTargetMarkerValue.
@Nullable
static TargetMarkerValue computeTargetMarkerValue(SkyKey key, Environment env) throws NoSuchTargetException, NoSuchPackageException, InterruptedException {
Label label = (Label) key.argument();
PathFragment pkgForLabel = label.getPackageFragment();
if (label.getName().contains("/")) {
// This target is in a subdirectory, therefore it could potentially be invalidated by
// a new BUILD file appearing in the hierarchy.
PathFragment containingDirectory = label.toPathFragment().getParentDirectory();
ContainingPackageLookupValue containingPackageLookupValue;
try {
PackageIdentifier newPkgId = PackageIdentifier.create(label.getPackageIdentifier().getRepository(), containingDirectory);
containingPackageLookupValue = (ContainingPackageLookupValue) env.getValueOrThrow(ContainingPackageLookupValue.key(newPkgId), BuildFileNotFoundException.class, InconsistentFilesystemException.class);
} catch (InconsistentFilesystemException e) {
throw new NoSuchTargetException(label, e.getMessage());
}
if (containingPackageLookupValue == null) {
return null;
}
if (!containingPackageLookupValue.hasContainingPackage()) {
// trying to build the target for label 'a:b/foo'.
throw new BuildFileNotFoundException(label.getPackageIdentifier(), "BUILD file not found on package path for '" + pkgForLabel.getPathString() + "'");
}
if (!containingPackageLookupValue.getContainingPackageName().equals(label.getPackageIdentifier())) {
throw new NoSuchTargetException(label, String.format("Label '%s' crosses boundary of subpackage '%s'", label, containingPackageLookupValue.getContainingPackageName()));
}
}
SkyKey pkgSkyKey = PackageValue.key(label.getPackageIdentifier());
PackageValue value = (PackageValue) env.getValueOrThrow(pkgSkyKey, NoSuchPackageException.class);
if (value == null) {
return null;
}
Package pkg = value.getPackage();
Target target = pkg.getTarget(label.getName());
if (pkg.containsErrors()) {
// if one of its targets was in error).
throw new NoSuchTargetException(target);
}
return TargetMarkerValue.TARGET_MARKER_INSTANCE;
}
use of com.google.devtools.build.lib.packages.NoSuchPackageException in project bazel by bazelbuild.
the class SkyframeDependencyResolver method getTarget.
@Nullable
@Override
protected Target getTarget(Target from, Label label, NestedSetBuilder<Label> rootCauses) throws InterruptedException {
SkyKey key = PackageValue.key(label.getPackageIdentifier());
PackageValue packageValue;
try {
packageValue = (PackageValue) env.getValueOrThrow(key, NoSuchPackageException.class);
} catch (NoSuchPackageException e) {
rootCauses.add(label);
missingEdgeHook(from, label, e);
return null;
}
if (packageValue == null) {
return null;
}
Package pkg = packageValue.getPackage();
try {
Target target = pkg.getTarget(label.getName());
if (pkg.containsErrors()) {
NoSuchTargetException e = new NoSuchTargetException(target);
missingEdgeHook(from, label, e);
if (target != null) {
rootCauses.add(label);
return target;
} else {
return null;
}
}
return target;
} catch (NoSuchTargetException e) {
rootCauses.add(label);
missingEdgeHook(from, label, e);
return null;
}
}
use of com.google.devtools.build.lib.packages.NoSuchPackageException in project bazel by bazelbuild.
the class WorkspaceFileFunction method compute.
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws WorkspaceFileFunctionException, InterruptedException {
WorkspaceFileKey key = (WorkspaceFileKey) skyKey.argument();
RootedPath workspaceRoot = key.getPath();
WorkspaceASTValue workspaceASTValue = (WorkspaceASTValue) env.getValue(WorkspaceASTValue.key(workspaceRoot));
if (workspaceASTValue == null) {
return null;
}
Path repoWorkspace = workspaceRoot.getRoot().getRelative(workspaceRoot.getRelativePath());
Package.Builder builder = packageFactory.newExternalPackageBuilder(repoWorkspace, ruleClassProvider.getRunfilesPrefix());
if (workspaceASTValue.getASTs().isEmpty()) {
return new WorkspaceFileValue(// resulting package
builder.build(), // list of imports
ImmutableMap.<String, Extension>of(), // list of symbol bindings
ImmutableMap.<String, Object>of(), // Workspace root
workspaceRoot, // first fragment, idx = 0
0, // last fragment
false);
}
WorkspaceFactory parser;
try (Mutability mutability = Mutability.create("workspace %s", repoWorkspace)) {
parser = new WorkspaceFactory(builder, ruleClassProvider, packageFactory.getEnvironmentExtensions(), mutability, key.getIndex() == 0, directories.getEmbeddedBinariesRoot(), directories.getWorkspace());
if (key.getIndex() > 0) {
WorkspaceFileValue prevValue = (WorkspaceFileValue) env.getValue(WorkspaceFileValue.key(key.getPath(), key.getIndex() - 1));
if (prevValue == null) {
return null;
}
if (prevValue.next() == null) {
return prevValue;
}
parser.setParent(prevValue.getPackage(), prevValue.getImportMap(), prevValue.getBindings());
}
BuildFileAST ast = workspaceASTValue.getASTs().get(key.getIndex());
PackageFunction.SkylarkImportResult importResult = PackageFunction.fetchImportsFromBuildFile(repoWorkspace, rootPackage, ast, env, null);
if (importResult == null) {
return null;
}
parser.execute(ast, importResult.importMap);
} catch (NoSuchPackageException e) {
throw new WorkspaceFileFunctionException(e, Transience.PERSISTENT);
} catch (NameConflictException e) {
throw new WorkspaceFileFunctionException(e, Transience.PERSISTENT);
}
return new WorkspaceFileValue(builder.build(), parser.getImportMap(), parser.getVariableBindings(), workspaceRoot, key.getIndex(), key.getIndex() < workspaceASTValue.getASTs().size() - 1);
}
use of com.google.devtools.build.lib.packages.NoSuchPackageException in project bazel by bazelbuild.
the class SkyframePackageLoaderWithValueEnvironment method getPackage.
private Package getPackage(final PackageIdentifier pkgIdentifier) throws NoSuchPackageException, InterruptedException {
SkyKey key = PackageValue.key(pkgIdentifier);
PackageValue value = (PackageValue) env.getValueOrThrow(key, NoSuchPackageException.class);
if (value != null) {
return value.getPackage();
}
return null;
}
use of com.google.devtools.build.lib.packages.NoSuchPackageException in project bazel by bazelbuild.
the class TransitiveTargetFunction method processDeps.
@Override
void processDeps(TransitiveTargetValueBuilder builder, EventHandler eventHandler, TargetAndErrorIfAny targetAndErrorIfAny, Iterable<Entry<SkyKey, ValueOrException2<NoSuchPackageException, NoSuchTargetException>>> depEntries) throws InterruptedException {
boolean successfulTransitiveLoading = builder.isSuccessfulTransitiveLoading();
Target target = targetAndErrorIfAny.getTarget();
NestedSetBuilder<Label> transitiveRootCauses = builder.getTransitiveRootCauses();
for (Entry<SkyKey, ValueOrException2<NoSuchPackageException, NoSuchTargetException>> entry : depEntries) {
Label depLabel = (Label) entry.getKey().argument();
TransitiveTargetValue transitiveTargetValue;
try {
transitiveTargetValue = (TransitiveTargetValue) entry.getValue().get();
if (transitiveTargetValue == null) {
continue;
}
} catch (NoSuchPackageException | NoSuchTargetException e) {
successfulTransitiveLoading = false;
transitiveRootCauses.add(depLabel);
maybeReportErrorAboutMissingEdge(target, depLabel, e, eventHandler);
continue;
}
builder.getTransitiveSuccessfulPkgs().addTransitive(transitiveTargetValue.getTransitiveSuccessfulPackages());
builder.getTransitiveUnsuccessfulPkgs().addTransitive(transitiveTargetValue.getTransitiveUnsuccessfulPackages());
builder.getTransitiveTargets().addTransitive(transitiveTargetValue.getTransitiveTargets());
NestedSet<Label> rootCauses = transitiveTargetValue.getTransitiveRootCauses();
if (rootCauses != null) {
successfulTransitiveLoading = false;
transitiveRootCauses.addTransitive(rootCauses);
if (transitiveTargetValue.getErrorLoadingTarget() != null) {
maybeReportErrorAboutMissingEdge(target, depLabel, transitiveTargetValue.getErrorLoadingTarget(), eventHandler);
}
}
NestedSet<Class<? extends Fragment>> depFragments = transitiveTargetValue.getTransitiveConfigFragments();
Collection<Class<? extends Fragment>> depFragmentsAsCollection = depFragments.toCollection();
// The simplest collection technique would be to unconditionally add all deps' nested
// sets to the current target's nested set. But when there's large overlap between their
// fragment needs, this produces unnecessarily bloated nested sets and a lot of references
// that don't contribute anything unique to the required fragment set. So we optimize here
// by completely skipping sets that don't offer anything new. More fine-tuned optimization
// is possible, but this offers a good balance between simplicity and practical efficiency.
Set<Class<? extends Fragment>> addedConfigFragments = builder.getConfigFragmentsFromDeps();
if (!addedConfigFragments.containsAll(depFragmentsAsCollection)) {
builder.getTransitiveConfigFragments().addTransitive(depFragments);
addedConfigFragments.addAll(depFragmentsAsCollection);
}
}
builder.setSuccessfulTransitiveLoading(successfulTransitiveLoading);
}
Aggregations