Search in sources :

Example 1 with Identifier

use of com.google.devtools.build.lib.syntax.Identifier 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;
}
Also used : Identifier(com.google.devtools.build.lib.syntax.Identifier) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) AssignmentStatement(com.google.devtools.build.lib.syntax.AssignmentStatement) Expression(com.google.devtools.build.lib.syntax.Expression) FuncallExpression(com.google.devtools.build.lib.syntax.FuncallExpression) AssignmentStatement(com.google.devtools.build.lib.syntax.AssignmentStatement) Statement(com.google.devtools.build.lib.syntax.Statement)

Example 2 with Identifier

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

the class SkylarkRepositoryContextTest method setUpContextForRule.

protected void setUpContextForRule(Map<String, Object> kwargs, Attribute... attributes) throws Exception {
    Package.Builder packageBuilder = Package.newExternalPackageBuilder(Package.Builder.DefaultHelper.INSTANCE, workspaceFile, "runfiles");
    FuncallExpression ast = new FuncallExpression(new Identifier("test"), ImmutableList.<Passed>of());
    ast.setLocation(Location.BUILTIN);
    Rule rule = packageBuilder.externalPackageData().createAndAddRepositoryRule(packageBuilder, buildRuleClass(attributes), null, kwargs, ast);
    HttpDownloader downloader = Mockito.mock(HttpDownloader.class);
    context = new SkylarkRepositoryContext(rule, outputDirectory, Mockito.mock(SkyFunction.Environment.class), ImmutableMap.of("FOO", "BAR"), downloader, new HashMap<String, String>());
}
Also used : Identifier(com.google.devtools.build.lib.syntax.Identifier) SkyFunction(com.google.devtools.build.skyframe.SkyFunction) HttpDownloader(com.google.devtools.build.lib.bazel.repository.downloader.HttpDownloader) HashMap(java.util.HashMap) Package(com.google.devtools.build.lib.packages.Package) Rule(com.google.devtools.build.lib.packages.Rule) FuncallExpression(com.google.devtools.build.lib.syntax.FuncallExpression)

Aggregations

FuncallExpression (com.google.devtools.build.lib.syntax.FuncallExpression)2 Identifier (com.google.devtools.build.lib.syntax.Identifier)2 HttpDownloader (com.google.devtools.build.lib.bazel.repository.downloader.HttpDownloader)1 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)1 Package (com.google.devtools.build.lib.packages.Package)1 Rule (com.google.devtools.build.lib.packages.Rule)1 AssignmentStatement (com.google.devtools.build.lib.syntax.AssignmentStatement)1 Expression (com.google.devtools.build.lib.syntax.Expression)1 Statement (com.google.devtools.build.lib.syntax.Statement)1 SkyFunction (com.google.devtools.build.skyframe.SkyFunction)1 HashMap (java.util.HashMap)1