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