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

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

Issue 16364004: Add dartdoc to the generated utils snapshot. (Closed) Base URL: https://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"]);
25 26
26 return getVersion(options, rootPath).then((version) { 27 return getVersion(options, rootPath).then((version) {
27 var snapshotGenerationText = 28 var snapshotGenerationText =
28 """ 29 """
29 import '${dart2js}' as dart2jsMain; 30 import '${dart2js}' as dart2jsMain;
31 import '${dartdoc}' as dartdocMain;
30 import 'dart:io'; 32 import 'dart:io';
31 33
32 void main() { 34 void main() {
33 Options options = new Options(); 35 Options options = new Options();
34 if (options.arguments.length < 1) throw "No tool given as argument"; 36 if (options.arguments.length < 1) throw "No tool given as argument";
35 String tool = options.arguments.removeAt(0); 37 String tool = options.arguments.removeAt(0);
36 if (tool == "dart2js") { 38 if (tool == "dart2js") {
37 dart2jsMain.BUILD_ID = "$version"; 39 dart2jsMain.BUILD_ID = "$version";
38 dart2jsMain.mainWithErrorHandler(options); 40 dart2jsMain.mainWithErrorHandler(options);
41 } else if (tool == "dartdoc") {
42 dartdocMain.mainWithOptions(options);
39 } 43 }
40 } 44 }
41 45
42 """; 46 """;
43 return snapshotGenerationText; 47 return snapshotGenerationText;
44 }); 48 });
45 } 49 }
46 50
47 void writeSnapshotFile(var path, var content) { 51 void writeSnapshotFile(var path, var content) {
48 File file = new File(path); 52 File file = new File(path);
49 var writer = file.openSync(mode: FileMode.WRITE); 53 var writer = file.openSync(mode: FileMode.WRITE);
50 writer.writeStringSync(content); 54 writer.writeStringSync(content);
51 writer.close(); 55 writer.close();
52 } 56 }
53 57
54 Future createSnapshot(var options, var dart_file) { 58 Future createSnapshot(var options, var dart_file, var packageRoot) {
55 return Process.run(options.executable, 59 return Process.run(options.executable,
56 ["--generate-script-snapshot=$dart_file.snapshot", 60 ["--package-root=$packageRoot",
61 "--generate-script-snapshot=$dart_file.snapshot",
57 dart_file]) 62 dart_file])
58 .then((result) { 63 .then((result) {
59 if (result.exitCode != 0) { 64 if (result.exitCode != 0) {
60 throw "Could not generate snapshot"; 65 throw "Could not generate snapshot";
61 } 66 }
62 }); 67 });
63 } 68 }
64 69
65 /** 70 /**
66 * Takes the following arguments: 71 * Takes the following arguments:
67 * --output_dir=val The full path to the output_dir. 72 * --output_dir=val The full path to the output_dir.
68 * --dart2js_main=val The path to the dart2js main script releative to root. 73 * --dart2js_main=val The path to the dart2js main script releative to root.
69 */ 74 */
70 void main() { 75 void main() {
71 Options options = new Options(); 76 Options options = new Options();
72 var validArguments = ["--output_dir", "--dart2js_main"]; 77 var validArguments = ["--output_dir", "--dart2js_main", "--dartdoc_main",
78 "--package_root"];
73 var args = {}; 79 var args = {};
74 for (var argument in options.arguments) { 80 for (var argument in options.arguments) {
75 var argumentSplit = argument.split("="); 81 var argumentSplit = argument.split("=");
76 if (argumentSplit.length != 2) throw "Invalid argument $argument, no ="; 82 if (argumentSplit.length != 2) throw "Invalid argument $argument, no =";
77 if (!validArguments.contains(argumentSplit[0])) { 83 if (!validArguments.contains(argumentSplit[0])) {
78 throw "Invalid argument $argument"; 84 throw "Invalid argument $argument";
79 } 85 }
80 args[argumentSplit[0].substring(2)] = argumentSplit[1]; 86 args[argumentSplit[0].substring(2)] = argumentSplit[1];
81 } 87 }
82 if (!args.containsKey("dart2js_main")) throw "Please specify dart2js_main"; 88 if (!args.containsKey("dart2js_main")) throw "Please specify dart2js_main";
89 if (!args.containsKey("dartdoc_main")) throw "Please specify dartdoc_main";
83 if (!args.containsKey("output_dir")) throw "Please specify output_dir"; 90 if (!args.containsKey("output_dir")) throw "Please specify output_dir";
91 if (!args.containsKey("package_root")) throw "Please specify package_root";
84 92
85 var scriptFile = new File(new File(options.script).fullPathSync()); 93 var scriptFile = new File(new File(options.script).fullPathSync());
86 var path = new Path(scriptFile.directory.path); 94 var path = new Path(scriptFile.directory.path);
87 var rootPath = path.directoryPath.directoryPath; 95 var rootPath = path.directoryPath.directoryPath;
88 getSnapshotGenerationFile(options, args, rootPath).then((result) { 96 getSnapshotGenerationFile(options, args, rootPath).then((result) {
89 var wrapper = "${args['output_dir']}/utils_wrapper.dart"; 97 var wrapper = "${args['output_dir']}/utils_wrapper.dart";
90 writeSnapshotFile(wrapper, result); 98 writeSnapshotFile(wrapper, result);
91 createSnapshot(options, wrapper); 99 createSnapshot(options, wrapper, args["package_root"]);
92 }); 100 });
93 } 101 }
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