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