Chromium Code Reviews

Side by Side Diff: sdk/lib/_internal/pub_generated/bin/async_compile.dart

Issue 745153002: Make pub's binstubs resilient to changes in snapshot format. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 import 'package:args/args.dart'; 7 import 'package:args/args.dart';
8 import 'package:analyzer/src/services/formatter_impl.dart'; 8 import 'package:analyzer/src/services/formatter_impl.dart';
9 import 'package:async_await/async_await.dart' as async_await; 9 import 'package:async_await/async_await.dart' as async_await;
10 import 'package:path/path.dart' as p; 10 import 'package:path/path.dart' as p;
(...skipping 43 matching lines...)
54 var rest = parser.parse(arguments).rest; 54 var rest = parser.parse(arguments).rest;
55 if (rest.isEmpty) { 55 if (rest.isEmpty) {
56 throw new FormatException('Missing build directory.'); 56 throw new FormatException('Missing build directory.');
57 } else if (rest.length > 1) { 57 } else if (rest.length > 1) {
58 throw new FormatException( 58 throw new FormatException(
59 'Unexpected arguments: ${rest.skip(1).join(" ")}.'); 59 'Unexpected arguments: ${rest.skip(1).join(" ")}.');
60 } 60 }
61 61
62 buildDir = rest.first; 62 buildDir = rest.first;
63 } on FormatException catch (ex) { 63 } on FormatException catch (ex) {
64 stderr.writeln(ex); 64 print(ex);
65 stderr.writeln(); 65 print();
66 stderr.writeln( 66 print("Usage: dart async_compile.dart [--verbose] [--force] <build dir>");
67 "Usage: dart async_compile.dart [--verbose] [--force] <build dir>");
68 exit(64); 67 exit(64);
69 } 68 }
70 69
71 // See what version (i.e. Git commit) of the async-await compiler we 70 // See what version (i.e. Git commit) of the async-await compiler we
72 // currently have. If this is different from the version that was used to 71 // currently have. If this is different from the version that was used to
73 // compile the sources, recompile everything. 72 // compile the sources, recompile everything.
74 var currentCommit = _getCurrentCommit(); 73 var currentCommit = _getCurrentCommit();
75 74
76 var readmePath = p.join(generatedDir, "README.md"); 75 var readmePath = p.join(generatedDir, "README.md");
77 var lastCommit; 76 var lastCommit;
78 var readme = new File(readmePath).readAsStringSync(); 77 var readme = new File(readmePath).readAsStringSync();
79 var match = _commitPattern.firstMatch(readme); 78 var match = _commitPattern.firstMatch(readme);
80 if (match == null) { 79 if (match == null) {
81 stderr.writeln("Could not find compiler commit hash in README.md."); 80 print("Could not find compiler commit hash in README.md.");
82 exit(1); 81 exit(1);
83 } 82 }
84 83
85 lastCommit = match[0]; 84 lastCommit = match[0];
86 85
87 var numFiles = 0; 86 var numFiles = 0;
88 var numCompiled = 0; 87 var numCompiled = 0;
89 88
90 // Compile any modified or missing files. 89 // Compile any modified or missing files.
91 var sources = new Set(); 90 var sources = new Set();
(...skipping 52 matching lines...)
144 if (Platform.operatingSystem == "windows") { 143 if (Platform.operatingSystem == "windows") {
145 command = "cmd"; 144 command = "cmd";
146 args = ["/c", "git"]..addAll(args); 145 args = ["/c", "git"]..addAll(args);
147 } 146 }
148 147
149 var result = Process.runSync( 148 var result = Process.runSync(
150 command, 149 command,
151 args, 150 args,
152 workingDirectory: p.join(sourceDir, "../../../../third_party/pkg/async_awa it")); 151 workingDirectory: p.join(sourceDir, "../../../../third_party/pkg/async_awa it"));
153 if (result.exitCode != 0) { 152 if (result.exitCode != 0) {
154 stderr.writeln("Could not get Git revision of async_await compiler."); 153 print("Could not get Git revision of async_await compiler.");
155 exit(1); 154 exit(1);
156 } 155 }
157 156
158 return result.stdout.trim(); 157 return result.stdout.trim();
159 } 158 }
160 159
161 void _compile(String sourcePath, String source, String destPath) { 160 void _compile(String sourcePath, String source, String destPath) {
162 var destDir = new Directory(p.dirname(destPath)); 161 var destDir = new Directory(p.dirname(destPath));
163 destDir.createSync(recursive: true); 162 destDir.createSync(recursive: true);
164 163
(...skipping 21 matching lines...)
186 185
187 try { 186 try {
188 source = async_await.compile(source); 187 source = async_await.compile(source);
189 188
190 // Reformat the result since the compiler ditches all whitespace. 189 // Reformat the result since the compiler ditches all whitespace.
191 // TODO(rnystrom): Remove when this is fixed: 190 // TODO(rnystrom): Remove when this is fixed:
192 // https://github.com/dart-lang/async_await/issues/12 191 // https://github.com/dart-lang/async_await/issues/12
193 var result = new CodeFormatter().format(CodeKind.COMPILATION_UNIT, source); 192 var result = new CodeFormatter().format(CodeKind.COMPILATION_UNIT, source);
194 return result.source; 193 return result.source;
195 } catch (ex) { 194 } catch (ex) {
196 stderr.writeln("Async compile failed on $sourcePath:\n$ex"); 195 print("Async compile failed on $sourcePath:\n$ex");
197 hadFailure = true; 196 hadFailure = true;
198 return null; 197 return null;
199 } 198 }
200 } 199 }
201 200
202 /// Fix relative imports to dart2js libraries. 201 /// Fix relative imports to dart2js libraries.
203 /// 202 ///
204 /// Pub imports dart2js using relative imports that reach outside of pub's 203 /// Pub imports dart2js using relative imports that reach outside of pub's
205 /// source tree. Since the build directory is in a different location, we need 204 /// source tree. Since the build directory is in a different location, we need
206 /// to fix those to be valid relative imports from the build directory. 205 /// to fix those to be valid relative imports from the build directory.
(...skipping 12 matching lines...)
219 218
220 var entrypoint = p.join(generatedDir, 'bin/pub.dart'); 219 var entrypoint = p.join(generatedDir, 'bin/pub.dart');
221 var packageRoot = p.join(buildDir, 'packages'); 220 var packageRoot = p.join(buildDir, 'packages');
222 var snapshot = p.join(buildDir, 'dart-sdk/bin/snapshots/pub.dart.snapshot'); 221 var snapshot = p.join(buildDir, 'dart-sdk/bin/snapshots/pub.dart.snapshot');
223 222
224 var result = Process.runSync( 223 var result = Process.runSync(
225 Platform.executable, 224 Platform.executable,
226 ["--package-root=$packageRoot", "--snapshot=$snapshot", entrypoint]); 225 ["--package-root=$packageRoot", "--snapshot=$snapshot", entrypoint]);
227 226
228 if (result.exitCode != 0) { 227 if (result.exitCode != 0) {
229 stderr.writeln("Failed to generate snapshot:"); 228 print("Failed to generate snapshot:");
230 if (result.stderr.trim().isNotEmpty) stderr.writeln(result.stderr); 229 if (result.stderr.trim().isNotEmpty) print(result.stderr);
231 if (result.stdout.trim().isNotEmpty) stderr.writeln(result.stdout); 230 if (result.stdout.trim().isNotEmpty) print(result.stdout);
232 exit(result.exitCode); 231 exit(result.exitCode);
233 } 232 }
234 233
235 if (verbose) print("Created pub snapshot"); 234 if (verbose) print("Created pub snapshot");
236 } 235 }
237 236
238 /// Deletes the file at [path], ignoring any IO errors that occur. 237 /// Deletes the file at [path], ignoring any IO errors that occur.
239 /// 238 ///
240 /// This swallows errors to accommodate multiple compilers running concurrently. 239 /// This swallows errors to accommodate multiple compilers running concurrently.
241 /// Since they will produce the same output anyway, a failure of one is fine. 240 /// Since they will produce the same output anyway, a failure of one is fine.
242 void _deleteFile(String path) { 241 void _deleteFile(String path) {
243 try { 242 try {
244 new File(path).deleteSync(); 243 new File(path).deleteSync();
245 } on IOException catch (ex) { 244 } on IOException catch (ex) {
246 // Do nothing. 245 // Do nothing.
247 } 246 }
248 } 247 }
249 248
250 /// Writes [contents] to [path], ignoring any IO errors that occur. 249 /// Writes [contents] to [path], ignoring any IO errors that occur.
251 /// 250 ///
252 /// This swallows errors to accommodate multiple compilers running concurrently. 251 /// This swallows errors to accommodate multiple compilers running concurrently.
253 /// Since they will produce the same output anyway, a failure of one is fine. 252 /// Since they will produce the same output anyway, a failure of one is fine.
254 void _writeFile(String path, String contents) { 253 void _writeFile(String path, String contents) {
255 try { 254 try {
256 new File(path).writeAsStringSync(contents); 255 new File(path).writeAsStringSync(contents);
257 } on IOException catch (ex) { 256 } on IOException catch (ex) {
258 // Do nothing. 257 // Do nothing.
259 } 258 }
260 } 259 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/test/test_pub.dart ('k') | sdk/lib/_internal/pub_generated/lib/src/command/cache_repair.dart » ('j') | no next file with comments »

Powered by Google App Engine