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

Side by Side Diff: utils/pub/sdk_source.dart

Issue 12079112: Make a bunch of stuff in pub synchronous. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix after merge. Created 7 years, 10 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
« no previous file with comments | « utils/pub/pub.dart ('k') | utils/pub/source.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 '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 'utils.dart';
13 import 'version.dart'; 14 import 'version.dart';
14 15
15 /// A package source that uses libraries from the Dart SDK. 16 /// A package source that uses libraries from the Dart SDK.
16 class SdkSource extends Source { 17 class SdkSource extends Source {
17 final String name = "sdk"; 18 final String name = "sdk";
18 final bool shouldCache = false; 19 final bool shouldCache = false;
19 20
20 /// SDK packages are not individually versioned. Instead, their version is 21 /// SDK packages are not individually versioned. Instead, their version is
21 /// inferred from the revision number of the SDK itself. 22 /// inferred from the revision number of the SDK itself.
22 Future<Pubspec> describe(PackageId id) { 23 Future<Pubspec> describe(PackageId id) {
23 return _getPackagePath(id).then((packageDir) { 24 return defer(() {
25 var packageDir = _getPackagePath(id);
24 // TODO(rnystrom): What if packageDir is null? 26 // TODO(rnystrom): What if packageDir is null?
25 return Package.load(id.name, packageDir, systemCache.sources); 27 var package = new Package(id.name, packageDir, systemCache.sources);
26 }).then((package) {
27 // Ignore the pubspec's version, and use the SDK's. 28 // Ignore the pubspec's version, and use the SDK's.
28 return new Pubspec(id.name, sdk.version, package.pubspec.dependencies, 29 return new Pubspec(id.name, sdk.version, package.pubspec.dependencies,
29 package.pubspec.environment); 30 package.pubspec.environment);
30 }); 31 });
31 } 32 }
32 33
33 /// Since all the SDK files are already available locally, installation just 34 /// Since all the SDK files are already available locally, installation just
34 /// involves symlinking the SDK library into the packages directory. 35 /// involves symlinking the SDK library into the packages directory.
35 Future<bool> install(PackageId id, String destPath) { 36 Future<bool> install(PackageId id, String destPath) {
36 return _getPackagePath(id).then((path) { 37 return defer(() {
37 if (path == null) return new Future<bool>.immediate(false); 38 var path = _getPackagePath(id);
39 if (path == null) return false;
38 40
39 return createPackageSymlink(id.name, path, destPath).then( 41 return createPackageSymlink(id.name, path, destPath).then((_) => true);
40 (_) => true);
41 }); 42 });
42 } 43 }
43 44
44 /// Gets the path in the SDK's "pkg" directory to the directory containing 45 /// Gets the path in the SDK's "pkg" directory to the directory containing
45 /// package [id]. Returns `null` if the package could not be found. 46 /// package [id]. Returns `null` if the package could not be found.
46 Future<String> _getPackagePath(PackageId id) { 47 String _getPackagePath(PackageId id) {
47 var pkgPath = join(sdk.rootDirectory, "pkg", id.description); 48 var pkgPath = join(sdk.rootDirectory, "pkg", id.description);
48 return dirExists(pkgPath).then((found) => found ? pkgPath : null); 49 return dirExists(pkgPath) ? pkgPath : null;
49 } 50 }
50 } 51 }
OLDNEW
« no previous file with comments | « utils/pub/pub.dart ('k') | utils/pub/source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698