Skip to content

Commit

Permalink
Make sure the vanilla java builder closes its JavaFileManager.
Browse files Browse the repository at this point in the history
I observed that before this change, large vanilla Java builds could exhaust the file descriptor limit of java builder worker processes.

Closes bazelbuild#6695.

PiperOrigin-RevId: 222693636
  • Loading branch information
benjaminp authored and Copybara-Service committed Nov 24, 2018
1 parent 95190b7 commit d24d08b
Showing 1 changed file with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,29 +152,28 @@ public VanillaJavaBuilderResult run(List<String> args) throws IOException {
DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<>();
StringWriter output = new StringWriter();
JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager =
javaCompiler.getStandardFileManager(diagnosticCollector, ENGLISH, UTF_8);

Path tempDir = Paths.get(firstNonNull(optionsParser.getTempDir(), "_tmp"));
Path nativeHeaderDir = tempDir.resolve("native_headers");
Files.createDirectories(nativeHeaderDir);

setLocations(optionsParser, fileManager, nativeHeaderDir);
ImmutableList<JavaFileObject> sources = getSources(optionsParser, fileManager);
boolean ok;
if (sources.isEmpty()) {
ok = true;
} else {
CompilationTask task =
javaCompiler.getTask(
new PrintWriter(output, true),
fileManager,
diagnosticCollector,
JavacOptions.removeBazelSpecificFlags(optionsParser.getJavacOpts()),
ImmutableList.<String>of() /*classes*/,
sources);
setProcessors(optionsParser, fileManager, task);
ok = task.call();
try (StandardJavaFileManager fileManager =
javaCompiler.getStandardFileManager(diagnosticCollector, ENGLISH, UTF_8)) {
setLocations(optionsParser, fileManager, nativeHeaderDir);
ImmutableList<JavaFileObject> sources = getSources(optionsParser, fileManager);
if (sources.isEmpty()) {
ok = true;
} else {
CompilationTask task =
javaCompiler.getTask(
new PrintWriter(output, true),
fileManager,
diagnosticCollector,
JavacOptions.removeBazelSpecificFlags(optionsParser.getJavacOpts()),
ImmutableList.<String>of() /*classes*/,
sources);
setProcessors(optionsParser, fileManager, task);
ok = task.call();
}
}
if (ok) {
writeOutput(optionsParser);
Expand Down

0 comments on commit d24d08b

Please sign in to comment.