Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: utils/compiler/create_snapshot.dart

Issue 16357003: Revert revision 23575. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/compiler/compiler.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 os = Platform.operatingSystem; 8 var os = Platform.operatingSystem;
9 var suffix = os == 'windows' ? '.exe' : ''; 9 var suffix = os == 'windows' ? '.exe' : '';
10 var checkedInBinary = 10 var checkedInBinary =
11 rootPath.join(new Path('tools/testing/bin/$os/dart$suffix')); 11 rootPath.join(new Path('tools/testing/bin/$os/dart$suffix'));
12 var versionPath = rootPath.append("tools").append("version.dart"); 12 var versionPath = rootPath.append("tools").append("version.dart");
13 return Process.run(checkedInBinary.toNativePath(), 13 return Process.run(checkedInBinary.toNativePath(),
14 [versionPath.toNativePath()]) 14 [versionPath.toNativePath()])
15 .then((result) { 15 .then((result) {
16 if (result.exitCode != 0) { 16 if (result.exitCode != 0) {
17 throw "Could not generate version"; 17 throw "Could not generate version";
18 } 18 }
19 return result.stdout.trim(); 19 return result.stdout.trim();
20 }); 20 });
21 } 21 }
22 22
23 Future<String> getSnapshotGenerationFile(var options, var args, var rootPath) { 23 Future<String> getSnapshotGenerationFile(var options, var args, var rootPath) {
24 var dart2js = rootPath.append(args["dart2js_main"]); 24 var dart2js = rootPath.append(args["dart2js_main"]);
25 var dartdoc = rootPath.append(args["dartdoc_main"]);
26 25
27 return getVersion(options, rootPath).then((version) { 26 return getVersion(options, rootPath).then((version) {
28 var snapshotGenerationText = 27 var snapshotGenerationText =
29 """ 28 """
30 import '${dart2js}' as dart2jsMain; 29 import '${dart2js}' as dart2jsMain;
31 import '${dartdoc}' as dartdocMain;
32 import 'dart:io'; 30 import 'dart:io';
33 31
34 void main() { 32 void main() {
35 Options options = new Options(); 33 Options options = new Options();
36 if (options.arguments.length < 1) throw "No tool given as argument"; 34 if (options.arguments.length < 1) throw "No tool given as argument";
37 String tool = options.arguments.removeAt(0); 35 String tool = options.arguments.removeAt(0);
38 if (tool == "dart2js") { 36 if (tool == "dart2js") {
39 dart2jsMain.BUILD_ID = "$version"; 37 dart2jsMain.BUILD_ID = "$version";
40 dart2jsMain.mainWithErrorHandler(options); 38 dart2jsMain.mainWithErrorHandler(options);
41 } else if (tool == "dartdoc") {
42 dartdocMain.mainWithOptions(options);
43 } 39 }
44 } 40 }
45 41
46 """; 42 """;
47 return snapshotGenerationText; 43 return snapshotGenerationText;
48 }); 44 });
49 } 45 }
50 46
51 void writeSnapshotFile(var path, var content) { 47 void writeSnapshotFile(var path, var content) {
52 File file = new File(path); 48 File file = new File(path);
53 var writer = file.openSync(mode: FileMode.WRITE); 49 var writer = file.openSync(mode: FileMode.WRITE);
54 writer.writeStringSync(content); 50 writer.writeStringSync(content);
55 writer.close(); 51 writer.close();
56 } 52 }
57 53
58 Future createSnapshot(var options, var dart_file, var packageRoot) { 54 Future createSnapshot(var options, var dart_file) {
59 return Process.run(options.executable, 55 return Process.run(options.executable,
60 ["--package-root=$packageRoot", 56 ["--generate-script-snapshot=$dart_file.snapshot",
61 "--generate-script-snapshot=$dart_file.snapshot",
62 dart_file]) 57 dart_file])
63 .then((result) { 58 .then((result) {
64 if (result.exitCode != 0) { 59 if (result.exitCode != 0) {
65 throw "Could not generate snapshot"; 60 throw "Could not generate snapshot";
66 } 61 }
67 }); 62 });
68 } 63 }
69 64
70 /** 65 /**
71 * Takes the following arguments: 66 * Takes the following arguments:
72 * --output_dir=val The full path to the output_dir. 67 * --output_dir=val The full path to the output_dir.
73 * --dart2js_main=val The path to the dart2js main script releative to root. 68 * --dart2js_main=val The path to the dart2js main script releative to root.
74 */ 69 */
75 void main() { 70 void main() {
76 Options options = new Options(); 71 Options options = new Options();
77 var validArguments = ["--output_dir", "--dart2js_main", "--dartdoc_main", 72 var validArguments = ["--output_dir", "--dart2js_main"];
78 "--package_root"];
79 var args = {}; 73 var args = {};
80 for (var argument in options.arguments) { 74 for (var argument in options.arguments) {
81 var argumentSplit = argument.split("="); 75 var argumentSplit = argument.split("=");
82 if (argumentSplit.length != 2) throw "Invalid argument $argument, no ="; 76 if (argumentSplit.length != 2) throw "Invalid argument $argument, no =";
83 if (!validArguments.contains(argumentSplit[0])) { 77 if (!validArguments.contains(argumentSplit[0])) {
84 throw "Invalid argument $argument"; 78 throw "Invalid argument $argument";
85 } 79 }
86 args[argumentSplit[0].substring(2)] = argumentSplit[1]; 80 args[argumentSplit[0].substring(2)] = argumentSplit[1];
87 } 81 }
88 if (!args.containsKey("dart2js_main")) throw "Please specify dart2js_main"; 82 if (!args.containsKey("dart2js_main")) throw "Please specify dart2js_main";
89 if (!args.containsKey("dartdoc_main")) throw "Please specify dartdoc_main";
90 if (!args.containsKey("output_dir")) throw "Please specify output_dir"; 83 if (!args.containsKey("output_dir")) throw "Please specify output_dir";
91 if (!args.containsKey("package_root")) throw "Please specify package_root";
92 84
93 var scriptFile = new File(new File(options.script).fullPathSync()); 85 var scriptFile = new File(new File(options.script).fullPathSync());
94 var path = new Path(scriptFile.directory.path); 86 var path = new Path(scriptFile.directory.path);
95 var rootPath = path.directoryPath.directoryPath; 87 var rootPath = path.directoryPath.directoryPath;
96 getSnapshotGenerationFile(options, args, rootPath).then((result) { 88 getSnapshotGenerationFile(options, args, rootPath).then((result) {
97 var wrapper = "${args['output_dir']}/utils_wrapper.dart"; 89 var wrapper = "${args['output_dir']}/utils_wrapper.dart";
98 writeSnapshotFile(wrapper, result); 90 writeSnapshotFile(wrapper, result);
99 createSnapshot(options, wrapper, args["package_root"]); 91 createSnapshot(options, wrapper);
100 }); 92 });
101 } 93 }
OLDNEW
« no previous file with comments | « utils/compiler/compiler.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698