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"]); | 21 var dartdoc = rootPath.resolve(args["dartdoc_main"]); |
22 return getVersion(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; |
kasperl
2013/11/10 11:41:18
Is this dead code? You shouldn't remove it now but
ricow1
2013/11/10 12:02:00
Yes this is dead code (and it is probably making d
| |
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(List<String> arguments) { | 29 void main(List<String> arguments) { |
30 if (arguments.length < 1) throw "No tool given as argument"; | 30 if (arguments.length < 1) throw "No tool given as argument"; |
31 String tool = arguments[0]; | 31 String tool = arguments[0]; |
32 if (tool == "dart2js") { | 32 if (tool == "dart2js") { |
33 dart2jsMain.BUILD_ID = "$version"; | 33 dart2jsMain.BUILD_ID = "$version"; |
34 dart2jsMain.main(arguments.skip(1).toList()); | 34 dart2jsMain.main(arguments.skip(1).toList()); |
35 } else if (tool == "dartdoc") { | 35 } else if (tool == "dartdoc") { |
36 dartdocMain.main(arguments.skip(1).toList()); | 36 dartdocMain.main(arguments.skip(1).toList()); |
37 } | 37 } |
38 } | 38 } |
39 | 39 |
40 """; | 40 """; |
41 return snapshotGenerationText; | 41 return snapshotGenerationText; |
42 }); | 42 }); |
43 } | 43 } |
44 | 44 |
45 Future<String> getDart2jsSnapshotGenerationFile(var args, var rootPath) { | |
46 var dart2js = rootPath.resolve(args["dart2js_main"]); | |
47 return getVersion(rootPath).then((version) { | |
48 var snapshotGenerationText = | |
49 """ | |
50 import '${dart2js.toFilePath(windows: false)}' as dart2jsMain; | |
51 import 'dart:io'; | |
52 | |
53 void main(List<String> arguments) { | |
54 dart2jsMain.BUILD_ID = "$version"; | |
kasperl
2013/11/10 11:41:18
Less indentation.
ricow1
2013/11/10 12:02:00
Done.
| |
55 dart2jsMain.main(arguments.skip(1).toList()); | |
56 } | |
57 """; | |
58 return snapshotGenerationText; | |
59 }); | |
60 } | |
61 | |
45 void writeSnapshotFile(var path, var content) { | 62 void writeSnapshotFile(var path, var content) { |
46 File file = new File(path); | 63 File file = new File(path); |
47 var writer = file.openSync(mode: FileMode.WRITE); | 64 var writer = file.openSync(mode: FileMode.WRITE); |
48 writer.writeStringSync(content); | 65 writer.writeStringSync(content); |
49 writer.close(); | 66 writer.close(); |
50 } | 67 } |
51 | 68 |
52 Future createSnapshot(var dart_file, var packageRoot) { | 69 Future createSnapshot(var dart_file, var packageRoot) { |
53 return Process.run(Platform.executable, | 70 return Process.run(Platform.executable, |
54 ["--package-root=$packageRoot", | 71 ["--package-root=$packageRoot", |
(...skipping 29 matching lines...) Expand all Loading... | |
84 if (!args.containsKey("package_root")) throw "Please specify package_root"; | 101 if (!args.containsKey("package_root")) throw "Please specify package_root"; |
85 | 102 |
86 var scriptFile = Uri.base.resolveUri(Platform.script); | 103 var scriptFile = Uri.base.resolveUri(Platform.script); |
87 var path = scriptFile.resolve("."); | 104 var path = scriptFile.resolve("."); |
88 var rootPath = path.resolve("../.."); | 105 var rootPath = path.resolve("../.."); |
89 getSnapshotGenerationFile(args, rootPath).then((result) { | 106 getSnapshotGenerationFile(args, rootPath).then((result) { |
90 var wrapper = "${args['output_dir']}/utils_wrapper.dart"; | 107 var wrapper = "${args['output_dir']}/utils_wrapper.dart"; |
91 writeSnapshotFile(wrapper, result); | 108 writeSnapshotFile(wrapper, result); |
92 createSnapshot(wrapper, args["package_root"]); | 109 createSnapshot(wrapper, args["package_root"]); |
93 }); | 110 }); |
111 | |
112 getDart2jsSnapshotGenerationFile(args, rootPath).then((result) { | |
113 var wrapper = "${args['output_dir']}/dart2js.dart"; | |
114 writeSnapshotFile(wrapper, result); | |
115 createSnapshot(wrapper, args["package_root"]); | |
116 }); | |
117 | |
94 } | 118 } |
OLD | NEW |