Search in sources :

Example 1 with SkylarkAspectLoadingKey

use of com.google.devtools.build.lib.skyframe.AspectValue.SkylarkAspectLoadingKey in project bazel by bazelbuild.

the class ToplevelSkylarkAspectFunction method compute.

@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws LoadSkylarkAspectFunctionException, InterruptedException {
    SkylarkAspectLoadingKey aspectLoadingKey = (SkylarkAspectLoadingKey) skyKey.argument();
    String skylarkValueName = aspectLoadingKey.getSkylarkValueName();
    SkylarkImport extensionFile = aspectLoadingKey.getSkylarkImport();
    // Find label corresponding to skylark file, if one exists.
    ImmutableMap<String, Label> labelLookupMap;
    try {
        labelLookupMap = SkylarkImportLookupFunction.findLabelsForLoadStatements(ImmutableList.of(extensionFile), Label.parseAbsoluteUnchecked("//:empty"), env);
    } catch (SkylarkImportFailedException e) {
        env.getListener().handle(Event.error(e.getMessage()));
        throw new LoadSkylarkAspectFunctionException(new AspectCreationException(e.getMessage()));
    }
    if (labelLookupMap == null) {
        return null;
    }
    SkylarkAspect skylarkAspect;
    Label extensionFileLabel = Iterables.getOnlyElement(labelLookupMap.values());
    try {
        skylarkAspect = AspectFunction.loadSkylarkAspect(env, extensionFileLabel, skylarkValueName);
        if (skylarkAspect == null) {
            return null;
        }
        if (!skylarkAspect.getParamAttributes().isEmpty()) {
            throw new AspectCreationException("Cannot instantiate parameterized aspect " + skylarkAspect.getName() + " at the top level.", extensionFileLabel);
        }
    } catch (AspectCreationException e) {
        throw new LoadSkylarkAspectFunctionException(e);
    }
    SkyKey aspectKey = ActionLookupValue.key(AspectValue.createAspectKey(aspectLoadingKey.getTargetLabel(), aspectLoadingKey.getTargetConfiguration(), new AspectDescriptor(skylarkAspect.getAspectClass(), AspectParameters.EMPTY), aspectLoadingKey.getAspectConfiguration()));
    return env.getValue(aspectKey);
}
Also used : SkylarkImport(com.google.devtools.build.lib.syntax.SkylarkImport) AspectCreationException(com.google.devtools.build.lib.skyframe.AspectFunction.AspectCreationException) SkyKey(com.google.devtools.build.skyframe.SkyKey) SkylarkAspectLoadingKey(com.google.devtools.build.lib.skyframe.AspectValue.SkylarkAspectLoadingKey) SkylarkAspect(com.google.devtools.build.lib.packages.SkylarkAspect) Label(com.google.devtools.build.lib.cmdline.Label) SkylarkImportFailedException(com.google.devtools.build.lib.skyframe.SkylarkImportLookupFunction.SkylarkImportFailedException) AspectDescriptor(com.google.devtools.build.lib.packages.AspectDescriptor) Nullable(javax.annotation.Nullable)

Aggregations

Label (com.google.devtools.build.lib.cmdline.Label)1 AspectDescriptor (com.google.devtools.build.lib.packages.AspectDescriptor)1 SkylarkAspect (com.google.devtools.build.lib.packages.SkylarkAspect)1 AspectCreationException (com.google.devtools.build.lib.skyframe.AspectFunction.AspectCreationException)1 SkylarkAspectLoadingKey (com.google.devtools.build.lib.skyframe.AspectValue.SkylarkAspectLoadingKey)1 SkylarkImportFailedException (com.google.devtools.build.lib.skyframe.SkylarkImportLookupFunction.SkylarkImportFailedException)1 SkylarkImport (com.google.devtools.build.lib.syntax.SkylarkImport)1 SkyKey (com.google.devtools.build.skyframe.SkyKey)1 Nullable (javax.annotation.Nullable)1