diff options
author | John Field <jfield@google.com> | 2015-11-17 21:21:34 +0000 |
---|---|---|
committer | Lukacs Berki <lberki@google.com> | 2015-11-18 15:30:29 +0000 |
commit | 3b58a1c372a9ebec62d09172321dd1866505940e (patch) | |
tree | 1a000a5a05af1f33ab0decf433f59da8cafd1d70 /src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java | |
parent | e5e82501576fce25e2ef1e659e10efdd817df7a6 (diff) |
Skylark path-based relative loads now work correctly (with the new label-based loading machinery) when the containing file is in a subdirectory of a package.
Also, while we're in the neighborhood: correct two nearby tests of relative loads that were passing for the wrong reasons.
--
MOS_MIGRATED_REVID=108072189
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 | 7 |
1 files changed, 5 insertions, 2 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 3b18e09fcb..9baa935cd1 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 @@ -210,10 +210,13 @@ public class SkylarkImportLookupFunction implements SkyFunction { /** Computes the Label corresponding to a relative import path. */ private static Label labelForRelativeImport(PathFragment importPath, Label containingFileLabel) throws SkylarkImportFailedException { + // The twistiness of the code below is due to the fact that the containing file may be in + // a subdirectory of the package that contains it. We need to construct a Label with + // the import file in the same subdirectory. PackageIdentifier pkgIdForImport = containingFileLabel.getPackageIdentifier(); - PathFragment containingDir = + PathFragment containingDirInPkg = (new PathFragment(containingFileLabel.getName())).getParentDirectory(); - String targetNameForImport = importPath.getRelative(containingDir).toString(); + String targetNameForImport = containingDirInPkg.getRelative(importPath).toString(); try { return Label.create(pkgIdForImport, targetNameForImport); } catch (LabelSyntaxException e) { |