Search in sources :

Example 16 with PathPackageLocator

use of com.google.devtools.build.lib.pkgcache.PathPackageLocator in project bazel by bazelbuild.

the class SkylarkFileContentHashTests method getHash.

/**
   * Returns the hash code of the rule target defined by the pkg and the target name parameters.
   * Asserts that the targets and it's Skylark dependencies were loaded properly.
   */
private String getHash(String pkg, String name) throws Exception {
    PackageCacheOptions packageCacheOptions = Options.getDefaults(PackageCacheOptions.class);
    packageCacheOptions.defaultVisibility = ConstantRuleVisibility.PUBLIC;
    packageCacheOptions.showLoadingProgress = true;
    packageCacheOptions.globbingThreads = 7;
    getSkyframeExecutor().preparePackageLoading(new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory)), packageCacheOptions, "", UUID.randomUUID(), ImmutableMap.<String, String>of(), ImmutableMap.<String, String>of(), new TimestampGranularityMonitor(BlazeClock.instance()));
    SkyKey pkgLookupKey = PackageValue.key(PackageIdentifier.parse("@//" + pkg));
    EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate(getSkyframeExecutor(), pkgLookupKey, /*keepGoing=*/
    false, reporter);
    assertFalse(result.hasError());
    Collection<Target> targets = result.get(pkgLookupKey).getPackage().getTargets();
    for (Target target : targets) {
        if (target.getName().equals(name)) {
            return ((Rule) target).getRuleClassObject().getRuleDefinitionEnvironment().getTransitiveContentHashCode();
        }
    }
    throw new IllegalStateException("target not found: " + name);
}
Also used : PathPackageLocator(com.google.devtools.build.lib.pkgcache.PathPackageLocator) SkyKey(com.google.devtools.build.skyframe.SkyKey) Target(com.google.devtools.build.lib.packages.Target) Rule(com.google.devtools.build.lib.packages.Rule) PackageCacheOptions(com.google.devtools.build.lib.pkgcache.PackageCacheOptions) TimestampGranularityMonitor(com.google.devtools.build.lib.util.io.TimestampGranularityMonitor)

Example 17 with PathPackageLocator

use of com.google.devtools.build.lib.pkgcache.PathPackageLocator in project bazel by bazelbuild.

the class SkylarkImportLookupFunctionTest method preparePackageLoading.

@Before
public final void preparePackageLoading() throws Exception {
    Path alternativeRoot = scratch.dir("/root_2");
    PackageCacheOptions packageCacheOptions = Options.getDefaults(PackageCacheOptions.class);
    packageCacheOptions.defaultVisibility = ConstantRuleVisibility.PUBLIC;
    packageCacheOptions.showLoadingProgress = true;
    packageCacheOptions.globbingThreads = 7;
    getSkyframeExecutor().preparePackageLoading(new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory, alternativeRoot)), packageCacheOptions, "", UUID.randomUUID(), ImmutableMap.<String, String>of(), ImmutableMap.<String, String>of(), new TimestampGranularityMonitor(BlazeClock.instance()));
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) PathPackageLocator(com.google.devtools.build.lib.pkgcache.PathPackageLocator) PackageCacheOptions(com.google.devtools.build.lib.pkgcache.PackageCacheOptions) TimestampGranularityMonitor(com.google.devtools.build.lib.util.io.TimestampGranularityMonitor) Before(org.junit.Before)

Example 18 with PathPackageLocator

use of com.google.devtools.build.lib.pkgcache.PathPackageLocator in project bazel by bazelbuild.

the class BlacklistedPackagePrefixesFunction method compute.

@Nullable
@Override
public SkyValue compute(SkyKey key, Environment env) throws SkyFunctionException, InterruptedException {
    PathPackageLocator pkgLocator = PrecomputedValue.PATH_PACKAGE_LOCATOR.get(env);
    PathFragment patternsFile = PrecomputedValue.BLACKLISTED_PACKAGE_PREFIXES_FILE.get(env);
    if (env.valuesMissing()) {
        return null;
    }
    if (patternsFile.equals(PathFragment.EMPTY_FRAGMENT)) {
        return new BlacklistedPackagePrefixesValue(ImmutableSet.<PathFragment>of());
    }
    for (Path packagePathEntry : pkgLocator.getPathEntries()) {
        RootedPath rootedPatternFile = RootedPath.toRootedPath(packagePathEntry, patternsFile);
        FileValue patternFileValue = (FileValue) env.getValue(FileValue.key(rootedPatternFile));
        if (patternFileValue == null) {
            return null;
        }
        if (patternFileValue.isFile()) {
            try {
                try (InputStreamReader reader = new InputStreamReader(rootedPatternFile.asPath().getInputStream(), StandardCharsets.UTF_8)) {
                    return new BlacklistedPackagePrefixesValue(CharStreams.readLines(reader, new PathFragmentLineProcessor()));
                }
            } catch (IOException e) {
                String errorMessage = e.getMessage() != null ? "error '" + e.getMessage() + "'" : "an error";
                throw new BlacklistedPatternsFunctionException(new InconsistentFilesystemException(rootedPatternFile.asPath() + " is not readable because: " + errorMessage + ". Was it modified mid-build?"));
            }
        }
    }
    return new BlacklistedPackagePrefixesValue(ImmutableSet.<PathFragment>of());
}
Also used : PathPackageLocator(com.google.devtools.build.lib.pkgcache.PathPackageLocator) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) InputStreamReader(java.io.InputStreamReader) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Nullable(javax.annotation.Nullable)

Example 19 with PathPackageLocator

use of com.google.devtools.build.lib.pkgcache.PathPackageLocator in project bazel by bazelbuild.

the class PackageLookupFunction method compute.

@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws PackageLookupFunctionException, InterruptedException {
    PathPackageLocator pkgLocator = PrecomputedValue.PATH_PACKAGE_LOCATOR.get(env);
    PackageIdentifier packageKey = (PackageIdentifier) skyKey.argument();
    if (PackageFunction.isDefaultsPackage(packageKey)) {
        return PackageLookupValue.success(pkgLocator.getPathEntries().get(0), BuildFileName.BUILD);
    }
    if (!packageKey.getRepository().isMain()) {
        return computeExternalPackageLookupValue(skyKey, env, packageKey);
    } else if (packageKey.equals(Label.EXTERNAL_PACKAGE_IDENTIFIER)) {
        return computeWorkspacePackageLookupValue(env, pkgLocator.getPathEntries());
    }
    String packageNameErrorMsg = LabelValidator.validatePackageName(packageKey.getPackageFragment().getPathString());
    if (packageNameErrorMsg != null) {
        return PackageLookupValue.invalidPackageName("Invalid package name '" + packageKey + "': " + packageNameErrorMsg);
    }
    if (deletedPackages.get().contains(packageKey)) {
        return PackageLookupValue.DELETED_PACKAGE_VALUE;
    }
    BlacklistedPackagePrefixesValue blacklistedPatternsValue = (BlacklistedPackagePrefixesValue) env.getValue(BlacklistedPackagePrefixesValue.key());
    if (blacklistedPatternsValue == null) {
        return null;
    }
    PathFragment buildFileFragment = packageKey.getPackageFragment();
    for (PathFragment pattern : blacklistedPatternsValue.getPatterns()) {
        if (buildFileFragment.startsWith(pattern)) {
            return PackageLookupValue.DELETED_PACKAGE_VALUE;
        }
    }
    return findPackageByBuildFile(env, pkgLocator, packageKey);
}
Also used : PathPackageLocator(com.google.devtools.build.lib.pkgcache.PathPackageLocator) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 20 with PathPackageLocator

use of com.google.devtools.build.lib.pkgcache.PathPackageLocator in project bazel by bazelbuild.

the class EnvironmentBackedRecursivePackageProvider method getPackagesUnderDirectory.

@Override
public Iterable<PathFragment> getPackagesUnderDirectory(ExtendedEventHandler eventHandler, RepositoryName repository, PathFragment directory, ImmutableSet<PathFragment> excludedSubdirectories) throws MissingDepException, InterruptedException {
    PathPackageLocator packageLocator = PrecomputedValue.PATH_PACKAGE_LOCATOR.get(env);
    if (packageLocator == null) {
        throw new MissingDepException();
    }
    List<Path> roots = new ArrayList<>();
    if (repository.isMain()) {
        roots.addAll(packageLocator.getPathEntries());
    } else {
        RepositoryDirectoryValue repositoryValue = (RepositoryDirectoryValue) env.getValue(RepositoryDirectoryValue.key(repository));
        if (repositoryValue == null) {
            throw new MissingDepException();
        }
        roots.add(repositoryValue.getPath());
    }
    NestedSetBuilder<String> packageNames = NestedSetBuilder.stableOrder();
    for (Path root : roots) {
        PathFragment.checkAllPathsAreUnder(excludedSubdirectories, directory);
        RecursivePkgValue lookup = (RecursivePkgValue) env.getValue(RecursivePkgValue.key(repository, RootedPath.toRootedPath(root, directory), excludedSubdirectories));
        if (lookup == null) {
            // the exception types it can accept.
            throw new MissingDepException();
        }
        packageNames.addTransitive(lookup.getPackages());
    }
    // unnecessary.
    return Iterables.transform(packageNames.build(), PathFragment.TO_PATH_FRAGMENT);
}
Also used : PathPackageLocator(com.google.devtools.build.lib.pkgcache.PathPackageLocator) RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) RepositoryDirectoryValue(com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue) ArrayList(java.util.ArrayList)

Aggregations

PathPackageLocator (com.google.devtools.build.lib.pkgcache.PathPackageLocator)32 Before (org.junit.Before)13 BlazeDirectories (com.google.devtools.build.lib.analysis.BlazeDirectories)12 TimestampGranularityMonitor (com.google.devtools.build.lib.util.io.TimestampGranularityMonitor)12 InMemoryMemoizingEvaluator (com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator)11 RecordingDifferencer (com.google.devtools.build.skyframe.RecordingDifferencer)11 SequentialBuildDriver (com.google.devtools.build.skyframe.SequentialBuildDriver)11 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 PackageCacheOptions (com.google.devtools.build.lib.pkgcache.PackageCacheOptions)9 SkyFunction (com.google.devtools.build.skyframe.SkyFunction)9 SkyFunctionName (com.google.devtools.build.skyframe.SkyFunctionName)9 Path (com.google.devtools.build.lib.vfs.Path)8 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)7 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)6 HashMap (java.util.HashMap)6 Test (org.junit.Test)5 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)4 PackageFactory (com.google.devtools.build.lib.packages.PackageFactory)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 AnalysisMock (com.google.devtools.build.lib.analysis.util.AnalysisMock)3