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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
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 #library('sdk_source'); 5 #library('sdk_source');
6 6
7 #import('io.dart'); 7 #import('io.dart');
8 #import('package.dart'); 8 #import('package.dart');
9 #import('pubspec.dart'); 9 #import('pubspec.dart');
10 #import('source.dart'); 10 #import('source.dart');
11 #import('version.dart'); 11 #import('version.dart');
12 12
13 /** 13 /// A package source that uses libraries from the Dart SDK.
14 * A package source that uses libraries from the Dart SDK.
15 *
16 * This currently uses the "sdkdir" command-line argument to find the SDK.
17 */
18 class SdkSource extends Source { 14 class SdkSource extends Source {
19 final String name = "sdk"; 15 final String name = "sdk";
20 final bool shouldCache = false; 16 final bool shouldCache = false;
21 17
22 /** 18 /// The root directory of the Dart SDK.
23 * The root directory of the Dart SDK.
24 */
25 final String _rootDir; 19 final String _rootDir;
26 20
27 String get rootDir { 21 String get rootDir {
28 if (_rootDir != null) return _rootDir; 22 if (_rootDir != null) return _rootDir;
29 throw "Pub can't find the Dart SDK. Please set the DART_SDK environment " 23 throw "Pub can't find the Dart SDK. Please set the DART_SDK environment "
30 "variable to the Dart SDK directory."; 24 "variable to the Dart SDK directory.";
31 } 25 }
32 26
33 SdkSource(this._rootDir); 27 SdkSource(this._rootDir);
34 28
35 /** 29 /// SDK packages are not individually versioned. Instead, their version is
36 * An SDK package has no dependencies. Its version number is inferred from the 30 /// inferred from the revision number of the SDK itself.
37 * revision number of the SDK itself.
38 */
39 Future<Pubspec> describe(PackageId id) { 31 Future<Pubspec> describe(PackageId id) {
40 return readTextFile(join(rootDir, "revision")).transform((revision) { 32 return readTextFile(join(rootDir, "revision")).chain((revision) {
41 var version = new Version.parse("0.0.0-r.${revision.trim()}"); 33 var version = new Version.parse("0.0.0-r.${revision.trim()}");
42 return new Pubspec(id.name, version, <PackageRef>[]); 34 // Read the pubspec for the package's dependencies.
35 return _getPackagePath(id).chain((packageDir) {
36 // TODO(rnystrom): What if packageDir is null?
37 return Package.load(id.name, packageDir, systemCache.sources)
38 .transform((package) {
39 // Ignore the pubspec's version, and use the SDK's.
40 return new Pubspec(id.name, version, package.pubspec.dependencies);
41 });
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.
42 });
43 }); 43 });
44 } 44 }
45 45
46 /** 46 /// Since all the SDK files are already available locally, installation just
47 * Since all the SDK files are already available locally, installation just 47 /// involves symlinking the SDK library into the packages directory.
48 * involves symlinking the SDK library into the packages directory.
49 */
50 Future<bool> install(PackageId id, String destPath) { 48 Future<bool> install(PackageId id, String destPath) {
51 // Look in "pkg" first. 49 return _getPackagePath(id).chain((path) {
52 var sourcePath = join(rootDir, "pkg", id.description); 50 if (path == null) return new Future<bool>.immediate(false);
53 return exists(sourcePath).chain((found) {
54 if (!found) {
55 // TODO(rnystrom): Get rid of this when all SDK packages are moved from
56 // "lib" to "pkg".
57 // Not in "pkg", so try "lib".
58 sourcePath = join(rootDir, "lib", id.description);
59 return exists(sourcePath).chain((found) {
60 if (!found) return new Future<bool>.immediate(false);
61 return createPackageSymlink(id.name, sourcePath, destPath).transform(
62 (_) => true);
63 });
64 }
65 51
66 return createPackageSymlink(id.name, sourcePath, destPath).transform( 52 return createPackageSymlink(id.name, path, destPath).transform(
67 (_) => true); 53 (_) => true);
68 }); 54 });
69 } 55 }
56
57 /// Gets the path in the SDK to the directory containing package [id]. Looks
58 /// inside both "pkg" and "lib" in the SDK. Returns `null` if the package
59 /// could not be found.
60 Future<String> _getPackagePath(PackageId id) {
61 // Look in "pkg" first.
62 var pkgPath = join(rootDir, "pkg", id.description);
63 return exists(pkgPath).chain((found) {
64 if (found) return new Future<String>.immediate(pkgPath);
65
66 // Not in "pkg", so try "lib".
67 // TODO(rnystrom): Get rid of this when all SDK packages are moved from
68 // "lib" to "pkg".
69 var libPath = join(rootDir, "lib", id.description);
70 return exists(libPath).transform((found) => found ? libPath : null);
71 });
72 }
70 } 73 }
OLDNEW
« 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