aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar John Field <jfield@google.com>2015-11-13 21:25:41 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-11-16 09:00:40 +0000
commit81e093e4bfc73b2b4e607ebf904781041d0da4a3 (patch)
tree99da549af98d19733ac6475e6f23cb4e27e122e3 /src
parent50230466ff83b9981cdd1826180b8a94bc413211 (diff)
Fix crash when two Skylark loads reference the same path.
-- MOS_MIGRATED_REVID=107808413
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java25
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunctionTest.java22
2 files changed, 35 insertions, 12 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java
index 603e8329b3..e60e0ec0cd 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java
@@ -318,30 +318,37 @@ public class SkylarkImportLookupFunction implements SkyFunction {
static ImmutableMap<PathFragment, Label> findLabelsForLoadStatements(
Iterable<LoadStatement> loadStmts, Label containingFileLabel, Environment env)
throws SkylarkImportFailedException {
- ImmutableSet.Builder<PathFragment> absolutePathsToLookup = new ImmutableSet.Builder<>();
-
ImmutableMap.Builder<PathFragment, Label> outputMap = new ImmutableMap.Builder<>();
+
+ // Filter relative vs. absolute paths.
+ ImmutableSet.Builder<PathFragment> absolutePathsToLookup = new ImmutableSet.Builder<>();
+ ImmutableSet.Builder<PathFragment> relativePathsToConvert = new ImmutableSet.Builder<>();
for (LoadStatement loadStmt : loadStmts) {
PathFragment importPath = loadStmt.getImportPath();
if (loadStmt.isAbsolute()) {
absolutePathsToLookup.add(importPath);
} else {
- // Relative paths don't require package lookups since they can only refer to files in the
- // same directory as the file containing the load statement; i.e., they can't refer to
- // subdirectories. We can therefore compute the corresponding label directly from the label
- // of the containing file (whose package has already been validated).
- outputMap.put(importPath, labelForRelativeImport(importPath, containingFileLabel));
+ relativePathsToConvert.add(importPath);
}
}
- // Compute labels for absolute paths
+ // Compute labels for absolute paths.
ImmutableMap<PathFragment, Label> absoluteLabels =
labelsForAbsoluteImports(absolutePathsToLookup.build(), env);
if (absoluteLabels == null) {
return null;
}
outputMap.putAll(absoluteLabels);
-
+
+ // Compute labels for relative paths.
+ for (PathFragment importPath : relativePathsToConvert.build()) {
+ // Relative paths don't require package lookups since they can only refer to files in the
+ // same directory as the file containing the load statement; i.e., they can't refer to
+ // subdirectories. We can therefore compute the corresponding label directly from the label
+ // of the containing file (whose package has already been validated).
+ outputMap.put(importPath, labelForRelativeImport(importPath, containingFileLabel));
+ }
+
return outputMap.build();
}
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunctionTest.java
index 6b60f076c9..546caf3088 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunctionTest.java
@@ -87,6 +87,21 @@ public class SkylarkImportLookupFunctionTest extends BuildViewTestCase {
get(key("//pkg3:ext.bzl"));
}
+ public void testLoadFromSameAbsolutePathTwice() throws Exception {
+ scratch.file("pkg1/BUILD");
+ scratch.file("pkg2/BUILD");
+ scratch.file("pkg1/ext.bzl", "a = 1", "b = 2");
+ scratch.file("pkg2/ext.bzl", "load('/pkg1/ext', 'a')", "load('/pkg1/ext', 'b')");
+ get(key("//pkg1:ext.bzl"));
+ }
+
+ public void testLoadFromSameRelativePathTwice() throws Exception {
+ scratch.file("pkg/BUILD");
+ scratch.file("pkg/ext1.bzl", "a = 1", "b = 2");
+ scratch.file("pkg/ext2.bzl", "load('ext1', 'a')", "load('ext1', 'b')");
+ get(key("//pkg:ext1.bzl"));
+ }
+
private EvaluationResult<SkylarkImportLookupValue> get(SkyKey skylarkImportLookupKey)
throws Exception {
EvaluationResult<SkylarkImportLookupValue> result =
@@ -102,10 +117,11 @@ public class SkylarkImportLookupFunctionTest extends BuildViewTestCase {
return SkylarkImportLookupValue.key(Label.parseAbsoluteUnchecked(label));
}
- private void checkLabel(String file, String label) throws Exception {
- SkyKey skylarkImportLookupKey = key(file);
+ private void checkLabel(String labelRequested, String labelFound) throws Exception {
+ SkyKey skylarkImportLookupKey = key(labelRequested);
EvaluationResult<SkylarkImportLookupValue> result = get(skylarkImportLookupKey);
- assertEquals(label, result.get(skylarkImportLookupKey).getDependency().getLabel().toString());
+ assertEquals(labelFound,
+ result.get(skylarkImportLookupKey).getDependency().getLabel().toString());
}
public void testSkylarkImportLookupNoBuildFile() throws Exception {