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

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

Issue 116043013: Add a snapshot for docgen and use it in the build (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Everything except the strictly snapshot-related pulled out to a different CL Created 6 years, 11 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
« utils/compiler/compiler.gyp ('K') | « 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 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 var docgen = rootPath.resolve(args["docgen_main"]);
22 return getVersion(rootPath).then((version) { 23 return getVersion(rootPath).then((version) {
23 var snapshotGenerationText = 24 var snapshotGenerationText =
24 """ 25 """
25 import '${dart2js.toFilePath(windows: false)}' as dart2jsMain; 26 import '${dart2js.toFilePath(windows: false)}' as dart2jsMain;
26 import '${dartdoc.toFilePath(windows: false)}' as dartdocMain; 27 import '${dartdoc.toFilePath(windows: false)}' as dartdocMain;
ricow1 2014/01/21 00:52:16 remove dartdoc
28 import '${docgen.toFilePath(windows: false)}' as docgenMain;
27 import 'dart:io'; 29 import 'dart:io';
28 30
29 void main(List<String> arguments) { 31 void main(List<String> arguments) {
30 if (arguments.length < 1) throw "No tool given as argument"; 32 if (arguments.length < 1) throw "No tool given as argument";
31 String tool = arguments[0]; 33 String tool = arguments[0];
32 if (tool == "dart2js") { 34 if (tool == "dart2js") {
33 dart2jsMain.BUILD_ID = "$version"; 35 dart2jsMain.BUILD_ID = "$version";
34 dart2jsMain.main(arguments.skip(1).toList()); 36 dart2jsMain.main(arguments.skip(1).toList());
35 } else if (tool == "dartdoc") { 37 } else if (tool == "dartdoc") {
ricow1 2014/01/21 00:52:16 remove
36 dartdocMain.main(arguments.skip(1).toList()); 38 dartdocMain.main(arguments.skip(1).toList());
39 } else if (tool == "docgen") {
40 docgenMain.main(arguments.skip(1).toList());
37 } 41 }
38 } 42 }
39 43
40 """; 44 """;
41 return snapshotGenerationText; 45 return snapshotGenerationText;
42 }); 46 });
43 } 47 }
44 48
45 Future<String> getDart2jsSnapshotGenerationFile(var args, var rootPath) { 49 Future<String> getDart2jsSnapshotGenerationFile(var args, var rootPath) {
46 var dart2js = rootPath.resolve(args["dart2js_main"]); 50 var dart2js = rootPath.resolve(args["dart2js_main"]);
(...skipping 18 matching lines...) Expand all
65 writer.close(); 69 writer.close();
66 } 70 }
67 71
68 Future createSnapshot(var dart_file, var packageRoot) { 72 Future createSnapshot(var dart_file, var packageRoot) {
69 return Process.run(Platform.executable, 73 return Process.run(Platform.executable,
70 ["--package-root=$packageRoot", 74 ["--package-root=$packageRoot",
71 "--snapshot=$dart_file.snapshot", 75 "--snapshot=$dart_file.snapshot",
72 dart_file]) 76 dart_file])
73 .then((result) { 77 .then((result) {
74 if (result.exitCode != 0) { 78 if (result.exitCode != 0) {
79 print("Could not generate snapshot: result code ${result.exitCode}");
80 print(result.stdout);
81 print(result.stderr);
75 throw "Could not generate snapshot"; 82 throw "Could not generate snapshot";
76 } 83 }
77 }); 84 });
78 } 85 }
79 86
80 /** 87 /**
81 * Takes the following arguments: 88 * Takes the following arguments:
82 * --output_dir=val The full path to the output_dir. 89 * --output_dir=val The full path to the output_dir.
83 * --dart2js_main=val The path to the dart2js main script releative to root. 90 * --dart2js_main=val The path to the dart2js main script relative to root.
91 * --dartdoc_main=val The path to the dartdoc main script relative to root.
ricow1 2014/01/21 00:52:16 remove
92 * --docgen_main=val The path to the docgen main script relative to root.
93 * --package-root=val The package-root used to find packages for the snapshot.
84 */ 94 */
85 void main(List<String> arguments) { 95 void main(List<String> arguments) {
86 var validArguments = ["--output_dir", "--dart2js_main", "--dartdoc_main", 96 var validArguments = ["--output_dir", "--dart2js_main", "--dartdoc_main",
ricow1 2014/01/21 00:52:16 remove dartdoc
87 "--package_root"]; 97 "--docgen_main", "--package_root"];
88 var args = {}; 98 var args = {};
89 for (var argument in arguments) { 99 for (var argument in arguments) {
90 var argumentSplit = argument.split("="); 100 var argumentSplit = argument.split("=");
91 if (argumentSplit.length != 2) throw "Invalid argument $argument, no ="; 101 if (argumentSplit.length != 2) throw "Invalid argument $argument, no =";
92 if (!validArguments.contains(argumentSplit[0])) { 102 if (!validArguments.contains(argumentSplit[0])) {
93 throw "Invalid argument $argument"; 103 throw "Invalid argument $argument";
94 } 104 }
95 args[argumentSplit[0].substring(2)] = argumentSplit[1]; 105 args[argumentSplit[0].substring(2)] = argumentSplit[1];
96 } 106 }
97 if (!args.containsKey("dart2js_main")) throw "Please specify dart2js_main"; 107 if (!args.containsKey("dart2js_main")) throw "Please specify dart2js_main";
98 if (!args.containsKey("dartdoc_main")) throw "Please specify dartdoc_main"; 108 if (!args.containsKey("dartdoc_main")) throw "Please specify dartdoc_main";
ricow1 2014/01/21 00:52:16 remove
109 if (!args.containsKey("docgen_main")) throw "Please specify docgen_main";
99 if (!args.containsKey("output_dir")) throw "Please specify output_dir"; 110 if (!args.containsKey("output_dir")) throw "Please specify output_dir";
100 if (!args.containsKey("package_root")) throw "Please specify package_root"; 111 if (!args.containsKey("package_root")) throw "Please specify package_root";
101 112
102 var scriptFile = Uri.base.resolveUri(Platform.script); 113 var scriptFile = Uri.base.resolveUri(Platform.script);
103 var path = scriptFile.resolve("."); 114 var path = scriptFile.resolve(".");
104 var rootPath = path.resolve("../.."); 115 var rootPath = path.resolve("../..");
105 getSnapshotGenerationFile(args, rootPath).then((result) { 116 getSnapshotGenerationFile(args, rootPath).then((result) {
106 var wrapper = "${args['output_dir']}/utils_wrapper.dart"; 117 var wrapper = "${args['output_dir']}/utils_wrapper.dart";
107 writeSnapshotFile(wrapper, result); 118 writeSnapshotFile(wrapper, result);
108 createSnapshot(wrapper, args["package_root"]); 119 createSnapshot(wrapper, args["package_root"]);
109 }); 120 });
110 121
111 getDart2jsSnapshotGenerationFile(args, rootPath).then((result) { 122 getDart2jsSnapshotGenerationFile(args, rootPath).then((result) {
112 var wrapper = "${args['output_dir']}/dart2js.dart"; 123 var wrapper = "${args['output_dir']}/dart2js.dart";
113 writeSnapshotFile(wrapper, result); 124 writeSnapshotFile(wrapper, result);
114 createSnapshot(wrapper, args["package_root"]); 125 createSnapshot(wrapper, args["package_root"]);
115 }); 126 });
116 127
117 } 128 }
OLDNEW
« utils/compiler/compiler.gyp ('K') | « utils/compiler/compiler.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698