diff options
author | Michajlo Matijkiw <michajlo@google.com> | 2015-09-22 02:22:12 +0000 |
---|---|---|
committer | Laszlo Csomor <laszlocsomor@google.com> | 2015-09-22 17:06:48 +0000 |
commit | 2a7c802823a0bc59d2cb010962e250ee145c620c (patch) | |
tree | f75a613a60e341c7eb0ecf6400cbb978b91456f8 /src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupValue.java | |
parent | f0a5ac60547751b34b3c307a6a4e47f8c791a720 (diff) |
Roll back using labels rather than PathFragments for skylark loads.
RELNOTES:
--
MOS_MIGRATED_REVID=103606693
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupValue.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupValue.java | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupValue.java index e9d050d300..0ac9fd4402 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupValue.java @@ -13,9 +13,14 @@ // limitations under the License. package com.google.devtools.build.lib.skyframe; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; -import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.cmdline.PackageIdentifier; +import com.google.devtools.build.lib.cmdline.PackageIdentifier.RepositoryName; +import com.google.devtools.build.lib.skyframe.ASTFileLookupValue.ASTLookupInputException; import com.google.devtools.build.lib.syntax.Environment.Extension; +import com.google.devtools.build.lib.syntax.LoadStatement; +import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.skyframe.SkyKey; import com.google.devtools.build.skyframe.SkyValue; @@ -53,7 +58,38 @@ public class SkylarkImportLookupValue implements SkyValue { return dependency; } - static SkyKey key(Label importLabel) { - return new SkyKey(SkyFunctions.SKYLARK_IMPORTS_LOOKUP, importLabel); + private static void checkInputArgument(PathFragment astFilePathFragment) + throws ASTLookupInputException { + if (astFilePathFragment.isAbsolute()) { + throw new ASTLookupInputException(String.format( + "Input file '%s' cannot be an absolute path.", astFilePathFragment)); + } + } + + @VisibleForTesting + static SkyKey key(PackageIdentifier pkgIdentifier) throws ASTLookupInputException { + return key(pkgIdentifier.getRepository(), pkgIdentifier.getPackageFragment()); + } + + static SkyKey key(RepositoryName repo, PathFragment fromFile, PathFragment fileToImport) + throws ASTLookupInputException { + PathFragment computedPath; + if (fileToImport.isAbsolute()) { + computedPath = fileToImport.toRelative(); + } else if (fileToImport.segmentCount() == 1) { + computedPath = fromFile.getParentDirectory().getRelative(fileToImport); + } else { + throw new ASTLookupInputException(String.format(LoadStatement.PATH_ERROR_MSG, fileToImport)); + } + return key(repo, computedPath); + } + + private static SkyKey key(RepositoryName repo, PathFragment fileToImport) + throws ASTLookupInputException { + // Skylark import lookup keys need to be valid AST file lookup keys. + checkInputArgument(fileToImport); + return new SkyKey( + SkyFunctions.SKYLARK_IMPORTS_LOOKUP, + new PackageIdentifier(repo, fileToImport)); } } |