| 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 library sdk_source; | 5 library sdk_source; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'io.dart'; | 8 import 'io.dart'; |
| 9 import 'package.dart'; | 9 import 'package.dart'; |
| 10 import 'pubspec.dart'; | 10 import 'pubspec.dart'; |
| 11 import 'sdk.dart' as sdk; | 11 import 'sdk.dart' as sdk; |
| 12 import 'source.dart'; | 12 import 'source.dart'; |
| 13 import 'version.dart'; | 13 import 'version.dart'; |
| 14 | 14 |
| 15 /// A package source that uses libraries from the Dart SDK. | 15 /// A package source that uses libraries from the Dart SDK. |
| 16 class SdkSource extends Source { | 16 class SdkSource extends Source { |
| 17 final String name = "sdk"; | 17 final String name = "sdk"; |
| 18 final bool shouldCache = false; | 18 final bool shouldCache = false; |
| 19 | 19 |
| 20 /// SDK packages are not individually versioned. Instead, their version is | 20 /// SDK packages are not individually versioned. Instead, their version is |
| 21 /// inferred from the revision number of the SDK itself. | 21 /// inferred from the revision number of the SDK itself. |
| 22 Future<Pubspec> describe(PackageId id) { | 22 Future<Pubspec> describe(PackageId id) { |
| 23 return _getPackagePath(id).then((packageDir) { | 23 return _getPackagePath(id).then((packageDir) { |
| 24 // TODO(rnystrom): What if packageDir is null? | 24 // TODO(rnystrom): What if packageDir is null? |
| 25 return Package.load(id.name, packageDir, systemCache.sources); | 25 return Package.load(id.name, packageDir, systemCache.sources); |
| 26 }).then((package) { | 26 }).then((package) { |
| 27 // Ignore the pubspec's version, and use the SDK's. | 27 // Ignore the pubspec's version, and use the SDK's. |
| 28 return new Pubspec(id.name, sdk.version, package.pubspec.dependencies); | 28 return new Pubspec(id.name, sdk.version, package.pubspec.dependencies, |
| 29 package.pubspec.environment); |
| 29 }); | 30 }); |
| 30 } | 31 } |
| 31 | 32 |
| 32 /// Since all the SDK files are already available locally, installation just | 33 /// Since all the SDK files are already available locally, installation just |
| 33 /// involves symlinking the SDK library into the packages directory. | 34 /// involves symlinking the SDK library into the packages directory. |
| 34 Future<bool> install(PackageId id, String destPath) { | 35 Future<bool> install(PackageId id, String destPath) { |
| 35 return _getPackagePath(id).then((path) { | 36 return _getPackagePath(id).then((path) { |
| 36 if (path == null) return new Future<bool>.immediate(false); | 37 if (path == null) return new Future<bool>.immediate(false); |
| 37 | 38 |
| 38 return createPackageSymlink(id.name, path, destPath).then( | 39 return createPackageSymlink(id.name, path, destPath).then( |
| 39 (_) => true); | 40 (_) => true); |
| 40 }); | 41 }); |
| 41 } | 42 } |
| 42 | 43 |
| 43 /// Gets the path in the SDK's "pkg" directory to the directory containing | 44 /// Gets the path in the SDK's "pkg" directory to the directory containing |
| 44 /// package [id]. Returns `null` if the package could not be found. | 45 /// package [id]. Returns `null` if the package could not be found. |
| 45 Future<String> _getPackagePath(PackageId id) { | 46 Future<String> _getPackagePath(PackageId id) { |
| 46 var pkgPath = join(sdk.rootDirectory, "pkg", id.description); | 47 var pkgPath = join(sdk.rootDirectory, "pkg", id.description); |
| 47 return dirExists(pkgPath).then((found) => found ? pkgPath : null); | 48 return dirExists(pkgPath).then((found) => found ? pkgPath : null); |
| 48 } | 49 } |
| 49 } | 50 } |
| OLD | NEW |