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

Side by Side Diff: utils/pub/io.dart

Issue 10916190: Support both new and old style package layouts. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Respond to review. Created 8 years, 3 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/pub/entrypoint.dart ('k') | utils/pub/pub.dart » ('j') | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * Helper functionality to make working with IO easier. 6 * Helper functionality to make working with IO easier.
7 */ 7 */
8 #library('io'); 8 #library('io');
9 9
10 #import('dart:io'); 10 #import('dart:io');
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 args = ['/c', 'mklink', '/j', to, from]; 273 args = ['/c', 'mklink', '/j', to, from];
274 } 274 }
275 275
276 return runProcess(command, args).transform((result) { 276 return runProcess(command, args).transform((result) {
277 // TODO(rnystrom): Check exit code and output? 277 // TODO(rnystrom): Check exit code and output?
278 return new File(to); 278 return new File(to);
279 }); 279 });
280 } 280 }
281 281
282 /** 282 /**
283 * Creates a new symlink that creates an alias from the package [from] to [to],
284 * both of which can be a [String], [File], or [Directory]. Returns a [Future]
285 * which completes to the symlink file (i.e. [to]).
286 *
287 * Unlike [createSymlink], this has heuristics to detect if [from] is using
288 * the old or new style of package layout. If it's using the new style, then
289 * it will create a symlink to the "lib" directory contained inside that
290 * package directory. Otherwise, it just symlinks to the package directory
291 * itself.
292 */
293 // TODO(rnystrom): Remove this when old style packages are no longer supported.
294 // See: http://code.google.com/p/dart/issues/detail?id=4964.
295 Future<File> createPackageSymlink(String name, from, to,
nweiz 2012/09/11 21:07:47 Can't you infer the name from "from"?
Bob Nystrom 2012/09/11 21:39:01 I could, but every callsite knew the name so I fig
296 [bool isSelfLink = false]) {
297 // If from contains any Dart files at the top level (aside from build.dart)
298 // we assume that means it's an old style package.
299 return listDir(from).chain((contents) {
300 var isOldStyle = contents.some(
301 (file) => file.endsWith('.dart') && basename(file) != 'build.dart');
302
303 if (isOldStyle) {
304 if (isSelfLink) {
305 printError('Warning: Package "$name" is using a deprecated layout.');
306 printError('See http://www.dartlang.org/docs/pub-package-manager/'
307 'package-layout.html for details.');
308
309 // Do not create self-links on old style packages.
310 return new Future.immediate(to);
311 } else {
312 return createSymlink(from, to);
313 }
314 }
315
316 // It's a new style package, so symlink to the 'lib' directory. But only
317 // if the package actually *has* one. Otherwise, we won't create a
318 // symlink at all.
319 from = join(from, 'lib');
320 return dirExists(from).chain((exists) {
321 if (exists) {
322 return createSymlink(from, to);
323 } else {
324 printError('Warning: Package "$name" does not have a "lib" directory.');
325 return new Future.immediate(to);
326 }
327 });
328 });
329 }
330
331 /**
283 * Given [entry] which may be a [String], [File], or [Directory] relative to 332 * Given [entry] which may be a [String], [File], or [Directory] relative to
284 * the current working directory, returns its full canonicalized path. 333 * the current working directory, returns its full canonicalized path.
285 */ 334 */
286 // TODO(rnystrom): Should this be async? 335 // TODO(rnystrom): Should this be async?
287 String getFullPath(entry) => new File(_getPath(entry)).fullPathSync(); 336 String getFullPath(entry) => new File(_getPath(entry)).fullPathSync();
288 337
289 // TODO(nweiz): make this configurable 338 // TODO(nweiz): make this configurable
290 /** 339 /**
291 * The amount of time in milliseconds to allow HTTP requests before assuming 340 * The amount of time in milliseconds to allow HTTP requests before assuming
292 * they've failed. 341 * they've failed.
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 return new Directory(entry); 623 return new Directory(entry);
575 } 624 }
576 625
577 /** 626 /**
578 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. 627 * Gets a [Uri] for [uri], which can either already be one, or be a [String].
579 */ 628 */
580 Uri _getUri(uri) { 629 Uri _getUri(uri) {
581 if (uri is Uri) return uri; 630 if (uri is Uri) return uri;
582 return new Uri.fromString(uri); 631 return new Uri.fromString(uri);
583 } 632 }
OLDNEW
« no previous file with comments | « utils/pub/entrypoint.dart ('k') | utils/pub/pub.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698