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

Unified Diff: pkg/compiler/tool/generate_kernel.dart

Issue 2976543002: Reapply "Tweak public APIs and use them in patch_sdk, dart2js, and kernel-service."" (Closed)
Patch Set: fix Created 3 years, 5 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
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();

Powered by Google App Engine
This is Rietveld 408576698