| OLD | NEW |
| 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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 args = ['/j', to, from]; | 311 args = ['/j', to, from]; |
| 312 } | 312 } |
| 313 | 313 |
| 314 return runProcess(command, args).transform((result) { | 314 return runProcess(command, args).transform((result) { |
| 315 // TODO(rnystrom): Check exit code and output? | 315 // TODO(rnystrom): Check exit code and output? |
| 316 return new File(to); | 316 return new File(to); |
| 317 }); | 317 }); |
| 318 } | 318 } |
| 319 | 319 |
| 320 /** | 320 /** |
| 321 * Creates a new symlink that creates an alias from the package [from] to [to], | 321 * Creates a new symlink that creates an alias from the `lib` directory of |
| 322 * both of which can be a [String], [File], or [Directory]. Returns a [Future] | 322 * package [from] to [to], both of which can be a [String], [File], or |
| 323 * which completes to the symlink file (i.e. [to]). | 323 * [Directory]. Returns a [Future] which completes to the symlink file (i.e. |
| 324 * | 324 * [to]). If [from] does not have a `lib` directory, this shows a warning if |
| 325 * Unlike [createSymlink], this has heuristics to detect if [from] is using | 325 * appropriate and then does nothing. |
| 326 * the old or new style of package layout. If it's using the new style, then | |
| 327 * it will create a symlink to the "lib" directory contained inside that | |
| 328 * package directory. Otherwise, it just symlinks to the package directory | |
| 329 * itself. | |
| 330 */ | 326 */ |
| 331 // TODO(rnystrom): Remove this when old style packages are no longer supported. | |
| 332 // See: http://code.google.com/p/dart/issues/detail?id=4964. | |
| 333 Future<File> createPackageSymlink(String name, from, to, | 327 Future<File> createPackageSymlink(String name, from, to, |
| 334 {bool isSelfLink: false}) { | 328 {bool isSelfLink: false}) { |
| 335 // If from contains any Dart files at the top level (aside from build.dart) | 329 // See if the package has a "lib" directory. |
| 336 // we assume that means it's an old style package. | 330 from = join(from, 'lib'); |
| 337 return listDir(from).chain((contents) { | 331 return dirExists(from).chain((exists) { |
| 338 var isOldStyle = contents.some( | 332 if (exists) return createSymlink(from, to); |
| 339 (file) => file.endsWith('.dart') && basename(file) != 'build.dart'); | |
| 340 | 333 |
| 341 if (isOldStyle) { | 334 // It's OK for the self link (i.e. the root package) to not have a lib |
| 342 if (isSelfLink) { | 335 // directory since it may just be a leaf application that only has |
| 343 printError('Warning: Package "$name" is using a deprecated layout.'); | 336 // code in bin or web. |
| 344 printError('See http://www.dartlang.org/docs/pub-package-manager/' | 337 if (!isSelfLink) { |
| 345 'package-layout.html for details.'); | 338 printError( |
| 346 | 339 'Warning: Package "$name" does not have a "lib" directory so you ' |
| 347 // Do not create self-links on old style packages. | 340 'will not be able to import any libraries from it.'); |
| 348 return new Future.immediate(to); | |
| 349 } else { | |
| 350 return createSymlink(from, to); | |
| 351 } | |
| 352 } | 341 } |
| 353 | 342 |
| 354 // It's a new style package, so symlink to the 'lib' directory. But only | 343 return new Future.immediate(to); |
| 355 // if the package actually *has* one. Otherwise, we won't create a | |
| 356 // symlink at all. | |
| 357 from = join(from, 'lib'); | |
| 358 return dirExists(from).chain((exists) { | |
| 359 if (exists) { | |
| 360 return createSymlink(from, to); | |
| 361 } else { | |
| 362 // It's OK for the self link (i.e. the root package) to not have a lib | |
| 363 // directory since it may just be a leaf application that only has | |
| 364 // code in bin or web. | |
| 365 if (!isSelfLink) { | |
| 366 printError( | |
| 367 'Warning: Package "$name" does not have a "lib" directory.'); | |
| 368 } | |
| 369 | |
| 370 return new Future.immediate(to); | |
| 371 } | |
| 372 }); | |
| 373 }); | 344 }); |
| 374 } | 345 } |
| 375 | 346 |
| 376 /// Given [entry] which may be a [String], [File], or [Directory] relative to | 347 /// Given [entry] which may be a [String], [File], or [Directory] relative to |
| 377 /// the current working directory, returns its full canonicalized path. | 348 /// the current working directory, returns its full canonicalized path. |
| 378 String getFullPath(entry) { | 349 String getFullPath(entry) { |
| 379 var path = _getPath(entry); | 350 var path = _getPath(entry); |
| 380 | 351 |
| 381 // Don't do anything if it's already absolute. | 352 // Don't do anything if it's already absolute. |
| 382 if (Platform.operatingSystem == 'windows') { | 353 if (Platform.operatingSystem == 'windows') { |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 return new Directory(entry); | 746 return new Directory(entry); |
| 776 } | 747 } |
| 777 | 748 |
| 778 /** | 749 /** |
| 779 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 750 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
| 780 */ | 751 */ |
| 781 Uri _getUri(uri) { | 752 Uri _getUri(uri) { |
| 782 if (uri is Uri) return uri; | 753 if (uri is Uri) return uri; |
| 783 return new Uri.fromString(uri); | 754 return new Uri.fromString(uri); |
| 784 } | 755 } |
| OLD | NEW |