Search in sources :

Example 26 with RootedPath

use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.

the class GraphBackedRecursivePackageProvider method collectPackagesUnder.

private void collectPackagesUnder(ExtendedEventHandler eventHandler, final RepositoryName repository, Set<TraversalInfo> traversals, ImmutableList.Builder<PathFragment> builder) throws InterruptedException {
    Map<TraversalInfo, SkyKey> traversalToKeyMap = Maps.asMap(traversals, new Function<TraversalInfo, SkyKey>() {

        @Override
        public SkyKey apply(TraversalInfo traversalInfo) {
            return CollectPackagesUnderDirectoryValue.key(repository, traversalInfo.rootedDir, traversalInfo.excludedSubdirectories);
        }
    });
    Map<SkyKey, SkyValue> values = graph.getSuccessfulValues(traversalToKeyMap.values());
    ImmutableSet.Builder<TraversalInfo> subdirTraversalBuilder = ImmutableSet.builder();
    for (Map.Entry<TraversalInfo, SkyKey> entry : traversalToKeyMap.entrySet()) {
        TraversalInfo info = entry.getKey();
        SkyKey key = entry.getValue();
        SkyValue val = values.get(key);
        CollectPackagesUnderDirectoryValue collectPackagesValue = (CollectPackagesUnderDirectoryValue) val;
        if (collectPackagesValue != null) {
            if (collectPackagesValue.isDirectoryPackage()) {
                builder.add(info.rootedDir.getRelativePath());
            }
            if (collectPackagesValue.getErrorMessage() != null) {
                eventHandler.handle(Event.error(collectPackagesValue.getErrorMessage()));
            }
            ImmutableMap<RootedPath, Boolean> subdirectoryTransitivelyContainsPackages = collectPackagesValue.getSubdirectoryTransitivelyContainsPackagesOrErrors();
            for (RootedPath subdirectory : subdirectoryTransitivelyContainsPackages.keySet()) {
                if (subdirectoryTransitivelyContainsPackages.get(subdirectory)) {
                    PathFragment subdirectoryRelativePath = subdirectory.getRelativePath();
                    ImmutableSet<PathFragment> excludedSubdirectoriesBeneathThisSubdirectory = PathFragment.filterPathsStartingWith(info.excludedSubdirectories, subdirectoryRelativePath);
                    subdirTraversalBuilder.add(new TraversalInfo(subdirectory, excludedSubdirectoriesBeneathThisSubdirectory));
                }
            }
        }
    }
    ImmutableSet<TraversalInfo> subdirTraversals = subdirTraversalBuilder.build();
    if (!subdirTraversals.isEmpty()) {
        collectPackagesUnder(eventHandler, repository, subdirTraversals, builder);
    }
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) SkyValue(com.google.devtools.build.skyframe.SkyValue) ImmutableSet(com.google.common.collect.ImmutableSet) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 27 with RootedPath

use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.

the class GraphBackedRecursivePackageProvider method getPackagesUnderDirectory.

@Override
public Iterable<PathFragment> getPackagesUnderDirectory(ExtendedEventHandler eventHandler, RepositoryName repository, PathFragment directory, ImmutableSet<PathFragment> excludedSubdirectories) throws InterruptedException {
    PathFragment.checkAllPathsAreUnder(excludedSubdirectories, directory);
    // Check that this package is covered by at least one of our universe patterns.
    boolean inUniverse = false;
    for (TargetPatternKey patternKey : universeTargetPatternKeys) {
        TargetPattern pattern = patternKey.getParsedPattern();
        boolean isTBD = pattern.getType().equals(Type.TARGETS_BELOW_DIRECTORY);
        PackageIdentifier packageIdentifier = PackageIdentifier.create(repository, directory);
        if (isTBD && pattern.containsAllTransitiveSubdirectoriesForTBD(packageIdentifier)) {
            inUniverse = true;
            break;
        }
    }
    if (!inUniverse) {
        return ImmutableList.of();
    }
    List<Path> roots = new ArrayList<>();
    if (repository.isMain()) {
        roots.addAll(pkgPath.getPathEntries());
    } else {
        RepositoryDirectoryValue repositoryValue = (RepositoryDirectoryValue) graph.getValue(RepositoryDirectoryValue.key(repository));
        if (repositoryValue == null) {
            // "nothing".
            return ImmutableList.of();
        }
        roots.add(repositoryValue.getPath());
    }
    // If we found a TargetsBelowDirectory pattern in the universe that contains this directory,
    // then we can look for packages in and under it in the graph. If we didn't find one, then the
    // directory wasn't in the universe, so return an empty list.
    ImmutableList.Builder<PathFragment> builder = ImmutableList.builder();
    for (Path root : roots) {
        RootedPath rootedDir = RootedPath.toRootedPath(root, directory);
        TraversalInfo info = new TraversalInfo(rootedDir, excludedSubdirectories);
        collectPackagesUnder(eventHandler, repository, ImmutableSet.of(info), builder);
    }
    return builder.build();
}
Also used : RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) TargetPatternKey(com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternKey) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) TargetPattern(com.google.devtools.build.lib.cmdline.TargetPattern) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) RepositoryDirectoryValue(com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue)

Example 28 with RootedPath

use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.

the class LocalRepositoryLookupFunction method compute.

// Implementation note: Although LocalRepositoryLookupValue.NOT_FOUND exists, it should never be
// returned from this method.
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException, InterruptedException {
    RootedPath directory = (RootedPath) skyKey.argument();
    // before this can be called if that is incorrect.
    if (directory.getRelativePath().equals(PathFragment.EMPTY_FRAGMENT)) {
        return LocalRepositoryLookupValue.mainRepository();
    }
    // Does this directory contain a WORKSPACE file?
    Optional<Boolean> maybeWorkspaceFileExists = maybeGetWorkspaceFileExistence(env, directory);
    if (!maybeWorkspaceFileExists.isPresent()) {
        return null;
    } else if (maybeWorkspaceFileExists.get()) {
        Optional<LocalRepositoryLookupValue> maybeRepository = maybeCheckWorkspaceForRepository(env, directory);
        if (!maybeRepository.isPresent()) {
            return null;
        }
        LocalRepositoryLookupValue repository = maybeRepository.get();
        // If the repository that was discovered doesn't exist, continue recursing.
        if (repository.exists()) {
            return repository;
        }
    }
    // If we haven't found a repository yet, check the parent directory.
    RootedPath parentDirectory = RootedPath.toRootedPath(directory.getRoot(), directory.getRelativePath().getParentDirectory());
    return env.getValue(LocalRepositoryLookupValue.key(parentDirectory));
}
Also used : Optional(com.google.common.base.Optional) RootedPath(com.google.devtools.build.lib.vfs.RootedPath)

Example 29 with RootedPath

use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.

the class PrepareDepsOfTargetsUnderDirectoryFunction method compute.

@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
    PrepareDepsOfTargetsUnderDirectoryKey argument = (PrepareDepsOfTargetsUnderDirectoryKey) skyKey.argument();
    final FilteringPolicy filteringPolicy = argument.getFilteringPolicy();
    RecursivePkgKey recursivePkgKey = argument.getRecursivePkgKey();
    ProcessPackageDirectory processPackageDirectory = new ProcessPackageDirectory(directories, new ProcessPackageDirectory.SkyKeyTransformer() {

        @Override
        public SkyKey makeSkyKey(RepositoryName repository, RootedPath subdirectory, ImmutableSet<PathFragment> excludedSubdirectoriesBeneathSubdirectory) {
            return PrepareDepsOfTargetsUnderDirectoryValue.key(repository, subdirectory, excludedSubdirectoriesBeneathSubdirectory, filteringPolicy);
        }
    });
    ProcessPackageDirectoryResult packageExistenceAndSubdirDeps = processPackageDirectory.getPackageExistenceAndSubdirDeps(recursivePkgKey.getRootedPath(), recursivePkgKey.getRepository(), env, recursivePkgKey.getExcludedPaths());
    if (env.valuesMissing()) {
        return null;
    }
    Iterable<SkyKey> keysToRequest = packageExistenceAndSubdirDeps.getChildDeps();
    if (packageExistenceAndSubdirDeps.packageExists()) {
        keysToRequest = Iterables.concat(ImmutableList.of(CollectTargetsInPackageValue.key(PackageIdentifier.create(recursivePkgKey.getRepository(), recursivePkgKey.getRootedPath().getRelativePath()), filteringPolicy)), keysToRequest);
    }
    env.getValuesOrThrow(keysToRequest, NoSuchPackageException.class);
    if (env.valuesMissing()) {
        return null;
    }
    return PrepareDepsOfTargetsUnderDirectoryValue.INSTANCE;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) RecursivePkgKey(com.google.devtools.build.lib.skyframe.RecursivePkgValue.RecursivePkgKey) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RepositoryName(com.google.devtools.build.lib.cmdline.RepositoryName) PrepareDepsOfTargetsUnderDirectoryKey(com.google.devtools.build.lib.skyframe.PrepareDepsOfTargetsUnderDirectoryValue.PrepareDepsOfTargetsUnderDirectoryKey) FilteringPolicy(com.google.devtools.build.lib.pkgcache.FilteringPolicy) RootedPath(com.google.devtools.build.lib.vfs.RootedPath)

Example 30 with RootedPath

use of com.google.devtools.build.lib.vfs.RootedPath in project bazel by bazelbuild.

the class SkyframeIncrementalBuildMonitor method accrue.

public void accrue(Iterable<SkyKey> invalidatedValues) {
    for (SkyKey skyKey : invalidatedValues) {
        if (skyKey.functionName().equals(SkyFunctions.FILE_STATE)) {
            RootedPath file = (RootedPath) skyKey.argument();
            maybeAddFile(file.getRelativePath());
        }
    }
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) RootedPath(com.google.devtools.build.lib.vfs.RootedPath)

Aggregations

RootedPath (com.google.devtools.build.lib.vfs.RootedPath)84 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)43 SkyKey (com.google.devtools.build.skyframe.SkyKey)41 Test (org.junit.Test)33 Path (com.google.devtools.build.lib.vfs.Path)28 Artifact (com.google.devtools.build.lib.actions.Artifact)21 IOException (java.io.IOException)15 Package (com.google.devtools.build.lib.packages.Package)13 SkyValue (com.google.devtools.build.skyframe.SkyValue)11 TraversalRequest (com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.TraversalRequest)9 ResolvedFile (com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.ResolvedFile)8 FilesetTraversalParams (com.google.devtools.build.lib.actions.FilesetTraversalParams)7 EvalException (com.google.devtools.build.lib.syntax.EvalException)7 ErrorInfo (com.google.devtools.build.skyframe.ErrorInfo)7 Dirent (com.google.devtools.build.lib.vfs.Dirent)6 LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)5 BuildFileNotFoundException (com.google.devtools.build.lib.packages.BuildFileNotFoundException)5 NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)5 FileValue (com.google.devtools.build.lib.skyframe.FileValue)5 Map (java.util.Map)5