diff options
author | John Field <jfield@google.com> | 2015-11-13 02:19:52 +0000 |
---|---|---|
committer | Lukacs Berki <lberki@google.com> | 2015-11-13 10:24:13 +0000 |
commit | a97e17f4a5b6662b96ab4e14b804ac75d6f76ad4 (patch) | |
tree | d92acd480c6f02fc2b708a4672f2b59a6ff8d364 /src/main/java/com/google/devtools/build/lib/skyframe/ToplevelSkylarkAspectFunction.java | |
parent | 1e66ccd2f18b03733f22b93ad8051ff2cf37d3dd (diff) |
Use Labels, rather than PathFragments, to represent Skylark loads internally. The load location for a Skylark Aspect is specified via a PathFragment, for consistency with current non-Aspect Skylark loads.
This should be a semantics-preserving change for users. In a subsequent CL, I'll change the Skylark syntax to allow load statements to use labels as well as paths, with the goal of eventually deprecating the latter.
Also:
- Removed the hack for handling relative loads in the prelude file.
- Refactored some redundant functionality in PackageFunction and SkylarkImportLookupFunction for handling loads.
- Removed the ability to put the BUILD file for the package containing a Skylark file under a different package root than the Skylark file itself. This functionality isn't currently used and is inconsistent with Blaze's handling of the package path elsewhere.
- Added BUILD files to a number of tests that load Skylark files; this is consistent with the requirement that all Skylark files need to be part of some package.
- Changed the constants used to set the location of the prelude file from paths to labels.
--
MOS_MIGRATED_REVID=107741568
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/ToplevelSkylarkAspectFunction.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/ToplevelSkylarkAspectFunction.java | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ToplevelSkylarkAspectFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ToplevelSkylarkAspectFunction.java index fabb1bb058..cecc689b75 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/ToplevelSkylarkAspectFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/ToplevelSkylarkAspectFunction.java @@ -14,13 +14,16 @@ package com.google.devtools.build.lib.skyframe; -import com.google.devtools.build.lib.cmdline.PackageIdentifier; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.packages.AspectParameters; import com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.SkylarkAspect; import com.google.devtools.build.lib.rules.SkylarkRuleClassFunctions.SkylarkAspectClass; -import com.google.devtools.build.lib.skyframe.ASTFileLookupValue.ASTLookupInputException; import com.google.devtools.build.lib.skyframe.AspectValue.SkylarkAspectLoadingKey; +import com.google.devtools.build.lib.skyframe.SkylarkImportLookupFunction.SkylarkImportFailedException; import com.google.devtools.build.lib.syntax.Type.ConversionException; +import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.skyframe.SkyFunction; import com.google.devtools.build.skyframe.SkyFunctionException; import com.google.devtools.build.skyframe.SkyKey; @@ -33,7 +36,7 @@ import javax.annotation.Nullable; * * Used for loading top-level aspects. At top level, in * {@link com.google.devtools.build.lib.analysis.BuildView}, we cannot invoke two SkyFunctions - * one aftre another, so BuildView call this function to do the work. + * one after another, so BuildView calls this function to do the work. */ public class ToplevelSkylarkAspectFunction implements SkyFunction { @@ -43,11 +46,25 @@ public class ToplevelSkylarkAspectFunction implements SkyFunction { throws LoadSkylarkAspectFunctionException, InterruptedException { SkylarkAspectLoadingKey aspectLoadingKey = (SkylarkAspectLoadingKey) skyKey.argument(); String skylarkValueName = aspectLoadingKey.getSkylarkValueName(); - PackageIdentifier extensionFile = aspectLoadingKey.getExtensionFile(); + PathFragment extensionFile = aspectLoadingKey.getExtensionFile(); + + // Find label corresponding to skylark file, if one exists. + ImmutableMap<PathFragment, Label> labelLookupMap; + try { + labelLookupMap = + SkylarkImportLookupFunction.labelsForAbsoluteImports(ImmutableSet.of(extensionFile), env); + } catch (SkylarkImportFailedException e) { + throw new LoadSkylarkAspectFunctionException(e, skyKey); + } + if (labelLookupMap == null) { + return null; + } + SkylarkAspect skylarkAspect = null; try { - skylarkAspect = AspectFunction.loadSkylarkAspect(env, extensionFile, skylarkValueName); - } catch (ASTLookupInputException | ConversionException e) { + skylarkAspect = AspectFunction.loadSkylarkAspect( + env, labelLookupMap.get(extensionFile), skylarkValueName); + } catch (ConversionException e) { throw new LoadSkylarkAspectFunctionException(e, skyKey); } if (skylarkAspect == null) { |