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