Skip to content

Commit 0489bda

Browse files
authored
[tool] Adds --wasm flag to the drive-examples command (flutter#7162)
I was unsure if we wanted to add a new platform option for this or add a `--wasm` flag to the command. Adding a `--wasm` flag seems more complicated since we would probably want to add extra handling around proper use of the flag, whereas adding a `web-wasm` platform should require no additional checks. This is in preparation for flutter/flutter#151664
1 parent 50238e7 commit 0489bda

File tree

3 files changed

+89
-6
lines changed

3 files changed

+89
-6
lines changed

script/tool/lib/src/common/core.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ const String kEnableExperiment = 'enable-experiment';
3737
/// land (e.g., dependency overrides in federated plugin combination PRs).
3838
const String kDoNotLandWarning = 'DO NOT MERGE';
3939

40+
/// Key for enabling web WASM compilation
41+
const String kWebWasmFlag = 'wasm';
42+
4043
/// Target platforms supported by Flutter.
4144
// ignore: public_member_api_docs
4245
enum FlutterPlatform { android, ios, linux, macos, web, windows }

script/tool/lib/src/drive_examples_command.dart

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'common/package_looping_command.dart';
1313
import 'common/plugin_utils.dart';
1414
import 'common/repository_package.dart';
1515

16-
const int _exitNoPlatformFlags = 2;
16+
const int _exitInvalidArgs = 2;
1717
const int _exitNoAvailableDevice = 3;
1818

1919
// From https://flutter.dev/to/integration-test-on-web
@@ -40,6 +40,8 @@ class DriveExamplesCommand extends PackageLoopingCommand {
4040
help: 'Runs the web implementation of the examples');
4141
argParser.addFlag(platformWindows,
4242
help: 'Runs the Windows implementation of the examples');
43+
argParser.addFlag(kWebWasmFlag,
44+
help: 'Compile to WebAssembly rather than JavaScript');
4345
argParser.addOption(
4446
kEnableExperiment,
4547
defaultsTo: '',
@@ -84,7 +86,7 @@ class DriveExamplesCommand extends PackageLoopingCommand {
8486
printError(
8587
'Exactly one of ${platformSwitches.map((String platform) => '--$platform').join(', ')} '
8688
'must be specified.');
87-
throw ToolExit(_exitNoPlatformFlags);
89+
throw ToolExit(_exitInvalidArgs);
8890
}
8991

9092
String? androidDevice;
@@ -107,22 +109,31 @@ class DriveExamplesCommand extends PackageLoopingCommand {
107109
iOSDevice = devices.first;
108110
}
109111

112+
final bool useWasm = getBoolArg(kWebWasmFlag);
113+
final bool hasPlatformWeb = getBoolArg(platformWeb);
114+
if (useWasm && !hasPlatformWeb) {
115+
printError('--wasm is only supported on the web platform');
116+
throw ToolExit(_exitInvalidArgs);
117+
}
118+
110119
_targetDeviceFlags = <String, List<String>>{
111120
if (getBoolArg(platformAndroid))
112121
platformAndroid: <String>['-d', androidDevice!],
113122
if (getBoolArg(platformIOS)) platformIOS: <String>['-d', iOSDevice!],
114123
if (getBoolArg(platformLinux)) platformLinux: <String>['-d', 'linux'],
115124
if (getBoolArg(platformMacOS)) platformMacOS: <String>['-d', 'macos'],
116-
if (getBoolArg(platformWeb))
125+
if (hasPlatformWeb)
117126
platformWeb: <String>[
118127
'-d',
119128
'web-server',
120129
'--web-port=7357',
121130
'--browser-name=chrome',
131+
if (useWasm)
132+
'--wasm'
122133
// TODO(dit): Clean this up, https://github.com/flutter/flutter/issues/151869
123-
if (platform.environment['CHANNEL']?.toLowerCase() == 'master')
124-
'--web-renderer=canvaskit',
125-
if (platform.environment['CHANNEL']?.toLowerCase() != 'master')
134+
else if (platform.environment['CHANNEL']?.toLowerCase() == 'master')
135+
'--web-renderer=canvaskit'
136+
else
126137
'--web-renderer=html',
127138
if (platform.environment.containsKey('CHROME_EXECUTABLE'))
128139
'--chrome-binary=${platform.environment['CHROME_EXECUTABLE']}',

script/tool/test/drive_examples_command_test.dart

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,24 @@ void main() {
8989
);
9090
});
9191

92+
test('fails if wasm flag is present but not web platform', () async {
93+
setMockFlutterDevicesOutput();
94+
Error? commandError;
95+
final List<String> output = await runCapturingPrint(
96+
runner, <String>['drive-examples', '--android', '--wasm'],
97+
errorHandler: (Error e) {
98+
commandError = e;
99+
});
100+
101+
expect(commandError, isA<ToolExit>());
102+
expect(
103+
output,
104+
containsAllInOrder(<Matcher>[
105+
contains('--wasm is only supported on the web platform'),
106+
]),
107+
);
108+
});
109+
92110
test('fails if multiple platforms are provided', () async {
93111
setMockFlutterDevicesOutput();
94112
Error? commandError;
@@ -691,6 +709,57 @@ void main() {
691709
]));
692710
});
693711

712+
test('drives a web plugin compiled to WASM', () async {
713+
final RepositoryPackage plugin = createFakePlugin(
714+
'plugin',
715+
packagesDir,
716+
extraFiles: <String>[
717+
'example/integration_test/plugin_test.dart',
718+
'example/test_driver/integration_test.dart',
719+
'example/web/index.html',
720+
],
721+
platformSupport: <String, PlatformDetails>{
722+
platformWeb: const PlatformDetails(PlatformSupport.inline),
723+
},
724+
);
725+
726+
final Directory pluginExampleDirectory = getExampleDir(plugin);
727+
728+
final List<String> output = await runCapturingPrint(runner, <String>[
729+
'drive-examples',
730+
'--web',
731+
'--wasm',
732+
]);
733+
734+
expect(
735+
output,
736+
containsAllInOrder(<Matcher>[
737+
contains('Running for plugin'),
738+
contains('No issues found!'),
739+
]),
740+
);
741+
742+
expect(
743+
processRunner.recordedCalls,
744+
orderedEquals(<ProcessCall>[
745+
ProcessCall(
746+
getFlutterCommand(mockPlatform),
747+
const <String>[
748+
'drive',
749+
'-d',
750+
'web-server',
751+
'--web-port=7357',
752+
'--browser-name=chrome',
753+
'--wasm',
754+
'--driver',
755+
'test_driver/integration_test.dart',
756+
'--target',
757+
'integration_test/plugin_test.dart',
758+
],
759+
pluginExampleDirectory.path),
760+
]));
761+
});
762+
694763
// TODO(dit): Clean this up, https://github.com/flutter/flutter/issues/151869
695764
test('drives a web plugin (html renderer in stable)', () async {
696765
// Override the platform to simulate CHANNEL: stable

0 commit comments

Comments
 (0)