Skip to content

Commit 2b82bc9

Browse files
biggs0125natebiggs
andauthored
Skip wasm build when dry run is disabled and --wasm is not specified. (flutter#174184)
This fixes an issue where the wasm build was still getting executed when `--no-wasm-dry-run` was specified. Also adds a test to verify the expected behavior. Co-authored-by: Nate Biggs <[email protected]>
1 parent d78cb7f commit 2b82bc9

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

packages/flutter_tools/lib/src/commands/build_web.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,14 @@ class BuildWebCommand extends BuildSubCommand {
237237
sourceMaps: sourceMaps,
238238
renderer: webRenderer,
239239
),
240-
WasmCompilerConfig(
241-
optimizationLevel: optimizationLevel,
242-
stripWasm: boolArg('strip-wasm'),
243-
sourceMaps: sourceMaps,
244-
minify: minifyWasm,
245-
dryRun: boolArg('wasm-dry-run'),
246-
),
240+
if (boolArg('wasm-dry-run'))
241+
WasmCompilerConfig(
242+
optimizationLevel: optimizationLevel,
243+
stripWasm: boolArg('strip-wasm'),
244+
sourceMaps: sourceMaps,
245+
minify: minifyWasm,
246+
dryRun: true,
247+
),
247248
];
248249
}
249250

packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,38 @@ void main() {
439439
},
440440
);
441441

442+
testUsingContext(
443+
'Does not build wasm when wasm-dry-run is disabled',
444+
() async {
445+
final buildCommand = TestWebBuildCommand(fileSystem: fileSystem);
446+
final CommandRunner<void> runner = createTestCommandRunner(buildCommand);
447+
setupFileSystemForEndToEndTest(fileSystem);
448+
await runner.run(<String>['build', 'web', '--no-pub', '--no-wasm-dry-run']);
449+
},
450+
overrides: <Type, Generator>{
451+
Platform: () => fakePlatform,
452+
FileSystem: () => fileSystem,
453+
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
454+
ProcessManager: () => processManager,
455+
BuildSystem: () =>
456+
TestBuildSystem.all(BuildResult(success: true), (Target target, Environment environment) {
457+
expect(target, isA<WebServiceWorker>());
458+
final List<WebCompilerConfig> configs = (target as WebServiceWorker).compileConfigs;
459+
expect(configs, hasLength(1));
460+
final WebCompilerConfig jsConfig = configs[0];
461+
expect(jsConfig.renderer, WebRendererMode.canvaskit);
462+
expect(jsConfig.compileTarget, CompileTarget.js);
463+
final List<String> jsOptions = jsConfig.toCommandOptions(BuildMode.release);
464+
expect(jsOptions, <String>[
465+
'--native-null-assertions',
466+
'--no-source-maps',
467+
'-O4',
468+
'--minify',
469+
]);
470+
}),
471+
},
472+
);
473+
442474
testUsingContext(
443475
'Defaults to web renderer skwasm mode and minify for wasm when no option is specified',
444476
() async {

0 commit comments

Comments
 (0)