use of com.google.devtools.build.lib.syntax.AssignmentStatement in project bazel by bazelbuild.
the class PackageFactory method validateAssignmentStatements.
/**
* Tests a build AST to ensure that it contains no assignment statements that
* redefine built-in build rules.
*
* @param pkgEnv a package environment initialized with all of the built-in
* build rules
* @param ast the build file AST to be tested
* @param eventHandler a eventHandler where any errors should be logged
* @return true if the build file contains no redefinitions of built-in
* functions
*/
// TODO(bazel-team): Remove this check. It should be moved to LValue.assign
private static boolean validateAssignmentStatements(Environment pkgEnv, BuildFileAST ast, EventHandler eventHandler) {
for (Statement stmt : ast.getStatements()) {
if (stmt instanceof AssignmentStatement) {
Expression lvalue = ((AssignmentStatement) stmt).getLValue().getExpression();
if (!(lvalue instanceof Identifier)) {
continue;
}
String target = ((Identifier) lvalue).getName();
if (pkgEnv.hasVariable(target)) {
eventHandler.handle(Event.error(stmt.getLocation(), "Reassignment of builtin build " + "function '" + target + "' not permitted"));
return false;
}
}
}
return true;
}
use of com.google.devtools.build.lib.syntax.AssignmentStatement 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()));
}
}
}
}
Aggregations