diff --git a/packages/flutter_tools/lib/src/compile.dart b/packages/flutter_tools/lib/src/compile.dart index 5ffd602c01..04ac530e89 100644 --- a/packages/flutter_tools/lib/src/compile.dart +++ b/packages/flutter_tools/lib/src/compile.dart @@ -177,8 +177,12 @@ List buildModeOptions(BuildMode mode, List dartDefines) { ]; case BuildMode.profile: return [ - '-Ddart.vm.profile=true', - '-Ddart.vm.product=false', + // These checks allow the CLI to override the value of this define for + // benchmarks with most timeline traces disabled. + if (!dartDefines.any((String define) => define.startsWith('dart.vm.profile'))) + '-Ddart.vm.profile=true', + if (!dartDefines.any((String define) => define.startsWith('dart.vm.product'))) + '-Ddart.vm.product=false', ]; case BuildMode.release: return [ diff --git a/packages/flutter_tools/test/general.shard/compile_test.dart b/packages/flutter_tools/test/general.shard/compile_test.dart index 72cd902baa..28442b625b 100644 --- a/packages/flutter_tools/test/general.shard/compile_test.dart +++ b/packages/flutter_tools/test/general.shard/compile_test.dart @@ -89,16 +89,27 @@ void main() { ]); }); - testWithoutContext('buildModeOptions removes matching profile define', () { + testWithoutContext('buildModeOptions removes matching profile define in debug mode', () { expect(buildModeOptions(BuildMode.debug, ['dart.vm.profile=true']), [ '-Ddart.vm.product=false', '--enable-asserts', ]); }); - testWithoutContext('buildModeOptions removes both matching profile and release define', () { + testWithoutContext('buildModeOptions removes both matching profile and release define in debug mode', () { expect(buildModeOptions(BuildMode.debug, ['dart.vm.profile=true', 'dart.vm.product=true']), [ '--enable-asserts', ]); }); + + testWithoutContext('buildModeOptions removes matching profile define in profile mode', () { + expect(buildModeOptions(BuildMode.profile, ['dart.vm.profile=true']), [ + '-Ddart.vm.product=false', + ]); + }); + + testWithoutContext('buildModeOptions removes both matching profile and release define in profile mode', () { + expect(buildModeOptions(BuildMode.profile, ['dart.vm.profile=false', 'dart.vm.product=true']), [ + ]); + }); }