Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import 'dart:io'; | |
| 6 | |
| 7 /** | |
| 8 * Takes the following arguments: | |
|
ahe
2013/04/10 14:50:08
This documentation comment applies to the followin
| |
| 9 * --output_dir=val The full path to the output_dir. | |
| 10 * --dart2js_main=val The path to the dart2js main script releative to root. | |
| 11 */ | |
| 12 | |
| 13 Future<String> getVersion(var options, var rootPath) { | |
| 14 var versionPath = rootPath.append("tools").append("version.dart"); | |
| 15 return Process.run(options.executable, | |
| 16 [versionPath.toNativePath()]) | |
| 17 .then((result) { | |
| 18 if (result.exitCode != 0) { | |
| 19 throw "Could not generate version"; | |
| 20 } | |
| 21 return result.stdout.trim(); | |
| 22 }); | |
| 23 } | |
| 24 | |
|
ahe
2013/04/10 14:50:08
Extra line.
ricow1
2013/04/11 05:45:12
That really depends if you like 1 or 2 lines betwe
| |
| 25 | |
| 26 Future<String> getSnapshotGenerationFile(var options, var args, var rootPath) { | |
| 27 var dart2js = rootPath.append(args["dart2js_main"]); | |
| 28 | |
| 29 return getVersion(options, rootPath).then((version) { | |
| 30 var snapshotGenerationText = | |
| 31 """ | |
| 32 import '${dart2js}' as dart2jsMain; | |
| 33 import 'dart:io'; | |
| 34 | |
| 35 void main() { | |
| 36 Options options = new Options(); | |
| 37 if (options.arguments.length < 1) throw "No tool given as argument"; | |
| 38 String tool = options.arguments.removeAt(0); | |
| 39 if (tool == "dart2js") { | |
| 40 dart2jsMain.BUILD_ID = "$version"; | |
| 41 dart2jsMain.mainWithErrorHandler(options); | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 """; | |
| 46 return snapshotGenerationText; | |
| 47 }); | |
| 48 } | |
| 49 | |
|
ahe
2013/04/10 14:50:08
Extra line.
ricow1
2013/04/11 05:45:12
Done.
| |
| 50 | |
| 51 void writeSnapshotFile(var path, var content) { | |
| 52 File file = new File(path); | |
|
ahe
2013/04/10 14:50:08
Indentation.
ricow1
2013/04/11 05:45:12
Done.
| |
| 53 var writer = file.openSync(mode: FileMode.WRITE); | |
| 54 writer.writeStringSync(content); | |
| 55 writer.close(); | |
| 56 } | |
| 57 | |
|
ahe
2013/04/10 14:50:08
Extra line.
ricow1
2013/04/11 05:45:12
Done.
| |
| 58 | |
| 59 Future createSnapshot(var options, var dart_file) { | |
| 60 return Process.run(options.executable, | |
| 61 ["--generate-script-snapshot=$dart_file.snapshot", | |
| 62 dart_file]) | |
| 63 .then((result) { | |
| 64 if (result.exitCode != 0) { | |
| 65 throw "Could not generate snapshot"; | |
| 66 } | |
| 67 return; | |
|
ahe
2013/04/10 14:50:08
Remove.
ricow1
2013/04/11 05:45:12
Done.
| |
| 68 }); | |
| 69 } | |
| 70 | |
| 71 void main() { | |
| 72 Options options = new Options(); | |
| 73 var validArguments = ["--output_dir", "--dart2js_main"]; | |
| 74 var args = {}; | |
| 75 for (var argument in options.arguments) { | |
| 76 var argumentSplit = argument.split("="); | |
| 77 if (argumentSplit.length != 2) throw "Invalid argument $argument, no ="; | |
| 78 if (!validArguments.contains(argumentSplit[0])) { | |
| 79 throw "Invalid argument $argument"; | |
| 80 } | |
| 81 args[argumentSplit[0].substring(2)] = argumentSplit[1]; | |
| 82 } | |
| 83 if (!args.containsKey("dart2js_main")) throw "Please specify dart2js_main"; | |
| 84 if (!args.containsKey("output_dir")) throw "Please specify output_dir"; | |
| 85 | |
| 86 var scriptFile = new File(options.script); | |
| 87 var path = new Path(scriptFile.directorySync().path); | |
| 88 var rootPath = path.directoryPath.directoryPath; | |
| 89 | |
| 90 getSnapshotGenerationFile(options, args, rootPath).then((result) { | |
| 91 var wrapper = "${args['output_dir']}/utils_wrapper.dart"; | |
| 92 writeSnapshotFile(wrapper, result); | |
| 93 createSnapshot(options, wrapper); | |
| 94 }); | |
| 95 } | |
| OLD | NEW |