Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Unified Diff: lib/src/compiler/command.dart

Issue 1896613002: Move all args to per-request for the worker, and add a test (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: use exit code 70 for internal errors Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bin/dartdevc.dart ('k') | test/worker/worker_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/compiler/command.dart
diff --git a/lib/src/compiler/command.dart b/lib/src/compiler/command.dart
index 686dddfae493a29d3ccd42b1c32ad7b67e17ff43..6cb95da11657320bd2d0a2beddf127ab9143696a 100644
--- a/lib/src/compiler/command.dart
+++ b/lib/src/compiler/command.dart
@@ -8,53 +8,42 @@ import 'package:args/command_runner.dart';
import 'package:analyzer/src/generated/source.dart' show Source;
import 'package:analyzer/src/summary/package_bundle_reader.dart'
show InSummarySource;
-import 'package:bazel_worker/bazel_worker.dart';
import 'compiler.dart'
show BuildUnit, CompilerOptions, JSModuleFile, ModuleCompiler;
import '../analyzer/context.dart' show AnalyzerOptions;
import 'package:path/path.dart' as path;
+typedef void MessageHandler(Object message);
+
/// The command for invoking the modular compiler.
class CompileCommand extends Command {
get name => 'compile';
get description => 'Compile a set of Dart files into a JavaScript module.';
+ final MessageHandler messageHandler;
- CompileCommand() {
+ CompileCommand({MessageHandler messageHandler})
+ : this.messageHandler = messageHandler ?? print {
argParser.addOption('out', abbr: 'o', help: 'Output file (required)');
- argParser.addFlag('persistent_worker',
- help: 'Run in a persistent Bazel worker (http://bazel.io/)\n',
- defaultsTo: false,
- hide: true);
CompilerOptions.addArguments(argParser);
AnalyzerOptions.addArguments(argParser);
}
@override
void run() {
- var analyzerOptions = new AnalyzerOptions.fromArguments(argResults);
- if (argResults['persistent_worker']) {
- new _CompilerWorker(analyzerOptions, this).run();
- } else {
- compile(
- new ModuleCompiler(analyzerOptions),
- new CompilerOptions.fromArguments(argResults),
- argResults['out'],
- argResults.rest);
- }
- }
+ var compiler =
+ new ModuleCompiler(new AnalyzerOptions.fromArguments(argResults));
+ var compilerOptions = new CompilerOptions.fromArguments(argResults);
+ var outPath = argResults['out'];
- void compile(ModuleCompiler compiler, CompilerOptions compilerOptions,
- String outPath, List<String> extraArgs,
- {void forEachError(String error): print}) {
if (outPath == null) {
usageException('Please include the output file location. For example:\n'
' -o PATH/TO/OUTPUT_FILE.js');
}
- var unit = new BuildUnit(
- path.basenameWithoutExtension(outPath), extraArgs, _moduleForLibrary);
+ var unit = new BuildUnit(path.basenameWithoutExtension(outPath),
+ argResults.rest, _moduleForLibrary);
JSModuleFile module = compiler.compile(unit, compilerOptions);
- module.errors.forEach(forEachError);
+ module.errors.forEach(messageHandler);
if (!module.isValid) throw new CompileErrorException();
@@ -83,81 +72,7 @@ class CompileCommand extends Command {
}
}
-/// Handles [error] in a uniform fashion. Returns the proper exit code and calls
-/// [messageHandler] with messages.
-int handleError(dynamic error, dynamic stackTrace, List<String> args,
- {void messageHandler(Object message): print}) {
- if (error is UsageException) {
- // Incorrect usage, input file not found, etc.
- messageHandler(error);
- return 64;
- } else if (error is CompileErrorException) {
- // Code has error(s) and failed to compile.
- messageHandler(error);
- return 1;
- } else {
- // Anything else is likely a compiler bug.
- //
- // --unsafe-force-compile is a bit of a grey area, but it's nice not to
- // crash while compiling
- // (of course, output code may crash, if it had errors).
- //
- messageHandler("");
- messageHandler("We're sorry, you've found a bug in our compiler.");
- messageHandler("You can report this bug at:");
- messageHandler(" https://github.com/dart-lang/dev_compiler/issues");
- messageHandler("");
- messageHandler(
- "Please include the information below in your report, along with");
- messageHandler(
- "any other information that may help us track it down. Thanks!");
- messageHandler("");
- messageHandler(" dartdevc arguments: " + args.join(' '));
- messageHandler(" dart --version: ${Platform.version}");
- messageHandler("");
- messageHandler("```");
- messageHandler(error);
- messageHandler(stackTrace);
- messageHandler("```");
- return 1;
- }
-}
-
/// Thrown when the input source code has errors.
class CompileErrorException implements Exception {
toString() => '\nPlease fix all errors before compiling (warnings are okay).';
}
-
-/// Runs the compiler worker loop.
-class _CompilerWorker extends SyncWorkerLoop {
- final AnalyzerOptions analyzerOptions;
- final CompileCommand compileCommand;
-
- _CompilerWorker(this.analyzerOptions, this.compileCommand) : super();
-
- WorkResponse performRequest(WorkRequest request) {
- var arguments = new List.from(request.arguments)
- ..addAll(compileCommand.argResults.rest);
- var argResults = compileCommand.argParser.parse(arguments);
-
- var output = new StringBuffer();
- try {
- compileCommand.compile(
- new ModuleCompiler(analyzerOptions),
- new CompilerOptions.fromArguments(argResults),
- argResults['out'],
- argResults.rest,
- forEachError: output.writeln);
- return new WorkResponse()
- ..exitCode = EXIT_CODE_OK
- ..output = output.toString();
- } catch (e, s) {
- var response = new WorkResponse();
- var output = new StringBuffer();
- response.exitCode =
- handleError(e, s, request.arguments, messageHandler: output.writeln);
- response.output = output.toString();
- return response;
- }
- }
-}
« no previous file with comments | « bin/dartdevc.dart ('k') | test/worker/worker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698