in lib/src/report/multi_platform.dart [15:123]
Future<ReportSection> multiPlatform(String packageDir, Pubspec pubspec) async {
Subsection subsection;
if (File(p.join(packageDir, '.dart_tool', 'package_config.json'))
.existsSync()) {
final tags = <String>[];
final explanations = <Explanation>[];
final tagger = Tagger(packageDir);
final sdkTags = <String>[];
final sdkExplanations = <Explanation>[];
tagger.sdkTags(sdkTags, sdkExplanations);
final flutterPackage = pubspec.usesFlutter;
String platformList(List<String> tags, Map<String, String> tagNames) {
return tagNames.entries.map((entry) {
if (tags.contains(entry.key)) {
return '**${entry.value}**';
} else {
return entry.value;
}
}).join(', ');
}
Subsection scorePlatforms(
List<String> tags, List<Explanation> explanations) {
final tagNames = const {
'platform:ios': 'iOS',
'platform:android': 'Android',
'platform:web': 'Web',
'platform:windows': 'Windows',
'platform:macos': 'MacOS',
'platform:linux': 'Linux',
};
final sdkExplanations =
explanations.where((e) => e.tag != null && e.tag!.startsWith('sdk:'));
final platformExplanations = explanations
.where((e) => e.tag == null || !e.tag!.startsWith('sdk:'));
final officialExplanations = platformExplanations.where((e) =>
!tags.contains(e.tag) &&
(e.tag == null || tagNames.containsKey(e.tag)));
final trustExplanations = explanations.where((e) => tags.contains(e.tag));
final paragraphs = <Paragraph>[
if (sdkExplanations.isNotEmpty) RawParagraph('SDK issues found:'),
...sdkExplanations.map(explanationToIssue),
for (final tag in tags.where((e) => e.startsWith('platform')))
RawParagraph('* ✓ ${tagNames[tag]}'),
if (officialExplanations.isNotEmpty)
RawParagraph('\nThese platforms are not supported:\n'),
...officialExplanations.map(explanationToIssue),
if (trustExplanations.isNotEmpty)
RawParagraph(
'\nThese issues are present but do not affect the score, because they may not originate in your package:\n'),
...trustExplanations.map(explanationToIssue),
];
final officialTags = tags.where(tagNames.containsKey).toList();
final status =
officialTags.where((tag) => tag.startsWith('platform:')).isEmpty
? ReportStatus.failed
: ReportStatus.passed;
final score = {
ReportStatus.failed: 0,
ReportStatus.partial: 10,
ReportStatus.passed: 20
}[status];
final platforms = platformList(tags, tagNames);
final description = 'Supports ${officialTags.length} of '
'${tagNames.length} possible platforms ($platforms)';
return Subsection(description, paragraphs, score!, 20, status);
}
tagger.platformTags(tags, explanations, trustDeclarations: true);
if (!flutterPackage) {
tagger.runtimeTags(tags, explanations);
// We don't want the native-aot runtime to be explained here.
explanations.removeWhere(
(explanation) => explanation.tag == Runtime.nativeAot.tag,
);
}
subsection = scorePlatforms(
tags,
explanations,
);
} else {
subsection = Subsection(
'Doesn\'t support any platforms',
[
Issue(
'Package resolution failed. Could not determine platforms.',
suggestion: 'Run `dart pub get` for more information.',
)
],
0,
20,
ReportStatus.failed,
);
}
return makeSection(
id: ReportSectionId.platform,
title: 'Platform Support',
maxPoints: 20,
basePath: packageDir,
subsections: [subsection],
maxIssues: 20);
}