OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// Helper to run fasta with the right target configuration to build dart2js | 5 /// Helper to run fasta with the right target configuration to build dart2js |
6 /// applications using the dart2js platform libraries. | 6 /// applications using the dart2js platform libraries. |
7 // TODO(sigmund): delete this file once we can configure fasta directly on the | 7 // TODO(sigmund): delete this file once we can configure fasta directly on the |
8 // command line. | 8 // command line. |
9 library compiler.tool.generate_kernel; | 9 library compiler.tool.generate_kernel; |
10 | 10 |
11 import 'dart:io'; | 11 import 'dart:io'; |
12 | 12 |
13 import 'package:args/args.dart'; | 13 import 'package:args/args.dart'; |
14 import 'package:compiler/src/kernel/dart2js_target.dart'; | 14 import 'package:compiler/src/kernel/dart2js_target.dart'; |
15 import 'package:front_end/front_end.dart'; | 15 import 'package:front_end/front_end.dart'; |
16 import 'package:front_end/src/fasta/util/relativize.dart'; | 16 import 'package:front_end/src/fasta/util/relativize.dart'; |
17 import 'package:kernel/kernel.dart'; | 17 import 'package:kernel/kernel.dart'; |
18 import 'package:kernel/target/targets.dart'; | 18 import 'package:kernel/target/targets.dart'; |
19 | 19 |
20 main(List<String> args) async { | 20 main(List<String> args) async { |
21 ArgResults flags = _argParser.parse(args); | 21 ArgResults flags = _argParser.parse(args); |
22 var options = new CompilerOptions() | 22 var options = new CompilerOptions() |
23 ..target = new Dart2jsTarget(new TargetFlags()) | 23 ..target = new Dart2jsTarget(new TargetFlags()) |
24 ..packagesFileUri = Platform.script.resolve('../../../.packages') | 24 ..packagesFileUri = Uri.base.resolve('.packages') |
25 ..compileSdk = true | 25 ..compileSdk = true |
26 ..linkedDependencies = [Uri.base.resolve(flags['platform'])] | 26 ..linkedDependencies = [Uri.base.resolve(flags['platform'])] |
27 ..onError = errorHandler; | 27 ..onError = errorHandler; |
28 | 28 |
29 if (flags.rest.isEmpty) { | 29 if (flags.rest.isEmpty) { |
30 var script = relativizeUri(Platform.script); | 30 var script = relativizeUri(Platform.script); |
31 var platform = relativizeUri(Uri.base.resolve(flags['platform'])); | 31 var platform = relativizeUri(Uri.base.resolve(flags['platform'])); |
32 print('usage: ${Platform.executable} $script ' | 32 print('usage: ${Platform.executable} $script ' |
33 '[--platform=$platform] [--out=out.dill] program.dart'); | 33 '[--platform=$platform] [--out=out.dill] program.dart'); |
34 exit(1); | 34 exit(1); |
35 } | 35 } |
36 | 36 |
37 Uri entry = Uri.base.resolve(flags.rest.first); | 37 Uri entry = Uri.base.resolve(flags.rest.first); |
38 var program = await kernelForProgram(entry, options); | 38 var program = await kernelForProgram(entry, options); |
39 program.uriToSource.clear(); | |
40 await writeProgramToBinary(program, flags['out']); | 39 await writeProgramToBinary(program, flags['out']); |
41 } | 40 } |
42 | 41 |
43 void errorHandler(CompilationError e) { | 42 void errorHandler(CompilationError e) { |
44 exitCode = 1; | 43 exitCode = 1; |
45 print(e.message); | 44 print(e.message); |
46 } | 45 } |
47 | 46 |
48 ArgParser _argParser = new ArgParser() | 47 ArgParser _argParser = new ArgParser() |
49 ..addOption('platform', | 48 ..addOption('platform', |
50 help: 'location of the precompiled dart2js sdk', | 49 help: 'location of the precompiled dart2js sdk', |
51 defaultsTo: _defaultPlatform) | 50 defaultsTo: _defaultPlatform) |
52 ..addOption('out', | 51 ..addOption('out', |
53 abbr: 'o', help: 'output location', defaultsTo: 'out.dill'); | 52 abbr: 'o', help: 'output location', defaultsTo: 'out.dill'); |
54 | 53 |
55 String _defaultPlatform = Uri | 54 String _defaultPlatform = Uri |
56 .parse(Platform.resolvedExecutable) | 55 .parse(Platform.resolvedExecutable) |
57 .resolve('patched_dart2js_sdk/platform.dill') | 56 .resolve('patched_dart2js_sdk/platform.dill') |
58 .toString(); | 57 .toString(); |
OLD | NEW |