aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
diff options
context:
space:
mode:
authorGravatar Lukacs Berki <lberki@google.com>2015-08-27 14:20:57 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2015-08-27 14:45:40 +0000
commit145b701977726094f8ae44f6532b9fb3e2057e5e (patch)
treed51a60ee98e72e1f577552a59bbab7ebf248e903 /src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
parent2ccd056fd911f821520c97dc8d064a42672a6056 (diff)
Make load() work in remote repositories too.
Previously, load() always looked up .bzl files in the main repository. Ideally, it would just take a label and then it would work by default, but for the time being, this quick fix will do. I had to put in an evil hack to make load() statements work in the prelude, because we currently have no way to distinguish load() statements from the prelude and from the BUILD file. Again, a proper label-based load() would solve this. -- MOS_MIGRATED_REVID=101677502
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
index fbf3870f09..6d51828a93 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
@@ -14,7 +14,9 @@
package com.google.devtools.build.lib.skyframe;
+import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.packages.CachingPackageLocator;
+import com.google.devtools.build.lib.packages.PackageIdentifier;
import com.google.devtools.build.lib.packages.RuleClassProvider;
import com.google.devtools.build.lib.pkgcache.PathPackageLocator;
import com.google.devtools.build.lib.syntax.BuildFileAST;
@@ -28,6 +30,7 @@ import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
import java.io.IOException;
+import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Nullable;
@@ -84,7 +87,7 @@ public class ASTFileLookupFunction implements SkyFunction {
@Override
public RootedPath rootedPath() {
- throw new IllegalStateException("unsucessful lookup");
+ throw new IllegalStateException("unsuccessful lookup");
}
}
}
@@ -104,8 +107,9 @@ public class ASTFileLookupFunction implements SkyFunction {
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException,
InterruptedException {
- PathFragment astFilePathFragment = (PathFragment) skyKey.argument();
- FileLookupResult lookupResult = getASTFile(env, astFilePathFragment);
+ PackageIdentifier key = (PackageIdentifier) skyKey.argument();
+ PathFragment astFilePathFragment = key.getPackageFragment();
+ FileLookupResult lookupResult = getASTFile(env, key);
if (lookupResult == null) {
return null;
}
@@ -132,15 +136,27 @@ public class ASTFileLookupFunction implements SkyFunction {
return ASTFileLookupValue.withFile(ast);
}
- private FileLookupResult getASTFile(Environment env, PathFragment astFilePathFragment)
+ private FileLookupResult getASTFile(Environment env, PackageIdentifier key)
throws ASTLookupFunctionException {
- for (Path packagePathEntry : pkgLocator.get().getPathEntries()) {
- RootedPath rootedPath = RootedPath.toRootedPath(packagePathEntry, astFilePathFragment);
- SkyKey fileSkyKey = FileValue.key(rootedPath);
- FileValue fileValue = null;
+ List<Path> candidateRoots;
+ if (!key.getRepository().isDefault()) {
+ RepositoryValue repository =
+ (RepositoryValue) env.getValue(RepositoryValue.key(key.getRepository()));
+ if (repository == null) {
+ return null;
+ }
+
+ candidateRoots = ImmutableList.of(repository.getPath());
+ } else {
+ candidateRoots = pkgLocator.get().getPathEntries();
+ }
+
+ for (Path root : candidateRoots) {
+ RootedPath rootedPath = RootedPath.toRootedPath(root, key.getPackageFragment());
+ FileValue fileValue;
try {
- fileValue = (FileValue) env.getValueOrThrow(fileSkyKey, IOException.class,
- FileSymlinkException.class, InconsistentFilesystemException.class);
+ fileValue = (FileValue) env.getValueOrThrow(FileValue.key(rootedPath),
+ IOException.class, FileSymlinkException.class, InconsistentFilesystemException.class);
} catch (IOException | FileSymlinkException e) {
throw new ASTLookupFunctionException(new ErrorReadingSkylarkExtensionException(
e.getMessage()), Transience.PERSISTENT);