diff options
author | John Field <jfield@google.com> | 2015-11-13 21:25:41 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2015-11-16 09:00:40 +0000 |
commit | 81e093e4bfc73b2b4e607ebf904781041d0da4a3 (patch) | |
tree | 99da549af98d19733ac6475e6f23cb4e27e122e3 /src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java | |
parent | 50230466ff83b9981cdd1826180b8a94bc413211 (diff) |
Fix crash when two Skylark loads reference the same path.
--
MOS_MIGRATED_REVID=107808413
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java | 25 |
1 files changed, 16 insertions, 9 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(); } |