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;
}
}
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;
}
}
}
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()));
}
}
}
}
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;
}
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;
}
};
}
Aggregations