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 |
11 [printVersionScript.toFilePath()]).then((result) { | 11 .run("python$suffix", [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 return getVersion(rootPath).then((version) { | 21 return getVersion(rootPath).then((version) { |
22 var snapshotGenerationText = | 22 var snapshotGenerationText = """ |
23 """ | |
24 import '${dart2js.toFilePath(windows: false)}' as dart2jsMain; | 23 import '${dart2js.toFilePath(windows: false)}' as dart2jsMain; |
25 import 'dart:io'; | 24 import 'dart:io'; |
26 | 25 |
27 void main(List<String> arguments) { | 26 void main(List<String> arguments) { |
28 if (arguments.length < 1) throw "No tool given as argument"; | 27 if (arguments.length < 1) throw "No tool given as argument"; |
29 String tool = arguments[0]; | 28 String tool = arguments[0]; |
30 if (tool == "dart2js") { | 29 if (tool == "dart2js") { |
31 dart2jsMain.BUILD_ID = "$version"; | 30 dart2jsMain.BUILD_ID = "$version"; |
32 dart2jsMain.main(arguments.skip(1).toList()); | 31 dart2jsMain.main(arguments.skip(1).toList()); |
33 } | 32 } |
34 } | 33 } |
35 | 34 |
36 """; | 35 """; |
37 return snapshotGenerationText; | 36 return snapshotGenerationText; |
38 }); | 37 }); |
39 } | 38 } |
40 | 39 |
41 Future<String> getDart2jsSnapshotGenerationFile(var args, var rootPath) { | 40 Future<String> getDart2jsSnapshotGenerationFile(var args, var rootPath) { |
42 var dart2js = rootPath.resolve(args["dart2js_main"]); | 41 var dart2js = rootPath.resolve(args["dart2js_main"]); |
43 return getVersion(rootPath).then((version) { | 42 return getVersion(rootPath).then((version) { |
44 var snapshotGenerationText = | 43 var snapshotGenerationText = """ |
45 """ | |
46 import '${dart2js.toFilePath(windows: false)}' as dart2jsMain; | 44 import '${dart2js.toFilePath(windows: false)}' as dart2jsMain; |
47 | 45 |
48 void main(List<String> arguments) { | 46 void main(List<String> arguments) { |
49 dart2jsMain.BUILD_ID = "$version"; | 47 dart2jsMain.BUILD_ID = "$version"; |
50 dart2jsMain.main(arguments); | 48 dart2jsMain.main(arguments); |
51 } | 49 } |
52 """; | 50 """; |
53 return snapshotGenerationText; | 51 return snapshotGenerationText; |
54 }); | 52 }); |
55 } | 53 } |
56 | 54 |
57 void writeSnapshotFile(var path, var content) { | 55 void writeSnapshotFile(var path, var content) { |
58 File file = new File(path); | 56 File file = new File(path); |
59 var writer = file.openSync(mode: FileMode.WRITE); | 57 var writer = file.openSync(mode: FileMode.WRITE); |
60 writer.writeStringSync(content); | 58 writer.writeStringSync(content); |
61 writer.close(); | 59 writer.close(); |
62 } | 60 } |
63 | 61 |
64 Future createSnapshot(var dart_file) { | 62 Future createSnapshot(var dart_file) { |
65 return Process.run(Platform.executable, | 63 return Process.run(Platform.executable, [ |
66 ["--packages=../../.packages", | 64 "--packages=../../.packages", |
67 "--snapshot=$dart_file.snapshot", | 65 "--snapshot=$dart_file.snapshot", |
68 dart_file]) | 66 dart_file |
69 .then((result) { | 67 ]).then((result) { |
70 if (result.exitCode != 0) { | 68 if (result.exitCode != 0) { |
71 print("Could not generate snapshot: result code ${result.exitCode}"); | 69 print("Could not generate snapshot: result code ${result.exitCode}"); |
72 print(result.stdout); | 70 print(result.stdout); |
73 print(result.stderr); | 71 print(result.stderr); |
74 throw "Could not generate snapshot"; | 72 throw "Could not generate snapshot"; |
75 } | 73 } |
76 }); | 74 }); |
77 } | 75 } |
78 | 76 |
79 /** | 77 /** |
80 * Takes the following arguments: | 78 * Takes the following arguments: |
81 * --output_dir=val The full path to the output_dir. | 79 * --output_dir=val The full path to the output_dir. |
82 * --dart2js_main=val The path to the dart2js main script relative to root. | 80 * --dart2js_main=val The path to the dart2js main script relative to root. |
83 */ | 81 */ |
84 void main(List<String> arguments) { | 82 void main(List<String> arguments) { |
85 var validArguments = ["--output_dir", "--dart2js_main"]; | 83 var validArguments = ["--output_dir", "--dart2js_main"]; |
86 var args = {}; | 84 var args = {}; |
(...skipping 15 matching lines...) Expand all Loading... |
102 var wrapper = "${args['output_dir']}/utils_wrapper.dart"; | 100 var wrapper = "${args['output_dir']}/utils_wrapper.dart"; |
103 writeSnapshotFile(wrapper, result); | 101 writeSnapshotFile(wrapper, result); |
104 createSnapshot(wrapper); | 102 createSnapshot(wrapper); |
105 }); | 103 }); |
106 | 104 |
107 getDart2jsSnapshotGenerationFile(args, rootPath).then((result) { | 105 getDart2jsSnapshotGenerationFile(args, rootPath).then((result) { |
108 var wrapper = "${args['output_dir']}/dart2js.dart"; | 106 var wrapper = "${args['output_dir']}/dart2js.dart"; |
109 writeSnapshotFile(wrapper, result); | 107 writeSnapshotFile(wrapper, result); |
110 createSnapshot(wrapper); | 108 createSnapshot(wrapper); |
111 }); | 109 }); |
112 | |
113 } | 110 } |
OLD | NEW |