-
Notifications
You must be signed in to change notification settings - Fork 230
/
sdk.dart
74 lines (59 loc) · 2.37 KB
/
sdk.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:collection';
import 'package:pub_semver/pub_semver.dart';
import 'sdk/dart.dart';
import 'sdk/flutter.dart';
import 'sdk/fuchsia.dart';
/// An SDK that can provide packages and on which pubspecs can express version
/// constraints.
abstract class Sdk {
/// Is this the Dart sdk?
bool get isDartSdk => identifier == 'dart';
/// This SDK's human-readable name.
String get name;
/// The identifier used in pubspecs to refer to this SDK.
///
/// This should match the key used in [sdks].
String get identifier => name.toLowerCase();
/// Whether the user has this SDK installed and configured so that it's
/// accessible to pub.
bool get isAvailable;
/// The SDK's version number, or `null` if the SDK is unavailable.
Version? get version;
/// A message to indicate to the user how to make this SDK available.
///
/// This is printed after a version solve where the SDK wasn't found. It may
/// be `null`, indicating that no such message should be printed.
String? get installMessage;
/// Whether or not non-SDK dependencies are allowed in the regular
/// dependencies section for packages vendored by this SDK.
bool get allowsNonSdkDepsInSdkPackages;
/// Returns the path to the package [name] within this SDK.
///
/// Returns `null` if the SDK isn't available or if it doesn't contain a
/// package with the given name.
String? packagePath(String name);
@override
String toString() => name;
}
/// A map from SDK identifiers that appear in pubspecs to the implementations of
/// those SDKs.
final sdks = UnmodifiableMapView<String, Sdk>(
{'dart': sdk, 'flutter': FlutterSdk(), 'fuchsia': FuchsiaSdk()},
);
/// The core Dart SDK.
final sdk = DartSdk();
extension AsCompatibleWithIfPossible on VersionConstraint {
// Returns `this` expressed as [VersionConstraint.compatibleWith] if possible.
VersionConstraint asCompatibleWithIfPossible() {
final range = this;
if (range is! VersionRange) return this;
final min = range.min;
if (min == null) return this;
final asCompatibleWith = VersionConstraint.compatibleWith(min);
if (asCompatibleWith == this) return asCompatibleWith;
return this;
}
}