Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is:wasm-ready tag #1336

Merged
merged 13 commits into from
Feb 9, 2024
8 changes: 4 additions & 4 deletions lib/src/report/multi_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Future<ReportSection> multiPlatform(String packageDir, Pubspec pubspec) async {

Subsection scorePlatforms(
List<String> tags, List<Explanation> explanations) {
// Scoring and the report only takes these platforms into account.
final tagNames = const {
PanaTags.platformIos: 'iOS',
PanaTags.platformAndroid: 'Android',
Expand All @@ -45,12 +46,13 @@ Future<ReportSection> multiPlatform(String packageDir, Pubspec pubspec) async {
PanaTags.platformMacos: 'macOS',
PanaTags.platformLinux: 'Linux',
};
final officialTags = tags.where(tagNames.containsKey).toList();
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) &&
!officialTags.contains(e.tag) &&
(e.tag == null || tagNames.containsKey(e.tag)));
final trustExplanations = explanations.where((e) => tags.contains(e.tag));
final paragraphs = <Paragraph>[
Expand All @@ -59,7 +61,7 @@ Future<ReportSection> multiPlatform(String packageDir, Pubspec pubspec) async {
if (sdkExplanations.isNotEmpty)
// This empty line is required for `package:markdown` to render the following list correctly.
RawParagraph(''),
for (final tag in tags.where((e) => e.startsWith('platform')))
for (final tag in officialTags.where((e) => e.startsWith('platform')))
RawParagraph('* ✓ ${tagNames[tag]}'),
if (officialExplanations.isNotEmpty)
RawParagraph('\nThese platforms are not supported:\n'),
Expand All @@ -70,8 +72,6 @@ Future<ReportSection> multiPlatform(String packageDir, Pubspec pubspec) async {
...trustExplanations.map(explanationToIssue),
];

final officialTags = tags.where(tagNames.containsKey).toList();

final status =
officialTags.where((tag) => tag.startsWith('platform:')).isEmpty
? ReportStatus.failed
Expand Down
38 changes: 19 additions & 19 deletions lib/src/tag/_specs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ 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 All @@ -90,6 +84,12 @@ class Runtime {
tag: PanaTags.runtimeWeb,
);

static final wasm = Runtime(
'wasm',
{..._onAllPlatforms, 'ui', 'ui_web', 'js_interop', 'js_interop_unsafe'},
tag: PanaTags.isWasmReady,
);

static final flutterNative = Runtime(
'flutter-native',
{
Expand Down Expand Up @@ -240,23 +240,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,
);
static Sdk dart = Sdk('dart', 'Dart', ['dart'], Runtime.broadDart,
tag: PanaTags.sdkDart,
recognizedRuntimes: [
Runtime.nativeAot,
Runtime.nativeJit,
Runtime.web,
Runtime.wasm,
]);

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

final List<Runtime> recognizedRuntimes;

static List<Sdk> knownSdks = [dart, flutter];
}
1 change: 1 addition & 0 deletions lib/src/tag/pana_tags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ abstract class PanaTags {
static const runtimeFlutterNative = 'runtime:flutter-native';
static const runtimeFlutterWeb = 'runtime:flutter-web';
static const runtimeWeb = 'runtime:web';
static const isWasmReady = 'is:wasm-ready';

// platform tags
static const platformAndroid = 'platform:android';
Expand Down
10 changes: 5 additions & 5 deletions lib/src/tag/tagger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,14 @@ class Tagger {
if (_isBinaryOnly) {
tags.addAll(<String>[Runtime.nativeAot.tag, Runtime.nativeJit.tag]);
} else {
final dartSdkViolationFinder = SdkViolationFinder(
_packageGraph, Sdk.dart, _pubspecCache, _session);
final sdkViolationFinder = SdkViolationFinder(_packageGraph,
_usesFlutter ? Sdk.dart : Sdk.flutter, _pubspecCache, _session);
final sdkViolation =
dartSdkViolationFinder.findSdkViolation(packageName, _topLibraries);
sdkViolationFinder.findSdkViolation(packageName, _topLibraries);
if (sdkViolation != null) {
explanations.add(sdkViolation);
} else {
for (final runtime in Runtime.recognizedRuntimes) {
for (final runtime in sdkViolationFinder.sdk.recognizedRuntimes) {
final finder = runtimeViolationFinder(
LibraryGraph(_session, runtime.declaredVariables),
runtime,
Expand Down Expand Up @@ -414,7 +414,7 @@ class Tagger {
explanations.add(sdkConstraintResult);
foundIssues = true;
} else {
for (final runtime in Runtime.recognizedRuntimes) {
for (final runtime in Sdk.dart.recognizedRuntimes) {
final optOutViolationFinder = PathFinder<Uri>(
LibraryGraph(_session, runtime.declaredVariables),
(library) {
Expand Down
1 change: 1 addition & 0 deletions test/goldens/end2end/async-2.11.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"runtime:native-aot",
"runtime:native-jit",
"runtime:web",
"is:wasm-ready",
"is:null-safe",
"is:dart3-compatible",
"license:bsd-3-clause",
Expand Down
1 change: 1 addition & 0 deletions test/goldens/end2end/http-0.13.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"runtime:native-aot",
"runtime:native-jit",
"runtime:web",
"is:wasm-ready",
"is:null-safe",
"is:dart3-compatible",
"license:bsd-3-clause",
Expand Down
1 change: 1 addition & 0 deletions test/goldens/end2end/lints-1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"runtime:native-aot",
"runtime:native-jit",
"runtime:web",
"is:wasm-ready",
"is:null-safe",
"is:dart3-compatible",
"license:bsd-3-clause",
Expand Down
91 changes: 87 additions & 4 deletions test/tag/tag_end2end_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void main() {
'runtime:native-jit',
'runtime:native-aot',
'runtime:web',
'is:wasm-ready',
},
explanations: isEmpty);
_expectTagging(tagger.flutterPluginTags, tags: isEmpty);
Expand Down Expand Up @@ -310,8 +311,12 @@ int fourtyTwo() => 42;
_expectTagging(tagger.sdkTags, tags: {'sdk:flutter', 'sdk:dart'});
_expectTagging(tagger.platformTags,
tags: {'platform:windows', 'platform:android'});
_expectTagging(tagger.runtimeTags,
tags: ['runtime:native-aot', 'runtime:native-jit', 'runtime:web']);
_expectTagging(tagger.runtimeTags, tags: [
'runtime:native-aot',
'runtime:native-jit',
'runtime:web',
'is:wasm-ready'
]);
_expectTagging(tagger.flutterPluginTags, tags: isEmpty);
});

Expand Down Expand Up @@ -406,7 +411,13 @@ Because:
finding: 'Package not compatible with runtime js', explanation: '''
Because:
* `package:my_package/my_package.dart` that imports:
* `dart:io`''')
* `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 @@ -449,7 +460,12 @@ int fourtyThree() => 43;
},
explanations: isEmpty);
_expectTagging(tagger.runtimeTags,
tags: {'runtime:native-aot', 'runtime:native-jit', 'runtime:web'},
tags: {
'runtime:native-aot',
'runtime:native-jit',
'runtime:web',
'is:wasm-ready',
},
explanations: isEmpty);
_expectTagging(tagger.flutterPluginTags, tags: isEmpty);
});
Expand Down Expand Up @@ -507,6 +523,7 @@ 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 @@ -536,6 +553,7 @@ 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 @@ -570,6 +588,71 @@ name: my_package
_expectTagging(tagger.flutterPluginTags, tags: {'is:plugin'});
});
});

group('wasm tag', () {
test('Excluded with dart:js', () async {
final descriptor = d.dir('cache', [
packageWithPathDeps('my_package', lib: [
d.file('my_package.dart', '''
import 'dart:js';
'''),
])
]);

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

test('Excluded with dart:js_util', () async {
final descriptor = d.dir('cache', [
packageWithPathDeps('my_package', lib: [
d.file('my_package.dart', '''
import 'dart:js_util';
'''),
])
]);

await descriptor.create();
final tagger = Tagger('${descriptor.io.path}/my_package');
_expectTagging(tagger.runtimeTags,
tags: isNot(contains('is:wasm-ready')));
});
test('Excluded with dart:html', () async {
final descriptor = d.dir('cache', [
packageWithPathDeps('my_package', lib: [
d.file('my_package.dart', '''
import 'dart:html';
'''),
])
]);

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

test(
'Included with dart:ui, dart:ui_web dart:js_interop dart:js_interop_unsafe',
() async {
final descriptor = d.dir('cache', [
packageWithPathDeps('my_package', lib: [
d.file('my_package.dart', '''
import 'dart:ui';
import 'dart:ui_web';
import 'dart:js_interop';
import 'dart:js_interop_unsafe';
'''),
])
]);

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

Matcher _explanation(
Expand Down
Loading