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", |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 }); | 54 }); |
55 } | 55 } |
56 | 56 |
57 void writeSnapshotFile(var path, var content) { | 57 void writeSnapshotFile(var path, var content) { |
58 File file = new File(path); | 58 File file = new File(path); |
59 var writer = file.openSync(mode: FileMode.WRITE); | 59 var writer = file.openSync(mode: FileMode.WRITE); |
60 writer.writeStringSync(content); | 60 writer.writeStringSync(content); |
61 writer.close(); | 61 writer.close(); |
62 } | 62 } |
63 | 63 |
64 Future createSnapshot(var dart_file, var packageRoot) { | 64 Future createSnapshot(var dart_file) { |
65 return Process.run(Platform.executable, | 65 return Process.run(Platform.executable, |
66 ["--package-root=$packageRoot", | 66 ["--snapshot=$dart_file.snapshot", |
67 "--snapshot=$dart_file.snapshot", | |
68 dart_file]) | 67 dart_file]) |
69 .then((result) { | 68 .then((result) { |
70 if (result.exitCode != 0) { | 69 if (result.exitCode != 0) { |
71 print("Could not generate snapshot: result code ${result.exitCode}"); | 70 print("Could not generate snapshot: result code ${result.exitCode}"); |
72 print(result.stdout); | 71 print(result.stdout); |
73 print(result.stderr); | 72 print(result.stderr); |
74 throw "Could not generate snapshot"; | 73 throw "Could not generate snapshot"; |
75 } | 74 } |
76 }); | 75 }); |
77 } | 76 } |
78 | 77 |
79 /** | 78 /** |
80 * Takes the following arguments: | 79 * Takes the following arguments: |
81 * --output_dir=val The full path to the output_dir. | 80 * --output_dir=val The full path to the output_dir. |
82 * --dart2js_main=val The path to the dart2js main script relative to root. | 81 * --dart2js_main=val The path to the dart2js main script relative to root. |
83 * --package-root=val The package-root used to find packages for the snapshot. | |
84 */ | 82 */ |
85 void main(List<String> arguments) { | 83 void main(List<String> arguments) { |
86 var validArguments = ["--output_dir", "--dart2js_main", | 84 var validArguments = ["--output_dir", "--dart2js_main"]; |
87 "--package_root"]; | |
88 var args = {}; | 85 var args = {}; |
89 for (var argument in arguments) { | 86 for (var argument in arguments) { |
90 var argumentSplit = argument.split("="); | 87 var argumentSplit = argument.split("="); |
91 if (argumentSplit.length != 2) throw "Invalid argument $argument, no ="; | 88 if (argumentSplit.length != 2) throw "Invalid argument $argument, no ="; |
92 if (!validArguments.contains(argumentSplit[0])) { | 89 if (!validArguments.contains(argumentSplit[0])) { |
93 throw "Invalid argument $argument"; | 90 throw "Invalid argument $argument"; |
94 } | 91 } |
95 args[argumentSplit[0].substring(2)] = argumentSplit[1]; | 92 args[argumentSplit[0].substring(2)] = argumentSplit[1]; |
96 } | 93 } |
97 if (!args.containsKey("dart2js_main")) throw "Please specify dart2js_main"; | 94 if (!args.containsKey("dart2js_main")) throw "Please specify dart2js_main"; |
98 if (!args.containsKey("output_dir")) throw "Please specify output_dir"; | 95 if (!args.containsKey("output_dir")) throw "Please specify output_dir"; |
99 if (!args.containsKey("package_root")) throw "Please specify package_root"; | |
100 | 96 |
101 var scriptFile = Uri.base.resolveUri(Platform.script); | 97 var scriptFile = Uri.base.resolveUri(Platform.script); |
102 var path = scriptFile.resolve("."); | 98 var path = scriptFile.resolve("."); |
103 var rootPath = path.resolve("../.."); | 99 var rootPath = path.resolve("../.."); |
104 getSnapshotGenerationFile(args, rootPath).then((result) { | 100 getSnapshotGenerationFile(args, rootPath).then((result) { |
105 var wrapper = "${args['output_dir']}/utils_wrapper.dart"; | 101 var wrapper = "${args['output_dir']}/utils_wrapper.dart"; |
106 writeSnapshotFile(wrapper, result); | 102 writeSnapshotFile(wrapper, result); |
107 createSnapshot(wrapper, args["package_root"]); | 103 createSnapshot(wrapper); |
108 }); | 104 }); |
109 | 105 |
110 getDart2jsSnapshotGenerationFile(args, rootPath).then((result) { | 106 getDart2jsSnapshotGenerationFile(args, rootPath).then((result) { |
111 var wrapper = "${args['output_dir']}/dart2js.dart"; | 107 var wrapper = "${args['output_dir']}/dart2js.dart"; |
112 writeSnapshotFile(wrapper, result); | 108 writeSnapshotFile(wrapper, result); |
113 createSnapshot(wrapper, args["package_root"]); | 109 createSnapshot(wrapper); |
114 }); | 110 }); |
115 | 111 |
116 } | 112 } |
OLD | NEW |