Search in sources :

Example 11 with NoSuchPackageException

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;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) BuildFileNotFoundException(com.google.devtools.build.lib.packages.BuildFileNotFoundException) Target(com.google.devtools.build.lib.packages.Target) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) Label(com.google.devtools.build.lib.cmdline.Label) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Package(com.google.devtools.build.lib.packages.Package) Nullable(javax.annotation.Nullable)

Example 12 with NoSuchPackageException

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;
    }
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) Target(com.google.devtools.build.lib.packages.Target) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) Package(com.google.devtools.build.lib.packages.Package) Nullable(javax.annotation.Nullable)

Example 13 with NoSuchPackageException

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);
}
Also used : RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) WorkspaceFactory(com.google.devtools.build.lib.packages.WorkspaceFactory) Mutability(com.google.devtools.build.lib.syntax.Mutability) NameConflictException(com.google.devtools.build.lib.packages.Package.NameConflictException) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) WorkspaceFileKey(com.google.devtools.build.lib.skyframe.WorkspaceFileValue.WorkspaceFileKey) Package(com.google.devtools.build.lib.packages.Package) BuildFileAST(com.google.devtools.build.lib.syntax.BuildFileAST)

Example 14 with NoSuchPackageException

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;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException)

Example 15 with NoSuchPackageException

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);
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) Label(com.google.devtools.build.lib.cmdline.Label) ValueOrException2(com.google.devtools.build.skyframe.ValueOrException2) Fragment(com.google.devtools.build.lib.analysis.config.BuildConfiguration.Fragment) Target(com.google.devtools.build.lib.packages.Target) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException)

Aggregations

NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)27 SkyKey (com.google.devtools.build.skyframe.SkyKey)21 Package (com.google.devtools.build.lib.packages.Package)13 NoSuchTargetException (com.google.devtools.build.lib.packages.NoSuchTargetException)11 Label (com.google.devtools.build.lib.cmdline.Label)10 Target (com.google.devtools.build.lib.packages.Target)8 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)7 BuildFileContainsErrorsException (com.google.devtools.build.lib.packages.BuildFileContainsErrorsException)6 BuildFileNotFoundException (com.google.devtools.build.lib.packages.BuildFileNotFoundException)6 Nullable (javax.annotation.Nullable)6 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)5 IOException (java.io.IOException)5 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)4 SkyValue (com.google.devtools.build.skyframe.SkyValue)4 ValueOrException2 (com.google.devtools.build.skyframe.ValueOrException2)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Path (com.google.devtools.build.lib.vfs.Path)3 Map (java.util.Map)3 LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)2 Attribute (com.google.devtools.build.lib.packages.Attribute)2