in lib/src/tag/tagger.dart [216:293]
void platformTags(
List<String> tags,
List<Explanation> explanations, {
bool trustDeclarations = true,
}) {
try {
if (_isBinaryOnly) {
explanations.add(Explanation('Binary only',
'Cannot assign platform tags, it is a binary only package',
tag: null));
} else {
for (final platform in Platform.recognizedPlatforms) {
final libraryGraph =
LibraryGraph(_session, platform.runtime.declaredVariables);
final declaredPlatformDetector =
DeclaredPlatformDetector(_pubspecCache);
final violationFinder = PlatformViolationFinder(
platform,
libraryGraph,
declaredPlatformDetector,
_pubspecCache,
runtimeViolationFinder(
libraryGraph,
platform.runtime,
(List<Uri> path) => Explanation(
'Package not compatible with platform ${platform.name}',
'Because:\n${LibraryGraph.formatPath(path)}',
tag: platform.tag,
),
),
);
// Wanting to trust the plugins annotations when assigning tags we
// make a library graph that treats all libraries in packages with
// declared platforms as leaf-nodes.
//
// In this way the restrictions of its dependencies are not
// restricting the result.
//
// We still keep the unpruned detection for providing Explanations.
final prunedLibraryGraph = trustDeclarations
? LibraryGraph(_session, platform.runtime.declaredVariables,
isLeaf: declaredPlatformDetector.hasDeclaredPlatforms)
: libraryGraph;
final prunedViolationFinder = PlatformViolationFinder(
platform,
prunedLibraryGraph,
declaredPlatformDetector,
_pubspecCache,
runtimeViolationFinder(
prunedLibraryGraph,
platform.runtime,
(List<Uri> path) => Explanation(
'Package not compatible with platform ${platform.name}',
'Because:\n${LibraryGraph.formatPath(path)}',
tag: platform.tag)));
// Report only the first non-pruned violation as Explanation
final firstNonPrunedViolation =
violationFinder.firstViolation(packageName, _topLibraries);
if (firstNonPrunedViolation != null) {
explanations.add(firstNonPrunedViolation);
}
// Tag is supported, if there is no pruned violations
final firstPrunedViolation =
prunedViolationFinder.firstViolation(packageName, _topLibraries);
if (firstPrunedViolation == null) {
tags.add(platform.tag);
}
}
}
} on TagException catch (e) {
explanations
.add(Explanation('Tag detection failed.', e.message, tag: null));
return;
}
}