| 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 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 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 docgen = rootPath.resolve(args["docgen_main"]); | |
| 22 return getVersion(rootPath).then((version) { | 21 return getVersion(rootPath).then((version) { |
| 23 var snapshotGenerationText = | 22 var snapshotGenerationText = |
| 24 """ | 23 """ |
| 25 import '${dart2js.toFilePath(windows: false)}' as dart2jsMain; | 24 import '${dart2js.toFilePath(windows: false)}' as dart2jsMain; |
| 26 import '${docgen.toFilePath(windows: false)}' as docgenMain; | |
| 27 import 'dart:io'; | 25 import 'dart:io'; |
| 28 | 26 |
| 29 void main(List<String> arguments) { | 27 void main(List<String> arguments) { |
| 30 if (arguments.length < 1) throw "No tool given as argument"; | 28 if (arguments.length < 1) throw "No tool given as argument"; |
| 31 String tool = arguments[0]; | 29 String tool = arguments[0]; |
| 32 if (tool == "dart2js") { | 30 if (tool == "dart2js") { |
| 33 dart2jsMain.BUILD_ID = "$version"; | 31 dart2jsMain.BUILD_ID = "$version"; |
| 34 dart2jsMain.main(arguments.skip(1).toList()); | 32 dart2jsMain.main(arguments.skip(1).toList()); |
| 35 } else if (tool == "docgen") { | |
| 36 docgenMain.main(arguments.skip(1).toList()); | |
| 37 } | 33 } |
| 38 } | 34 } |
| 39 | 35 |
| 40 """; | 36 """; |
| 41 return snapshotGenerationText; | 37 return snapshotGenerationText; |
| 42 }); | 38 }); |
| 43 } | 39 } |
| 44 | 40 |
| 45 Future<String> getDart2jsSnapshotGenerationFile(var args, var rootPath) { | 41 Future<String> getDart2jsSnapshotGenerationFile(var args, var rootPath) { |
| 46 var dart2js = rootPath.resolve(args["dart2js_main"]); | 42 var dart2js = rootPath.resolve(args["dart2js_main"]); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 77 print(result.stderr); | 73 print(result.stderr); |
| 78 throw "Could not generate snapshot"; | 74 throw "Could not generate snapshot"; |
| 79 } | 75 } |
| 80 }); | 76 }); |
| 81 } | 77 } |
| 82 | 78 |
| 83 /** | 79 /** |
| 84 * Takes the following arguments: | 80 * Takes the following arguments: |
| 85 * --output_dir=val The full path to the output_dir. | 81 * --output_dir=val The full path to the output_dir. |
| 86 * --dart2js_main=val The path to the dart2js main script relative to root. | 82 * --dart2js_main=val The path to the dart2js main script relative to root. |
| 87 * --docgen_main=val The path to the docgen main script relative to root. | |
| 88 * --package-root=val The package-root used to find packages for the snapshot. | 83 * --package-root=val The package-root used to find packages for the snapshot. |
| 89 */ | 84 */ |
| 90 void main(List<String> arguments) { | 85 void main(List<String> arguments) { |
| 91 var validArguments = ["--output_dir", "--dart2js_main", | 86 var validArguments = ["--output_dir", "--dart2js_main", |
| 92 "--docgen_main", "--package_root"]; | 87 "--package_root"]; |
| 93 var args = {}; | 88 var args = {}; |
| 94 for (var argument in arguments) { | 89 for (var argument in arguments) { |
| 95 var argumentSplit = argument.split("="); | 90 var argumentSplit = argument.split("="); |
| 96 if (argumentSplit.length != 2) throw "Invalid argument $argument, no ="; | 91 if (argumentSplit.length != 2) throw "Invalid argument $argument, no ="; |
| 97 if (!validArguments.contains(argumentSplit[0])) { | 92 if (!validArguments.contains(argumentSplit[0])) { |
| 98 throw "Invalid argument $argument"; | 93 throw "Invalid argument $argument"; |
| 99 } | 94 } |
| 100 args[argumentSplit[0].substring(2)] = argumentSplit[1]; | 95 args[argumentSplit[0].substring(2)] = argumentSplit[1]; |
| 101 } | 96 } |
| 102 if (!args.containsKey("dart2js_main")) throw "Please specify dart2js_main"; | 97 if (!args.containsKey("dart2js_main")) throw "Please specify dart2js_main"; |
| 103 if (!args.containsKey("docgen_main")) throw "Please specify docgen_main"; | |
| 104 if (!args.containsKey("output_dir")) throw "Please specify output_dir"; | 98 if (!args.containsKey("output_dir")) throw "Please specify output_dir"; |
| 105 if (!args.containsKey("package_root")) throw "Please specify package_root"; | 99 if (!args.containsKey("package_root")) throw "Please specify package_root"; |
| 106 | 100 |
| 107 var scriptFile = Uri.base.resolveUri(Platform.script); | 101 var scriptFile = Uri.base.resolveUri(Platform.script); |
| 108 var path = scriptFile.resolve("."); | 102 var path = scriptFile.resolve("."); |
| 109 var rootPath = path.resolve("../.."); | 103 var rootPath = path.resolve("../.."); |
| 110 getSnapshotGenerationFile(args, rootPath).then((result) { | 104 getSnapshotGenerationFile(args, rootPath).then((result) { |
| 111 var wrapper = "${args['output_dir']}/utils_wrapper.dart"; | 105 var wrapper = "${args['output_dir']}/utils_wrapper.dart"; |
| 112 writeSnapshotFile(wrapper, result); | 106 writeSnapshotFile(wrapper, result); |
| 113 createSnapshot(wrapper, args["package_root"]); | 107 createSnapshot(wrapper, args["package_root"]); |
| 114 }); | 108 }); |
| 115 | 109 |
| 116 getDart2jsSnapshotGenerationFile(args, rootPath).then((result) { | 110 getDart2jsSnapshotGenerationFile(args, rootPath).then((result) { |
| 117 var wrapper = "${args['output_dir']}/dart2js.dart"; | 111 var wrapper = "${args['output_dir']}/dart2js.dart"; |
| 118 writeSnapshotFile(wrapper, result); | 112 writeSnapshotFile(wrapper, result); |
| 119 createSnapshot(wrapper, args["package_root"]); | 113 createSnapshot(wrapper, args["package_root"]); |
| 120 }); | 114 }); |
| 121 | 115 |
| 122 } | 116 } |
| OLD | NEW |