OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import 'dart:io'; | 5 import 'dart:io'; |
6 | 6 |
7 Future<String> getVersion(var options, var rootPath) { | 7 Future<String> getVersion(var rootPath) { |
8 var suffix = Platform.operatingSystem == 'windows' ? '.exe' : ''; | 8 var suffix = Platform.operatingSystem == 'windows' ? '.exe' : ''; |
9 var printVersionScript = rootPath.resolve("tools/print_version.py"); | 9 var printVersionScript = rootPath.resolve("tools/print_version.py"); |
10 return Process.run("python$suffix", | 10 return Process.run("python$suffix", |
11 [printVersionScript.toFilePath()]).then((result) { | 11 [printVersionScript.toFilePath()]).then((result) { |
12 if (result.exitCode != 0) { | 12 if (result.exitCode != 0) { |
13 throw "Could not generate version"; | 13 throw "Could not generate version"; |
14 } | 14 } |
15 return result.stdout.trim(); | 15 return result.stdout.trim(); |
16 }); | 16 }); |
17 } | 17 } |
18 | 18 |
19 Future<String> getSnapshotGenerationFile(var options, var args, var rootPath) { | 19 Future<String> getSnapshotGenerationFile(var args, var rootPath) { |
20 var dart2js = rootPath.resolve(args["dart2js_main"]); | 20 var dart2js = rootPath.resolve(args["dart2js_main"]); |
21 var dartdoc = rootPath.resolve(args["dartdoc_main"]); | 21 var dartdoc = rootPath.resolve(args["dartdoc_main"]); |
22 return getVersion(options, rootPath).then((version) { | 22 return getVersion(rootPath).then((version) { |
23 var snapshotGenerationText = | 23 var snapshotGenerationText = |
24 """ | 24 """ |
25 import '${dart2js.toFilePath(windows: false)}' as dart2jsMain; | 25 import '${dart2js.toFilePath(windows: false)}' as dart2jsMain; |
26 import '${dartdoc.toFilePath(windows: false)}' as dartdocMain; | 26 import '${dartdoc.toFilePath(windows: false)}' as dartdocMain; |
27 import 'dart:io'; | 27 import 'dart:io'; |
28 | 28 |
29 void main() { | 29 void main(List<String> arguments) { |
30 Options options = new Options(); | 30 if (arguments.length < 1) throw "No tool given as argument"; |
31 if (options.arguments.length < 1) throw "No tool given as argument"; | 31 String tool = arguments[0]; |
32 String tool = options.arguments.removeAt(0); | |
33 if (tool == "dart2js") { | 32 if (tool == "dart2js") { |
34 dart2jsMain.BUILD_ID = "$version"; | 33 dart2jsMain.BUILD_ID = "$version"; |
35 dart2jsMain.mainWithErrorHandler(options); | 34 dart2jsMain.main(arguments.skip(1).toList()); |
36 } else if (tool == "dartdoc") { | 35 } else if (tool == "dartdoc") { |
37 dartdocMain.mainWithOptions(options); | 36 dartdocMain.main(arguments.skip(1).toList()); |
38 } | 37 } |
39 } | 38 } |
40 | 39 |
41 """; | 40 """; |
42 return snapshotGenerationText; | 41 return snapshotGenerationText; |
43 }); | 42 }); |
44 } | 43 } |
45 | 44 |
46 void writeSnapshotFile(var path, var content) { | 45 void writeSnapshotFile(var path, var content) { |
47 File file = new File(path); | 46 File file = new File(path); |
48 var writer = file.openSync(mode: FileMode.WRITE); | 47 var writer = file.openSync(mode: FileMode.WRITE); |
49 writer.writeStringSync(content); | 48 writer.writeStringSync(content); |
50 writer.close(); | 49 writer.close(); |
51 } | 50 } |
52 | 51 |
53 Future createSnapshot(var options, var dart_file, var packageRoot) { | 52 Future createSnapshot(var dart_file, var packageRoot) { |
54 return Process.run(options.executable, | 53 return Process.run(Platform.executable, |
55 ["--package-root=$packageRoot", | 54 ["--package-root=$packageRoot", |
56 "--snapshot=$dart_file.snapshot", | 55 "--snapshot=$dart_file.snapshot", |
57 dart_file]) | 56 dart_file]) |
58 .then((result) { | 57 .then((result) { |
59 if (result.exitCode != 0) { | 58 if (result.exitCode != 0) { |
60 throw "Could not generate snapshot"; | 59 throw "Could not generate snapshot"; |
61 } | 60 } |
62 }); | 61 }); |
63 } | 62 } |
64 | 63 |
65 /** | 64 /** |
66 * Takes the following arguments: | 65 * Takes the following arguments: |
67 * --output_dir=val The full path to the output_dir. | 66 * --output_dir=val The full path to the output_dir. |
68 * --dart2js_main=val The path to the dart2js main script releative to root. | 67 * --dart2js_main=val The path to the dart2js main script releative to root. |
69 */ | 68 */ |
70 void main() { | 69 void main(List<String> arguments) { |
71 Options options = new Options(); | |
72 var validArguments = ["--output_dir", "--dart2js_main", "--dartdoc_main", | 70 var validArguments = ["--output_dir", "--dart2js_main", "--dartdoc_main", |
73 "--package_root"]; | 71 "--package_root"]; |
74 var args = {}; | 72 var args = {}; |
75 for (var argument in options.arguments) { | 73 for (var argument in arguments) { |
76 var argumentSplit = argument.split("="); | 74 var argumentSplit = argument.split("="); |
77 if (argumentSplit.length != 2) throw "Invalid argument $argument, no ="; | 75 if (argumentSplit.length != 2) throw "Invalid argument $argument, no ="; |
78 if (!validArguments.contains(argumentSplit[0])) { | 76 if (!validArguments.contains(argumentSplit[0])) { |
79 throw "Invalid argument $argument"; | 77 throw "Invalid argument $argument"; |
80 } | 78 } |
81 args[argumentSplit[0].substring(2)] = argumentSplit[1]; | 79 args[argumentSplit[0].substring(2)] = argumentSplit[1]; |
82 } | 80 } |
83 if (!args.containsKey("dart2js_main")) throw "Please specify dart2js_main"; | 81 if (!args.containsKey("dart2js_main")) throw "Please specify dart2js_main"; |
84 if (!args.containsKey("dartdoc_main")) throw "Please specify dartdoc_main"; | 82 if (!args.containsKey("dartdoc_main")) throw "Please specify dartdoc_main"; |
85 if (!args.containsKey("output_dir")) throw "Please specify output_dir"; | 83 if (!args.containsKey("output_dir")) throw "Please specify output_dir"; |
86 if (!args.containsKey("package_root")) throw "Please specify package_root"; | 84 if (!args.containsKey("package_root")) throw "Please specify package_root"; |
87 | 85 |
88 var scriptFile = new Uri.file(new File(options.script).fullPathSync()); | 86 var scriptFile = new Uri.file(new File(Platform.script).fullPathSync()); |
89 var path = scriptFile.resolve("."); | 87 var path = scriptFile.resolve("."); |
90 var rootPath = path.resolve("../.."); | 88 var rootPath = path.resolve("../.."); |
91 getSnapshotGenerationFile(options, args, rootPath).then((result) { | 89 getSnapshotGenerationFile(args, rootPath).then((result) { |
92 var wrapper = "${args['output_dir']}/utils_wrapper.dart"; | 90 var wrapper = "${args['output_dir']}/utils_wrapper.dart"; |
93 writeSnapshotFile(wrapper, result); | 91 writeSnapshotFile(wrapper, result); |
94 createSnapshot(options, wrapper, args["package_root"]); | 92 createSnapshot(wrapper, args["package_root"]); |
95 }); | 93 }); |
96 } | 94 } |
OLD | NEW |