Index: pkg/compiler/tool/generate_kernel.dart |
diff --git a/pkg/compiler/tool/generate_kernel.dart b/pkg/compiler/tool/generate_kernel.dart |
index c6a24b0a0db44869afb876b88e80a77181e67273..dabd4076cd2e680a185eaaa58c7d19f6aa7b8024 100644 |
--- a/pkg/compiler/tool/generate_kernel.dart |
+++ b/pkg/compiler/tool/generate_kernel.dart |
@@ -8,29 +8,51 @@ |
// command line. |
library compiler.tool.generate_kernel; |
-import 'dart:io' show exitCode; |
- |
-import 'package:front_end/src/fasta/compiler_command_line.dart' |
- show CompilerCommandLine; |
-import 'package:front_end/src/fasta/compiler_context.dart' show CompilerContext; |
-import 'package:front_end/src/fasta/errors.dart' show InputError; |
-import 'package:front_end/src/fasta/ticker.dart' show Ticker; |
-import 'package:compiler/src/kernel/fasta_support.dart' show Dart2jsCompileTask; |
- |
-main(List<String> arguments) async { |
- try { |
- await CompilerCommandLine.withGlobalOptions("generate_kernel", arguments, |
- (CompilerContext c) async { |
- if (c.options.verbose) { |
- print("Compiling directly to Kernel: ${arguments.join(' ')}"); |
- } |
- var task = |
- new Dart2jsCompileTask(c, new Ticker(isVerbose: c.options.verbose)); |
- await task.compile(); |
- }); |
- } on InputError catch (e) { |
- exitCode = 1; |
- print(e.format()); |
- return null; |
+import 'dart:io'; |
+ |
+import 'package:args/args.dart'; |
+import 'package:compiler/src/kernel/dart2js_target.dart'; |
+import 'package:front_end/front_end.dart'; |
+import 'package:front_end/src/fasta/util/relativize.dart'; |
+import 'package:kernel/kernel.dart'; |
+import 'package:kernel/target/targets.dart'; |
+ |
+main(List<String> args) async { |
+ ArgResults flags = _argParser.parse(args); |
+ var options = new CompilerOptions() |
+ ..target = new Dart2jsTarget(new TargetFlags()) |
+ ..packagesFileUri = Platform.script.resolve('../../../.packages') |
+ ..compileSdk = true |
+ ..linkedDependencies = [Uri.base.resolve(flags['platform'])] |
+ ..onError = errorHandler; |
+ |
+ if (flags.rest.isEmpty) { |
+ var script = relativizeUri(Platform.script); |
+ var platform = relativizeUri(Uri.base.resolve(flags['platform'])); |
+ print('usage: ${Platform.executable} $script ' |
+ '[--platform=$platform] [--out=out.dill] program.dart'); |
+ exit(1); |
} |
+ |
+ Uri entry = Uri.base.resolve(flags.rest.first); |
+ var program = await kernelForProgram(entry, options); |
+ program.uriToSource.clear(); |
+ await writeProgramToBinary(program, flags['out']); |
} |
+ |
+void errorHandler(CompilationError e) { |
+ exitCode = 1; |
+ print(e.message); |
+} |
+ |
+ArgParser _argParser = new ArgParser() |
+ ..addOption('platform', |
+ help: 'location of the precompiled dart2js sdk', |
+ defaultsTo: _defaultPlatform) |
+ ..addOption('out', |
+ abbr: 'o', help: 'output location', defaultsTo: 'out.dill'); |
+ |
+String _defaultPlatform = Uri |
+ .parse(Platform.resolvedExecutable) |
+ .resolve('patched_dart2js_sdk/platform.dill') |
+ .toString(); |