Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/scripts/closure/closure_runner/src/org/chromium/devtools/compiler/Runner.java |
| diff --git a/third_party/WebKit/Source/devtools/scripts/closure/closure_runner/src/org/chromium/devtools/compiler/Runner.java b/third_party/WebKit/Source/devtools/scripts/closure/closure_runner/src/org/chromium/devtools/compiler/Runner.java |
| index 06c0d74b1a7113bdd627017f7f60f2db2820d2e0..79e7aa1ca46ba83ba67e4cecd0be2943e3f692dd 100644 |
| --- a/third_party/WebKit/Source/devtools/scripts/closure/closure_runner/src/org/chromium/devtools/compiler/Runner.java |
| +++ b/third_party/WebKit/Source/devtools/scripts/closure/closure_runner/src/org/chromium/devtools/compiler/Runner.java |
| @@ -69,7 +69,6 @@ public class Runner { |
| processedArgs.add(arg); |
| } |
| } |
| - |
| return processedArgs; |
| } |
| @@ -85,90 +84,54 @@ public class Runner { |
| } |
| private void run() { |
| - List<CompilerInstanceDescriptor> descriptors = getDescriptors(); |
| - if (descriptors == null) { |
| + CompilerInstanceDescriptor descriptor = getDescriptor(); |
| + if (descriptor == null) { |
| return; |
| } |
| - ExecutorService executor = Executors.newFixedThreadPool( |
| - Math.min(descriptors.size(), Runtime.getRuntime().availableProcessors() / 2 + 1)); |
| + ExecutorService executor = Executors.newSingleThreadExecutor(); |
| try { |
| - runWithExecutor(descriptors, executor); |
| + runWithExecutor(descriptor, executor); |
| } finally { |
| executor.shutdown(); |
| } |
| } |
| - private void runWithExecutor( |
| - List<CompilerInstanceDescriptor> descriptors, ExecutorService executor) { |
| - List<Future<CompilerRunner>> futures = new ArrayList<>(descriptors.size()); |
| - for (CompilerInstanceDescriptor descriptor : descriptors) { |
| - try { |
| - ByteArrayOutputStream rawStream = new ByteArrayOutputStream(512); |
| - PrintStream errPrintStream = new PrintStream(rawStream, false, "UTF-8"); |
| - // We have to create instance of LocalCommandLineRunner object here, |
| - // because its constructor should be executed on a single thread. |
| - // Constructor is parsing flags and creating options object that can |
| - // be used later in parallel during compilation. |
| - LocalCommandLineRunner runner = new LocalCommandLineRunner( |
| - descriptor.commandLine.split(" +"), System.out, errPrintStream); |
| - |
| - CompilerRunner task = new CompilerRunner(descriptor, rawStream, runner); |
| - futures.add(executor.submit(task)); |
| - } catch (Exception e) { |
| - System.err.println("ERROR - " + e.getMessage()); |
| - e.printStackTrace(System.err); |
| - } |
| - } |
| - |
| - for (Future<CompilerRunner> future : futures) { |
| - try { |
| - CompilerRunner task = future.get(); |
| - int result = task.result; |
| - if (result != 0) { |
| - System.err.println("ERROR: Compiler returned " + result); |
| - } |
| - task.errStream.flush(); |
| - System.err.println("@@ START_MODULE:" + task.descriptor.moduleName + " @@"); |
| - System.err.println(task.errStream.toString("UTF-8")); |
| - System.err.println("@@ END_MODULE @@"); |
| - } catch (Exception e) { |
| - System.err.println("ERROR - " + e.getMessage()); |
| - e.printStackTrace(System.err); |
| + private void runWithExecutor(CompilerInstanceDescriptor descriptor, ExecutorService executor) { |
| + try { |
| + ByteArrayOutputStream rawStream = new ByteArrayOutputStream(512); |
| + PrintStream errPrintStream = new PrintStream(rawStream, false, "UTF-8"); |
| + // We have to create instance of LocalCommandLineRunner object here, |
| + // because its constructor should be executed on a single thread. |
| + // Constructor is parsing flags and creating options object that can |
| + // be used later in parallel during compilation. |
| + LocalCommandLineRunner runner = new LocalCommandLineRunner( |
| + descriptor.commandLine.split(" +"), System.out, errPrintStream); |
| + |
| + Future<CompilerRunner> future = |
| + executor.submit(new CompilerRunner(descriptor, rawStream, runner)); |
| + CompilerRunner task = future.get(); |
| + int result = task.result; |
| + task.errStream.flush(); |
| + System.err.println(task.errStream.toString("UTF-8")); |
| + if (task.result != 0) { |
| + System.exit(task.result); |
| } |
| + } catch (Exception e) { |
| + System.err.println("ERROR - " + e.getMessage()); |
| + e.printStackTrace(System.err); |
| } |
| System.exit(0); |
| } |
| - private List<CompilerInstanceDescriptor> getDescriptors() { |
| - List<CompilerInstanceDescriptor> result = new ArrayList<>(); |
| + private CompilerInstanceDescriptor getDescriptor() { |
| try (BufferedReader reader = new BufferedReader( |
| new InputStreamReader(new FileInputStream(flags.compilerArgsFile), "UTF-8"))) { |
| - int lineIndex = 0; |
| - while (true) { |
| - ++lineIndex; |
| - String line = reader.readLine(); |
| - if (line == null) { |
| - break; |
| - } |
| - if (line.length() == 0) { |
| - continue; |
| - } |
| - String[] moduleAndArgs = line.split(" +", 2); |
| - if (moduleAndArgs.length != 2) { |
| - logError(String.format( |
| - "Line %d does not contain module name and compiler arguments", |
| - lineIndex), |
| - null); |
| - continue; |
| - } |
| - result.add(new CompilerInstanceDescriptor(moduleAndArgs[0], moduleAndArgs[1])); |
| - } |
| + String line = reader.readLine(); |
| + return new CompilerInstanceDescriptor(line); |
| } catch (IOException e) { |
| logError("Failed to read compiler arguments file", e); |
| return null; |
| } |
| - |
| - return result; |
| } |
| public static void main(String[] args) { |
| @@ -227,16 +190,14 @@ public class Runner { |
| private static class Flags { |
|
dgozman
2016/12/27 18:07:36
Why do we need all these classes (Flags, CompilerI
chenwilliam
2016/12/27 23:49:15
Splitting this up into a separate CL.
|
| @Option(name = "--compiler-args-file", |
| - usage = "Full path to file containing compiler arguments (one line per instance)") |
| + usage = "Full path to file containing compiler arguments (one line)") |
| private String compilerArgsFile = null; |
| } |
| private static class CompilerInstanceDescriptor { |
| - private final String moduleName; |
| private final String commandLine; |
| - public CompilerInstanceDescriptor(String moduleName, String commandLine) { |
| - this.moduleName = moduleName; |
| + public CompilerInstanceDescriptor(String commandLine) { |
| this.commandLine = commandLine; |
| } |
| } |