Skip to content

Commit

Permalink
Do wasm-checks separately
Browse files Browse the repository at this point in the history
  • Loading branch information
sigurdm committed Feb 9, 2024
1 parent a192fcb commit 6bd6194
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 37 deletions.
1 change: 1 addition & 0 deletions lib/src/package_analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class PackageAnalyzer {
tagger.runtimeTags(tags_, explanations);
tagger.flutterPluginTags(tags_, explanations);
tagger.nullSafetyTags(tags_, explanations);
tagger.wasmReadyTag(tags_, explanations);
// tags are exposed, explanations are ignored
// TODO: use a single result object to derive tags + report
tags.addAll(tags_);
Expand Down
32 changes: 19 additions & 13 deletions lib/src/tag/_specs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ class Runtime {
static final nativeJit =
Runtime('vm-native', _onNativeJit, tag: PanaTags.runtimeNativeJit);

static final recognizedRuntimes = [
nativeAot,
nativeJit,
web,
];

static final nativeAot = Runtime(
'native-aot',
{
Expand Down Expand Up @@ -240,23 +246,23 @@ class Sdk {
this.allowedSdks,
this.allowedRuntime, {
required this.tag,
required this.recognizedRuntimes,
});

static Sdk dart = Sdk('dart', 'Dart', ['dart'], Runtime.broadDart,
tag: PanaTags.sdkDart,
recognizedRuntimes: [
Runtime.nativeAot,
Runtime.nativeJit,
Runtime.web,
Runtime.wasm,
]);
static Sdk dart = Sdk(
'dart',
'Dart',
['dart'],
Runtime.broadDart,
tag: PanaTags.sdkDart,
);

static Sdk flutter = Sdk(
'flutter', 'Flutter', ['dart', 'flutter'], Runtime.broadFlutter,
tag: PanaTags.sdkFlutter, recognizedRuntimes: [Runtime.wasm]);

final List<Runtime> recognizedRuntimes;
'flutter',
'Flutter',
['dart', 'flutter'],
Runtime.broadFlutter,
tag: PanaTags.sdkFlutter,
);

static List<Sdk> knownSdks = [dart, flutter];
}
36 changes: 30 additions & 6 deletions lib/src/tag/tagger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,30 @@ class Tagger {
}
}

/// Adds the is:wasm-ready tag if there are no uses of disallowed dart: libraries.
void wasmReadyTag(List<String> tags, List<Explanation> explanations) {
final runtime = Runtime.wasm;
final finder = runtimeViolationFinder(
LibraryGraph(_session, runtime.declaredVariables),
runtime,
(List<Uri> path) => Explanation(
'Package not compatible with runtime ${runtime.name}',
'Because:\n${LibraryGraph.formatPath(path)}',
tag: runtime.tag));
var supports = true;
for (final lib in _topLibraries) {
final violationResult = finder.findViolation(lib);
if (violationResult != null) {
explanations.add(violationResult);
supports = false;
break;
}
}
if (supports) {
tags.add(runtime.tag);
}
}

/// Adds tags for the Dart runtimes that this package supports to [tags].
///
/// Adds [Explanation]s to [explanations] for runtimes not supported.
Expand All @@ -343,14 +367,14 @@ class Tagger {
if (_isBinaryOnly) {
tags.addAll(<String>[Runtime.nativeAot.tag, Runtime.nativeJit.tag]);
} else {
final sdkViolationFinder = SdkViolationFinder(_packageGraph,
_usesFlutter ? Sdk.dart : Sdk.flutter, _pubspecCache, _session);
final dartSdkViolationFinder = SdkViolationFinder(
_packageGraph, Sdk.dart, _pubspecCache, _session);
final sdkViolation =
sdkViolationFinder.findSdkViolation(packageName, _topLibraries);
dartSdkViolationFinder.findSdkViolation(packageName, _topLibraries);
if (sdkViolation != null) {
explanations.add(sdkViolation);
} else {
for (final runtime in sdkViolationFinder.sdk.recognizedRuntimes) {
for (final runtime in Runtime.recognizedRuntimes) {
final finder = runtimeViolationFinder(
LibraryGraph(_session, runtime.declaredVariables),
runtime,
Expand Down Expand Up @@ -388,7 +412,7 @@ class Tagger {
/// specifying a lower dart sdk bound >= 2.12.
///
/// - No libraries in the import closure of [_publicLibraries] opt out of
/// null-safety. (For each runtime in [Sdk.recognizedRuntimes]).
/// null-safety. (For each runtime in [Runtime.recognizedRuntimes]).
void nullSafetyTags(List<String> tags, List<Explanation> explanations) {
try {
var foundIssues = false;
Expand All @@ -414,7 +438,7 @@ class Tagger {
explanations.add(sdkConstraintResult);
foundIssues = true;
} else {
for (final runtime in Sdk.dart.recognizedRuntimes) {
for (final runtime in Runtime.recognizedRuntimes) {
final optOutViolationFinder = PathFinder<Uri>(
LibraryGraph(_session, runtime.declaredVariables),
(library) {
Expand Down
2 changes: 1 addition & 1 deletion test/goldens/end2end/async-2.11.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
"runtime:native-aot",
"runtime:native-jit",
"runtime:web",
"is:wasm-ready",
"is:null-safe",
"is:wasm-ready",
"is:dart3-compatible",
"license:bsd-3-clause",
"license:fsf-libre",
Expand Down
2 changes: 1 addition & 1 deletion test/goldens/end2end/http-0.13.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
"runtime:native-aot",
"runtime:native-jit",
"runtime:web",
"is:wasm-ready",
"is:null-safe",
"is:wasm-ready",
"is:dart3-compatible",
"license:bsd-3-clause",
"license:fsf-libre",
Expand Down
2 changes: 1 addition & 1 deletion test/goldens/end2end/lints-1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"runtime:native-aot",
"runtime:native-jit",
"runtime:web",
"is:wasm-ready",
"is:null-safe",
"is:wasm-ready",
"is:dart3-compatible",
"license:bsd-3-clause",
"license:fsf-libre",
Expand Down
1 change: 1 addition & 0 deletions test/goldens/end2end/onepub-1.1.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"runtime:native-aot",
"runtime:native-jit",
"is:null-safe",
"is:wasm-ready",
"is:dart3-compatible",
"license:unknown"
],
Expand Down
19 changes: 4 additions & 15 deletions test/tag/tag_end2end_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ void main() {
'runtime:native-jit',
'runtime:native-aot',
'runtime:web',
'is:wasm-ready',
},
explanations: isEmpty);
_expectTagging(tagger.flutterPluginTags, tags: isEmpty);
Expand Down Expand Up @@ -315,7 +314,6 @@ int fourtyTwo() => 42;
'runtime:native-aot',
'runtime:native-jit',
'runtime:web',
'is:wasm-ready'
]);
_expectTagging(tagger.flutterPluginTags, tags: isEmpty);
});
Expand Down Expand Up @@ -411,12 +409,6 @@ Because:
finding: 'Package not compatible with runtime js', explanation: '''
Because:
* `package:my_package/my_package.dart` that imports:
* `dart:io`'''),
_explanation(
finding: 'Package not compatible with runtime wasm',
explanation: '''
Because:
* `package:my_package/my_package.dart` that imports:
* `dart:io`'''),
});
_expectTagging(tagger.flutterPluginTags, tags: isEmpty);
Expand Down Expand Up @@ -464,7 +456,6 @@ int fourtyThree() => 43;
'runtime:native-aot',
'runtime:native-jit',
'runtime:web',
'is:wasm-ready',
},
explanations: isEmpty);
_expectTagging(tagger.flutterPluginTags, tags: isEmpty);
Expand Down Expand Up @@ -523,7 +514,6 @@ name: my_package
'runtime:native-jit',
'runtime:native-aot',
'runtime:web',
'is:wasm-ready',
},
explanations: isEmpty);
_expectTagging(tagger.flutterPluginTags, tags: isEmpty);
Expand Down Expand Up @@ -553,7 +543,6 @@ name: my_package
'runtime:native-jit',
'runtime:native-aot',
'runtime:web',
'is:wasm-ready',
},
explanations: isEmpty);
_expectTagging(tagger.flutterPluginTags, tags: isEmpty);
Expand Down Expand Up @@ -601,7 +590,7 @@ import 'dart:js';

await descriptor.create();
final tagger = Tagger('${descriptor.io.path}/my_package');
_expectTagging(tagger.runtimeTags,
_expectTagging(tagger.wasmReadyTag,
tags: isNot(contains('is:wasm-ready')));
});

Expand All @@ -616,7 +605,7 @@ import 'dart:js_util';

await descriptor.create();
final tagger = Tagger('${descriptor.io.path}/my_package');
_expectTagging(tagger.runtimeTags,
_expectTagging(tagger.wasmReadyTag,
tags: isNot(contains('is:wasm-ready')));
});
test('Excluded with dart:html', () async {
Expand All @@ -630,7 +619,7 @@ import 'dart:html';

await descriptor.create();
final tagger = Tagger('${descriptor.io.path}/my_package');
_expectTagging(tagger.runtimeTags,
_expectTagging(tagger.wasmReadyTag,
tags: isNot(contains('is:wasm-ready')));
});

Expand All @@ -650,7 +639,7 @@ import 'dart:js_interop_unsafe';

await descriptor.create();
final tagger = Tagger('${descriptor.io.path}/my_package');
_expectTagging(tagger.runtimeTags, tags: contains('is:wasm-ready'));
_expectTagging(tagger.wasmReadyTag, tags: contains('is:wasm-ready'));
});
});
}
Expand Down

0 comments on commit 6bd6194

Please sign in to comment.