Search in sources :

Example 31 with EvalException

use of com.google.devtools.build.lib.syntax.EvalException in project bazel by bazelbuild.

the class SkylarkRepositoryContext method verifyLabelMarkerData.

private static boolean verifyLabelMarkerData(String key, String value, Environment env) throws InterruptedException {
    Preconditions.checkArgument(key.startsWith("FILE:"));
    try {
        Label label = Label.parseAbsolute(key.substring(5));
        RootedPath rootedPath = getRootedPathFromLabel(label, env);
        SkyKey fileSkyKey = FileValue.key(rootedPath);
        FileValue fileValue = (FileValue) env.getValueOrThrow(fileSkyKey, IOException.class, FileSymlinkException.class, InconsistentFilesystemException.class);
        if (fileValue == null || !fileValue.isFile()) {
            return false;
        }
        return Objects.equals(value, Integer.toString(fileValue.realFileStateValue().hashCode()));
    } catch (LabelSyntaxException e) {
        throw new IllegalStateException("Key " + key + " is not a correct file key (should be in form FILE:label)", e);
    } catch (IOException | FileSymlinkException | InconsistentFilesystemException | EvalException e) {
        // Consider those exception to be a cause for invalidation
        return false;
    }
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) FileValue(com.google.devtools.build.lib.skyframe.FileValue) LabelSyntaxException(com.google.devtools.build.lib.cmdline.LabelSyntaxException) FileSymlinkException(com.google.devtools.build.lib.skyframe.FileSymlinkException) Label(com.google.devtools.build.lib.cmdline.Label) IOException(java.io.IOException) EvalException(com.google.devtools.build.lib.syntax.EvalException) InconsistentFilesystemException(com.google.devtools.build.lib.skyframe.InconsistentFilesystemException) RootedPath(com.google.devtools.build.lib.vfs.RootedPath)

Example 32 with EvalException

use of com.google.devtools.build.lib.syntax.EvalException in project bazel by bazelbuild.

the class SkylarkAspectFactory method create.

@Override
public ConfiguredAspect create(ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) throws InterruptedException {
    try (Mutability mutability = Mutability.create("aspect")) {
        AspectDescriptor aspectDescriptor = new AspectDescriptor(skylarkAspect.getAspectClass(), parameters);
        SkylarkRuleContext skylarkRuleContext;
        try {
            skylarkRuleContext = new SkylarkRuleContext(ruleContext, aspectDescriptor);
        } catch (EvalException e) {
            ruleContext.ruleError(e.getMessage());
            return null;
        }
        Environment env = Environment.builder(mutability).setGlobals(skylarkAspect.getFuncallEnv().getGlobals()).setEventHandler(ruleContext.getAnalysisEnvironment().getEventHandler()).build();
        // so we do *not* setLoadingPhase().
        Object aspectSkylarkObject;
        try {
            aspectSkylarkObject = skylarkAspect.getImplementation().call(ImmutableList.<Object>of(base, skylarkRuleContext), ImmutableMap.<String, Object>of(), /*ast=*/
            null, env);
            if (ruleContext.hasErrors()) {
                return null;
            } else if (!(aspectSkylarkObject instanceof SkylarkClassObject) && !(aspectSkylarkObject instanceof Iterable)) {
                ruleContext.ruleError(String.format("Aspect implementation should return a struct or a list, but got %s", SkylarkType.typeOf(aspectSkylarkObject)));
                return null;
            }
            return createAspect(aspectSkylarkObject, aspectDescriptor, ruleContext);
        } catch (EvalException e) {
            addAspectToStackTrace(base, e);
            ruleContext.ruleError("\n" + e.print());
            return null;
        }
    }
}
Also used : SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) Mutability(com.google.devtools.build.lib.syntax.Mutability) AspectDescriptor(com.google.devtools.build.lib.packages.AspectDescriptor) Environment(com.google.devtools.build.lib.syntax.Environment) SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) EvalException(com.google.devtools.build.lib.syntax.EvalException) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext)

Example 33 with EvalException

use of com.google.devtools.build.lib.syntax.EvalException in project bazel by bazelbuild.

the class SkylarkImportLookupFunction method possiblyExport.

private static void possiblyExport(Statement statement, Label extensionLabel, EventHandler eventHandler, com.google.devtools.build.lib.syntax.Environment extensionEnv) {
    if (!(statement instanceof AssignmentStatement)) {
        return;
    }
    AssignmentStatement assignmentStatement = (AssignmentStatement) statement;
    ImmutableSet<String> boundNames = assignmentStatement.getLValue().boundNames();
    for (String name : boundNames) {
        Object lookup = extensionEnv.lookup(name);
        if (lookup instanceof SkylarkExportable) {
            try {
                SkylarkExportable exportable = (SkylarkExportable) lookup;
                if (!exportable.isExported()) {
                    exportable.export(extensionLabel, name);
                }
            } catch (EvalException e) {
                eventHandler.handle(Event.error(e.getLocation(), e.getMessage()));
            }
        }
    }
}
Also used : AssignmentStatement(com.google.devtools.build.lib.syntax.AssignmentStatement) SkylarkExportable(com.google.devtools.build.lib.packages.SkylarkExportable) EvalException(com.google.devtools.build.lib.syntax.EvalException)

Example 34 with EvalException

use of com.google.devtools.build.lib.syntax.EvalException in project bazel by bazelbuild.

the class AbstractConfiguredTarget method containsKey.

@Override
public boolean containsKey(Object key, Location loc) throws EvalException {
    if (!(key instanceof ClassObjectConstructor)) {
        throw new EvalException(loc, String.format("Type Target only supports querying by object constructors, got %s instead", EvalUtils.getDataTypeName(key)));
    }
    ClassObjectConstructor constructor = (ClassObjectConstructor) key;
    SkylarkProviders provider = getProvider(SkylarkProviders.class);
    if (provider != null) {
        Object declaredProvider = provider.getDeclaredProvider(constructor.getKey());
        if (declaredProvider != null) {
            return true;
        }
    }
    return false;
}
Also used : ClassObjectConstructor(com.google.devtools.build.lib.packages.ClassObjectConstructor) ClassObject(com.google.devtools.build.lib.syntax.ClassObject) EvalException(com.google.devtools.build.lib.syntax.EvalException)

Example 35 with EvalException

use of com.google.devtools.build.lib.syntax.EvalException in project bazel by bazelbuild.

the class WorkspaceFactory method newBindFunction.

private static BuiltinFunction newBindFunction(final RuleFactory ruleFactory) {
    return new BuiltinFunction("bind", FunctionSignature.namedOnly(1, "name", "actual"), BuiltinFunction.USE_AST_ENV) {

        public Object invoke(String name, String actual, FuncallExpression ast, Environment env) throws EvalException, InterruptedException {
            Label nameLabel;
            try {
                nameLabel = Label.parseAbsolute("//external:" + name);
                try {
                    Package.Builder builder = PackageFactory.getContext(env, ast).pkgBuilder;
                    RuleClass ruleClass = ruleFactory.getRuleClass("bind");
                    builder.externalPackageData().addBindRule(builder, ruleClass, nameLabel, actual == null ? null : Label.parseAbsolute(actual), ast.getLocation(), ruleFactory.getAttributeContainer(ruleClass));
                } catch (RuleFactory.InvalidRuleException | Package.NameConflictException | LabelSyntaxException e) {
                    throw new EvalException(ast.getLocation(), e.getMessage());
                }
            } catch (LabelSyntaxException e) {
                throw new EvalException(ast.getLocation(), e.getMessage());
            }
            return NONE;
        }
    };
}
Also used : LabelSyntaxException(com.google.devtools.build.lib.cmdline.LabelSyntaxException) Label(com.google.devtools.build.lib.cmdline.Label) EvalException(com.google.devtools.build.lib.syntax.EvalException) NameConflictException(com.google.devtools.build.lib.packages.Package.NameConflictException) BuiltinFunction(com.google.devtools.build.lib.syntax.BuiltinFunction) Environment(com.google.devtools.build.lib.syntax.Environment) FuncallExpression(com.google.devtools.build.lib.syntax.FuncallExpression) InvalidRuleException(com.google.devtools.build.lib.packages.RuleFactory.InvalidRuleException)

Aggregations

EvalException (com.google.devtools.build.lib.syntax.EvalException)47 IOException (java.io.IOException)15 WorkspaceAttributeMapper (com.google.devtools.build.lib.rules.repository.WorkspaceAttributeMapper)9 ClassObject (com.google.devtools.build.lib.syntax.ClassObject)9 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 Label (com.google.devtools.build.lib.cmdline.Label)8 Path (com.google.devtools.build.lib.vfs.Path)8 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)7 Environment (com.google.devtools.build.lib.syntax.Environment)7 Map (java.util.Map)7 LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)6 RepositoryFunctionException (com.google.devtools.build.lib.rules.repository.RepositoryFunction.RepositoryFunctionException)6 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)6 SkyKey (com.google.devtools.build.skyframe.SkyKey)6 Nullable (javax.annotation.Nullable)6 FileValue (com.google.devtools.build.lib.skyframe.FileValue)5 ImmutableList (com.google.common.collect.ImmutableList)4 Artifact (com.google.devtools.build.lib.actions.Artifact)4 BaseFunction (com.google.devtools.build.lib.syntax.BaseFunction)3