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

Unified Diff: utils/pub/sdk_source.dart

Issue 10947050: Support dependencies in SDK packages. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | utils/tests/pub/pub_install_sdk_test.dart » ('j') | utils/tests/pub/pub_install_sdk_test.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/sdk_source.dart
diff --git a/utils/pub/sdk_source.dart b/utils/pub/sdk_source.dart
index 3260e441a8c11cd03877d0b1f4445a7b97e9be15..1b3e559d47550b3008a26a6788954b3aaac4fb2a 100644
--- a/utils/pub/sdk_source.dart
+++ b/utils/pub/sdk_source.dart
@@ -10,18 +10,12 @@
#import('source.dart');
#import('version.dart');
-/**
- * A package source that uses libraries from the Dart SDK.
- *
- * This currently uses the "sdkdir" command-line argument to find the SDK.
- */
+/// A package source that uses libraries from the Dart SDK.
class SdkSource extends Source {
final String name = "sdk";
final bool shouldCache = false;
- /**
- * The root directory of the Dart SDK.
- */
+ /// The root directory of the Dart SDK.
final String _rootDir;
String get rootDir {
@@ -32,39 +26,48 @@ class SdkSource extends Source {
SdkSource(this._rootDir);
- /**
- * An SDK package has no dependencies. Its version number is inferred from the
- * revision number of the SDK itself.
- */
+ /// SDK packages are not individually versioned. Instead, their version is
+ /// inferred from the revision number of the SDK itself.
Future<Pubspec> describe(PackageId id) {
- return readTextFile(join(rootDir, "revision")).transform((revision) {
+ return readTextFile(join(rootDir, "revision")).chain((revision) {
var version = new Version.parse("0.0.0-r.${revision.trim()}");
- return new Pubspec(id.name, version, <PackageRef>[]);
+ // Read the pubspec for the package's dependencies.
+ return _getPackagePath(id).chain((packageDir) {
+ // TODO(rnystrom): What if packageDir is null?
+ return Package.load(id.name, packageDir, systemCache.sources)
+ .transform((package) {
+ // Ignore the pubspec's version, and use the SDK's.
+ return new Pubspec(id.name, version, package.pubspec.dependencies);
+ });
nweiz 2012/09/19 23:38:53 This is a lot of unnecessary nesting. Use #chain m
Bob Nystrom 2012/09/20 01:00:08 Done.
+ });
});
}
- /**
- * Since all the SDK files are already available locally, installation just
- * involves symlinking the SDK library into the packages directory.
- */
+ /// Since all the SDK files are already available locally, installation just
+ /// involves symlinking the SDK library into the packages directory.
Future<bool> install(PackageId id, String destPath) {
- // Look in "pkg" first.
- var sourcePath = join(rootDir, "pkg", id.description);
- return exists(sourcePath).chain((found) {
- if (!found) {
- // TODO(rnystrom): Get rid of this when all SDK packages are moved from
- // "lib" to "pkg".
- // Not in "pkg", so try "lib".
- sourcePath = join(rootDir, "lib", id.description);
- return exists(sourcePath).chain((found) {
- if (!found) return new Future<bool>.immediate(false);
- return createPackageSymlink(id.name, sourcePath, destPath).transform(
- (_) => true);
- });
- }
+ return _getPackagePath(id).chain((path) {
+ if (path == null) return new Future<bool>.immediate(false);
- return createPackageSymlink(id.name, sourcePath, destPath).transform(
+ return createPackageSymlink(id.name, path, destPath).transform(
(_) => true);
});
}
+
+ /// Gets the path in the SDK to the directory containing package [id]. Looks
+ /// inside both "pkg" and "lib" in the SDK. Returns `null` if the package
+ /// could not be found.
+ Future<String> _getPackagePath(PackageId id) {
+ // Look in "pkg" first.
+ var pkgPath = join(rootDir, "pkg", id.description);
+ return exists(pkgPath).chain((found) {
+ if (found) return new Future<String>.immediate(pkgPath);
+
+ // Not in "pkg", so try "lib".
+ // TODO(rnystrom): Get rid of this when all SDK packages are moved from
+ // "lib" to "pkg".
+ var libPath = join(rootDir, "lib", id.description);
+ return exists(libPath).transform((found) => found ? libPath : null);
+ });
+ }
}
« no previous file with comments | « no previous file | utils/tests/pub/pub_install_sdk_test.dart » ('j') | utils/tests/pub/pub_install_sdk_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698