Search in sources :

Example 1 with Frame

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

the class WorkspaceFactory method execute.

private void execute(BuildFileAST ast, @Nullable Map<String, Extension> importedExtensions, StoredEventHandler localReporter) throws InterruptedException {
    Environment.Builder environmentBuilder = Environment.builder(mutability).setGlobals(BazelLibrary.GLOBALS).setEventHandler(localReporter);
    if (importedExtensions != null) {
        Map<String, Extension> map = new HashMap<String, Extension>(parentImportMap);
        map.putAll(importedExtensions);
        importMap = ImmutableMap.<String, Extension>copyOf(importedExtensions);
    } else {
        importMap = parentImportMap;
    }
    environmentBuilder.setImportedExtensions(importMap);
    Environment workspaceEnv = environmentBuilder.setPhase(Phase.WORKSPACE).build();
    addWorkspaceFunctions(workspaceEnv, localReporter);
    for (Map.Entry<String, Object> binding : parentVariableBindings.entrySet()) {
        try {
            workspaceEnv.update(binding.getKey(), binding.getValue());
        } catch (EvalException e) {
            // This should never happen because everything was already evaluated.
            throw new IllegalStateException(e);
        }
    }
    if (!ast.exec(workspaceEnv, localReporter)) {
        localReporter.handle(Event.error("Error evaluating WORKSPACE file"));
    }
    // Save the list of variable bindings for the next part of the workspace file. The list of
    // variable bindings of interest are the global variable bindings that are defined by the user,
    // so not the workspace functions.
    // Workspace functions are not serializable and should not be passed over sky values. They
    // also have a package builder specific to the current part and should be reinitialized for
    // each workspace file.
    ImmutableMap.Builder<String, Object> bindingsBuilder = ImmutableMap.builder();
    Frame globals = workspaceEnv.getGlobals();
    for (String s : globals.getDirectVariableNames()) {
        Object o = globals.get(s);
        if (!isAWorkspaceFunction(s, o)) {
            bindingsBuilder.put(s, o);
        }
    }
    variableBindings = bindingsBuilder.build();
    builder.addEvents(localReporter.getEvents());
    if (localReporter.hasErrors()) {
        builder.setContainsErrors();
    }
    localReporter.clear();
}
Also used : Frame(com.google.devtools.build.lib.syntax.Environment.Frame) HashMap(java.util.HashMap) EvalException(com.google.devtools.build.lib.syntax.EvalException) ImmutableMap(com.google.common.collect.ImmutableMap) EnvironmentExtension(com.google.devtools.build.lib.packages.PackageFactory.EnvironmentExtension) Extension(com.google.devtools.build.lib.syntax.Environment.Extension) Environment(com.google.devtools.build.lib.syntax.Environment) ClassObject(com.google.devtools.build.lib.syntax.ClassObject) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 EnvironmentExtension (com.google.devtools.build.lib.packages.PackageFactory.EnvironmentExtension)1 ClassObject (com.google.devtools.build.lib.syntax.ClassObject)1 Environment (com.google.devtools.build.lib.syntax.Environment)1 Extension (com.google.devtools.build.lib.syntax.Environment.Extension)1 Frame (com.google.devtools.build.lib.syntax.Environment.Frame)1 EvalException (com.google.devtools.build.lib.syntax.EvalException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1