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('io.dart'); | 7 #import('io.dart'); |
8 #import('package.dart'); | 8 #import('package.dart'); |
9 #import('source.dart'); | 9 #import('source.dart'); |
10 | 10 |
11 /** | 11 /** |
12 * A package source that uses libraries from the Dart SDK. | 12 * A package source that uses libraries from the Dart SDK. |
13 * | 13 * |
14 * This currently uses the "sdkdir" command-line argument to find the SDK. | 14 * This currently uses the "sdkdir" command-line argument to find the SDK. |
15 */ | 15 */ |
16 // TODO(nweiz): This should read the SDK directory from an environment variable | |
17 // once we can set those for tests. | |
18 class SdkSource extends Source { | 16 class SdkSource extends Source { |
19 final String name = "sdk"; | 17 final String name = "sdk"; |
20 final bool shouldCache = false; | 18 final bool shouldCache = false; |
21 | 19 |
22 /** | 20 /** |
23 * The root directory of the Dart SDK. | 21 * The root directory of the Dart SDK. |
24 */ | 22 */ |
25 final String rootDir; | 23 final String _rootDir; |
26 | 24 |
27 SdkSource(this.rootDir); | 25 String get rootDir() { |
| 26 if (_rootDir != null) return _rootDir; |
| 27 throw "Pub can't find the Dart SDK. Please set the DART_SDK environment " |
| 28 "variable to the Dart SDK directory."; |
| 29 } |
| 30 |
| 31 SdkSource(this._rootDir); |
28 | 32 |
29 /** | 33 /** |
30 * An SDK package has no dependencies. Its version number is inferred from the | 34 * An SDK package has no dependencies. Its version number is inferred from the |
31 * revision number of the SDK itself. | 35 * revision number of the SDK itself. |
32 */ | 36 */ |
33 Future<Pubspec> describe(PackageId id) { | 37 Future<Pubspec> describe(PackageId id) { |
34 return readTextFile(join(rootDir, "revision")).transform((revision) => | 38 return readTextFile(join(rootDir, "revision")).transform((revision) => |
35 new Pubspec("0.0.0-r.${revision.trim()}", <PackageRef>[])); | 39 new Pubspec("0.0.0-r.${revision.trim()}", <PackageRef>[])); |
36 } | 40 } |
37 | 41 |
38 /** | 42 /** |
39 * Since all the SDK files are already available locally, installation just | 43 * Since all the SDK files are already available locally, installation just |
40 * involves symlinking the SDK library into the packages directory. | 44 * involves symlinking the SDK library into the packages directory. |
41 */ | 45 */ |
42 Future<bool> install(PackageId id, String destPath) { | 46 Future<bool> install(PackageId id, String destPath) { |
43 var sourcePath = join(rootDir, "lib", id.description); | 47 var sourcePath = join(rootDir, "lib", id.description); |
44 return exists(sourcePath).chain((exists) { | 48 return exists(sourcePath).chain((exists) { |
45 if (!exists) return new Future<bool>.immediate(false); | 49 if (!exists) return new Future<bool>.immediate(false); |
46 return createSymlink(sourcePath, destPath).transform((_) => true); | 50 return createSymlink(sourcePath, destPath).transform((_) => true); |
47 }); | 51 }); |
48 } | 52 } |
49 } | 53 } |
OLD | NEW |