Skip to content

Commit

Permalink
Make platform names externally referenceable. (dart-lang#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored and kevmoo committed Aug 2, 2017
1 parent afc2fcf commit ebe6890
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions lib/src/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ part 'platform.g.dart';
class PubspecPlatform {
final String description;

static const PubspecPlatform flutter = const PubspecPlatform._('flutter');
static const PubspecPlatform flutter =
const PubspecPlatform._(PlatformFlags.flutter);

static const PubspecPlatform undefined = const PubspecPlatform._('undefined');
static const PubspecPlatform undefined =
const PubspecPlatform._(PlatformFlags.undefined);

bool get isFlutter => description == flutter.description;

const PubspecPlatform._(this.description);

factory PubspecPlatform.fromJson(String value) {
switch (value) {
case 'flutter':
case PlatformFlags.flutter:
return flutter;
case 'undefined':
case PlatformFlags.undefined:
return undefined;
default:
throw new ArgumentError.value(value, 'value', 'Not a supported value.');
Expand All @@ -35,11 +37,26 @@ class PubspecPlatform {
}

abstract class PlatformFlags {
/// Denotes a package that references Flutter in `pubspec.yaml`.
/// Package uses or depends on Flutter.
static const String flutter = 'flutter';

/// Denotes a library that depends on a native extensions via `dart-ext:`
/// Package uses or depends on a native extensions via `dart-ext:`
static const String dartExtension = 'dart-ext';

/// Package works everywhere.
static const String everywhere = 'everywhere';

/// Package's platform is unspecified.
static const String undefined = 'undefined';

/// Package's dependencies are in conflict, won't work.
static const String conflict = 'conflict';

/// Package is available in server applications.
static const String server = 'server';

/// Package is available in web applications.
static const String web = 'web';
}

@JsonSerializable()
Expand All @@ -61,10 +78,10 @@ class PlatformSummary extends Object with _$PlatformSummarySerializerMixin {
String get description {
if (pubspec.isFlutter) {
if (libraries.values.every((pi) => pi.worksOnFlutter)) {
return 'flutter';
return PlatformFlags.flutter;
}
assert(hasConflict);
return 'conflict';
return PlatformFlags.conflict;
}

assert(pubspec == PubspecPlatform.undefined);
Expand Down Expand Up @@ -116,25 +133,25 @@ class PlatformInfo extends Object with _$PlatformInfoSerializerMixin {

Set<String> get descriptionSet {
if (worksEverywhere) {
return new Set.from(['everywhere']);
return new Set.from([PlatformFlags.everywhere]);
}

var items = <String>[];
if (worksOnFlutter) {
items.add('flutter');
items.add(PlatformFlags.flutter);
}

if (worksOnServer) {
items.add('server');
items.add(PlatformFlags.server);
}

if (worksOnWeb) {
items.add('web');
items.add(PlatformFlags.web);
}

if (items.isEmpty) {
assert(hasConflict);
return new Set.from(['conflict']);
return new Set.from([PlatformFlags.conflict]);
}

assert(!hasConflict);
Expand Down

0 comments on commit ebe6890

Please sign in to comment.