Make Rule know about the name of the workspace it is in.
This is needed for taking the runfiles prefix from the WORKSPACE file instead of hardcoding it.
--
MOS_MIGRATED_REVID=87347883
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java
index b318f3e..1679810 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java
@@ -316,10 +316,10 @@
throws PackageFunctionException {
RootedPath workspacePath = RootedPath.toRootedPath(
packageLookupPath, new PathFragment("WORKSPACE"));
- SkyKey workspaceKey = WorkspaceFileValue.key(workspacePath);
- WorkspaceFileValue workspace = null;
+ SkyKey workspaceKey = PackageValue.workspaceKey(workspacePath);
+ PackageValue workspace = null;
try {
- workspace = (WorkspaceFileValue) env.getValueOrThrow(workspaceKey, IOException.class,
+ workspace = (PackageValue) env.getValueOrThrow(workspaceKey, IOException.class,
FileSymlinkCycleException.class, InconsistentFilesystemException.class,
EvalException.class);
} catch (IOException | FileSymlinkCycleException | InconsistentFilesystemException
@@ -385,6 +385,12 @@
if (packageName.equals(EXTERNAL_PACKAGE_NAME)) {
return getExternalPackage(env, packageLookupValue.getRoot());
}
+ PackageValue externalPackage = (PackageValue) env.getValue(
+ PackageValue.key(PackageIdentifier.createInDefaultRepo(EXTERNAL_PACKAGE_NAME)));
+ if (externalPackage == null) {
+ return null;
+ }
+ Package externalPkg = externalPackage.getPackage();
PathFragment buildFileFragment = packageNameFragment.getChild("BUILD");
RootedPath buildFileRootedPath = RootedPath.toRootedPath(packageLookupValue.getRoot(),
@@ -462,8 +468,9 @@
return null;
}
- Package.LegacyBuilder legacyPkgBuilder = loadPackage(inputSource, replacementContents,
- packageId, buildFilePath, defaultVisibility, preludeStatements, importResult);
+ Package.LegacyBuilder legacyPkgBuilder = loadPackage(externalPkg, inputSource,
+ replacementContents, packageId, buildFilePath, defaultVisibility, preludeStatements,
+ importResult);
legacyPkgBuilder.buildPartial();
try {
handleLabelsCrossingSubpackagesAndPropagateInconsistentFilesystemExceptions(
@@ -709,8 +716,8 @@
* Constructs a {@link Package} object for the given package using legacy package loading.
* Note that the returned package may be in error.
*/
- private Package.LegacyBuilder loadPackage(ParserInputSource inputSource,
- @Nullable String replacementContents,
+ private Package.LegacyBuilder loadPackage(Package externalPkg,
+ ParserInputSource inputSource, @Nullable String replacementContents,
PackageIdentifier packageId, Path buildFilePath, RuleVisibility defaultVisibility,
List<Statement> preludeStatements, SkylarkImportResult importResult)
throws InterruptedException {
@@ -729,8 +736,8 @@
? packageFactory.preprocess(packageId, buildFilePath, inputSource, globber,
localReporter)
: Preprocessor.Result.noPreprocessing(replacementSource);
- pkgBuilder = packageFactory.createPackageFromPreprocessingResult(packageId, buildFilePath,
- preprocessingResult, localReporter.getEvents(), preludeStatements,
+ pkgBuilder = packageFactory.createPackageFromPreprocessingResult(externalPkg, packageId,
+ buildFilePath, preprocessingResult, localReporter.getEvents(), preludeStatements,
importResult.importMap, importResult.fileDependencies, packageLocator,
defaultVisibility, globber);
if (eventBus.get() != null) {