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

Unified Diff: utils/pub/sdk_source.dart

Issue 11871028: Clean up code that locates SDK and SDK version. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 7 years, 11 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 | « utils/pub/sdk/pub.bat ('k') | utils/pub/system_cache.dart » ('j') | no next file with comments »
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 13ffa2525e91176f6d3cc1742c8f9593fff10879..7129a7b45bc420f924b23fd04dd983162f3654a5 100644
--- a/utils/pub/sdk_source.dart
+++ b/utils/pub/sdk_source.dart
@@ -8,6 +8,7 @@ import 'dart:async';
import 'io.dart';
import 'package.dart';
import 'pubspec.dart';
+import 'sdk.dart' as sdk;
import 'source.dart';
import 'version.dart';
@@ -16,31 +17,15 @@ class SdkSource extends Source {
final String name = "sdk";
final bool shouldCache = false;
- /// The root directory of the Dart SDK.
- final String _rootDir;
-
- String get rootDir {
- if (_rootDir != null) return _rootDir;
- throw "Pub can't find the Dart SDK. Please set the DART_SDK environment "
- "variable to the Dart SDK directory.";
- }
-
- SdkSource(this._rootDir);
-
/// SDK packages are not individually versioned. Instead, their version is
/// inferred from the revision number of the SDK itself.
Future<Pubspec> describe(PackageId id) {
- var version;
- return readTextFile(join(rootDir, "revision")).then((revision) {
- version = new Version.parse("0.0.0-r.${revision.trim()}");
- // Read the pubspec for the package's dependencies.
- return _getPackagePath(id);
- }).then((packageDir) {
+ return _getPackagePath(id).then((packageDir) {
// TODO(rnystrom): What if packageDir is null?
return Package.load(id.name, packageDir, systemCache.sources);
}).then((package) {
// Ignore the pubspec's version, and use the SDK's.
- return new Pubspec(id.name, version, package.pubspec.dependencies);
+ return new Pubspec(id.name, sdk.version, package.pubspec.dependencies);
});
}
@@ -55,20 +40,10 @@ class SdkSource extends Source {
});
}
- /// 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.
+ /// Gets the path in the SDK's "pkg" directory to the directory containing
+ /// package [id]. 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).then((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).then((found) => found ? libPath : null);
- });
+ var pkgPath = join(sdk.rootDirectory, "pkg", id.description);
+ return dirExists(pkgPath).then((found) => found ? pkgPath : null);
}
}
« no previous file with comments | « utils/pub/sdk/pub.bat ('k') | utils/pub/system_cache.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698