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);
}
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()));
}
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());
}
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);
}
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);
}
Aggregations