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('pubspec.dart'); |
9 #import('source.dart'); | 10 #import('source.dart'); |
| 11 #import('version.dart'); |
10 | 12 |
11 /** | 13 /** |
12 * A package source that uses libraries from the Dart SDK. | 14 * A package source that uses libraries from the Dart SDK. |
13 * | 15 * |
14 * This currently uses the "sdkdir" command-line argument to find the SDK. | 16 * This currently uses the "sdkdir" command-line argument to find the SDK. |
15 */ | 17 */ |
16 // TODO(nweiz): This should read the SDK directory from an environment variable | 18 // TODO(nweiz): This should read the SDK directory from an environment variable |
17 // once we can set those for tests. | 19 // once we can set those for tests. |
18 class SdkSource extends Source { | 20 class SdkSource extends Source { |
19 final String name = "sdk"; | 21 final String name = "sdk"; |
20 final bool shouldCache = false; | 22 final bool shouldCache = false; |
21 | 23 |
22 /** | 24 /** |
23 * The root directory of the Dart SDK. | 25 * The root directory of the Dart SDK. |
24 */ | 26 */ |
25 final String rootDir; | 27 final String rootDir; |
26 | 28 |
27 SdkSource(this.rootDir); | 29 SdkSource(this.rootDir); |
28 | 30 |
29 /** | 31 /** |
30 * An SDK package has no dependencies. Its version number is inferred from the | 32 * An SDK package has no dependencies. Its version number is inferred from the |
31 * revision number of the SDK itself. | 33 * revision number of the SDK itself. |
32 */ | 34 */ |
33 Future<Pubspec> describe(PackageId id) { | 35 Future<Pubspec> describe(PackageId id) { |
34 return readTextFile(join(rootDir, "revision")).transform((revision) => | 36 return readTextFile(join(rootDir, "revision")).transform((revision) { |
35 new Pubspec("0.0.0-r.${revision.trim()}", <PackageRef>[])); | 37 var version = new Version.parse("0.0.0-r.${revision.trim()}"); |
| 38 return new Pubspec(version, <PackageRef>[]); |
| 39 }); |
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 |