Skip to content

Commit b95548e

Browse files
Don't remove toString implementations while in debug mode. (#154216)
This matches the behavior of AOT/VM compilation.
1 parent d147e52 commit b95548e

File tree

2 files changed

+39
-11
lines changed
  • packages/flutter_tools

2 files changed

+39
-11
lines changed

packages/flutter_tools/lib/src/build_system/targets/web.dart

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,36 @@ class Dart2WasmTarget extends Dart2WebTarget {
284284
@override
285285
final WasmCompilerConfig compilerConfig;
286286

287+
/// List the preconfigured build options for a given build mode.
288+
List<String> buildModeOptions(BuildMode mode, List<String> dartDefines) =>
289+
switch (mode) {
290+
BuildMode.debug => <String>[
291+
// These checks allow the CLI to override the value of this define for unit
292+
// testing the framework.
293+
if (!dartDefines.any((String define) => define.startsWith('dart.vm.profile')))
294+
'-Ddart.vm.profile=false',
295+
if (!dartDefines.any((String define) => define.startsWith('dart.vm.product')))
296+
'-Ddart.vm.product=false',
297+
],
298+
BuildMode.profile => <String>[
299+
// These checks allow the CLI to override the value of this define for
300+
// benchmarks with most timeline traces disabled.
301+
if (!dartDefines.any((String define) => define.startsWith('dart.vm.profile')))
302+
'-Ddart.vm.profile=true',
303+
if (!dartDefines.any((String define) => define.startsWith('dart.vm.product')))
304+
'-Ddart.vm.product=false',
305+
'--extra-compiler-option=--delete-tostring-package-uri=dart:ui',
306+
'--extra-compiler-option=--delete-tostring-package-uri=package:flutter',
307+
],
308+
BuildMode.release => <String>[
309+
'-Ddart.vm.profile=false',
310+
'-Ddart.vm.product=true',
311+
'--extra-compiler-option=--delete-tostring-package-uri=dart:ui',
312+
'--extra-compiler-option=--delete-tostring-package-uri=package:flutter',
313+
],
314+
_ => throw Exception('Unknown BuildMode: $mode')
315+
};
316+
287317
@override
288318
Future<void> build(Environment environment) async {
289319
final String? buildModeEnvironment = environment.defines[kBuildMode];
@@ -297,25 +327,21 @@ class Dart2WasmTarget extends Dart2WebTarget {
297327
final File depFile = environment.buildDir.childFile('dart2wasm.d');
298328
final String platformBinariesPath = artifacts.getHostArtifact(HostArtifact.webPlatformKernelFolder).path;
299329
final String platformFilePath = environment.fileSystem.path.join(platformBinariesPath, 'dart2wasm_platform.dill');
330+
final List<String> dartDefines = computeDartDefines(environment);
300331

301332
final List<String> compilationArgs = <String>[
302333
artifacts.getArtifactPath(Artifact.engineDartBinary, platform: TargetPlatform.web_javascript),
303334
'compile',
304335
'wasm',
305336
'--packages=${findPackageConfigFileOrDefault(environment.projectDir).path}',
306337
'--extra-compiler-option=--platform=$platformFilePath',
307-
'--extra-compiler-option=--delete-tostring-package-uri=dart:ui',
308-
'--extra-compiler-option=--delete-tostring-package-uri=package:flutter',
338+
...buildModeOptions(buildMode, dartDefines),
309339
if (compilerConfig.renderer == WebRendererMode.skwasm) ...<String>[
310340
'--extra-compiler-option=--import-shared-memory',
311341
'--extra-compiler-option=--shared-memory-max-pages=32768',
312342
],
313-
if (buildMode == BuildMode.profile)
314-
'-Ddart.vm.profile=true'
315-
else if (buildMode == BuildMode.release)
316-
'-Ddart.vm.product=true',
317343
...decodeCommaSeparated(environment.defines, kExtraFrontEndOptions),
318-
for (final String dartDefine in computeDartDefines(environment))
344+
for (final String dartDefine in dartDefines)
319345
'-D$dartDefine',
320346
'--extra-compiler-option=--depfile=${depFile.path}',
321347

packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ const List<String> _kDart2WasmLinuxArgs = <String> [
3535
'wasm',
3636
'--packages=/.dart_tool/package_config.json',
3737
'--extra-compiler-option=--platform=HostArtifact.webPlatformKernelFolder/dart2wasm_platform.dill',
38-
'--extra-compiler-option=--delete-tostring-package-uri=dart:ui',
39-
'--extra-compiler-option=--delete-tostring-package-uri=package:flutter',
4038
];
4139

4240
void main() {
@@ -1034,12 +1032,16 @@ void main() {
10341032
processManager.addCommand(FakeCommand(
10351033
command: <String>[
10361034
..._kDart2WasmLinuxArgs,
1035+
'-Ddart.vm.profile=${buildMode == 'profile'}',
1036+
'-Ddart.vm.product=${buildMode == 'release'}',
1037+
if (buildMode != 'debug') ...<String>[
1038+
'--extra-compiler-option=--delete-tostring-package-uri=dart:ui',
1039+
'--extra-compiler-option=--delete-tostring-package-uri=package:flutter',
1040+
],
10371041
if (renderer == WebRendererMode.skwasm) ...<String>[
10381042
'--extra-compiler-option=--import-shared-memory',
10391043
'--extra-compiler-option=--shared-memory-max-pages=32768',
10401044
],
1041-
if (buildMode != 'debug')
1042-
'-Ddart.vm.${buildMode == 'release' ? 'product' : 'profile' }=true',
10431045
...defines.map((String define) => '-D$define'),
10441046
if (renderer == WebRendererMode.skwasm) ...<String>[
10451047
'-DFLUTTER_WEB_AUTO_DETECT=false',

0 commit comments

Comments
 (0)