diff --git a/AUTHORS b/AUTHORS index aa9535c024..05962ad7c5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -52,3 +52,4 @@ Alek Åström Efthymios Sarpmpanis Cédric Wyss Michel Feinstein +Michael Lee diff --git a/packages/flutter_tools/lib/src/commands/build_fuchsia.dart b/packages/flutter_tools/lib/src/commands/build_fuchsia.dart index 2c126b5e3d..ca1db5fafe 100644 --- a/packages/flutter_tools/lib/src/commands/build_fuchsia.dart +++ b/packages/flutter_tools/lib/src/commands/build_fuchsia.dart @@ -19,6 +19,7 @@ class BuildFuchsiaCommand extends BuildSubCommand { BuildFuchsiaCommand({bool verboseHelp = false}) { addTreeShakeIconsFlag(); usesTargetOption(); + usesDartDefineOption(); addBuildModeFlags(verboseHelp: verboseHelp); argParser.addOption( 'runner-source', diff --git a/packages/flutter_tools/lib/src/fuchsia/fuchsia_kernel_compiler.dart b/packages/flutter_tools/lib/src/fuchsia/fuchsia_kernel_compiler.dart index 1d23520006..384f96697e 100644 --- a/packages/flutter_tools/lib/src/fuchsia/fuchsia_kernel_compiler.dart +++ b/packages/flutter_tools/lib/src/fuchsia/fuchsia_kernel_compiler.dart @@ -56,28 +56,7 @@ class FuchsiaKernelCompiler { '--packages', '$multiRootScheme:///$relativePackagesFile', '--output', globals.fs.path.join(outDir, '$appName.dil'), '--component-name', appName, - - // AOT/JIT: - if (buildInfo.usesAot) ...['--aot', '--tfa'] - else ...[ - '--no-link-platform', - '--split-output-by-packages', - '--manifest', manifestPath - ], - - // debug, profile, jit release, release: - if (buildInfo.isDebug) '--embed-sources' - else '--no-embed-sources', - - if (buildInfo.isProfile) '-Ddart.vm.profile=true', - if (buildInfo.mode.isRelease) '-Ddart.vm.release=true', - '-Ddart.developer.causal_async_stacks=${buildInfo.isDebug}', - - // Use bytecode and drop the ast in JIT release mode. - if (buildInfo.isJitRelease) ...[ - '--gen-bytecode', - '--drop-ast', - ], + ...getBuildInfoFlags(buildInfo: buildInfo, manifestPath: manifestPath) ]; flags += [ @@ -103,4 +82,50 @@ class FuchsiaKernelCompiler { throwToolExit('Build process failed'); } } + + /// Provide flags that are affected by [BuildInfo] + @visibleForTesting + static List getBuildInfoFlags({ + @required BuildInfo buildInfo, + @required String manifestPath, + }) { + return [ + // AOT/JIT: + if (buildInfo.usesAot) ...[ + '--aot', + '--tfa' + ] else ...[ + '--no-link-platform', + '--split-output-by-packages', + '--manifest', + manifestPath + ], + + // debug, profile, jit release, release: + if (buildInfo.isDebug) + '--embed-sources' + else + '--no-embed-sources', + + if (buildInfo.isProfile) ...[ + '-Ddart.vm.profile=true', + '-Ddart.vm.product=false', + ], + + if (buildInfo.mode.isRelease) ...[ + '-Ddart.vm.profile=false', + '-Ddart.vm.product=true', + ], + '-Ddart.developer.causal_async_stacks=${buildInfo.isDebug}', + + // Use bytecode and drop the ast in JIT release mode. + if (buildInfo.isJitRelease) ...[ + '--gen-bytecode', + '--drop-ast', + ], + + for (final String dartDefine in buildInfo.dartDefines) + '-D$dartDefine', + ]; + } } diff --git a/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_kernel_compiler_test.dart b/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_kernel_compiler_test.dart new file mode 100644 index 0000000000..b9f3ea2ea1 --- /dev/null +++ b/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_kernel_compiler_test.dart @@ -0,0 +1,52 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_tools/src/build_info.dart'; +import 'package:flutter_tools/src/fuchsia/fuchsia_kernel_compiler.dart'; + +import '../../src/common.dart'; + +void main() { + group('Fuchsia Kernel Compiler', () { + test('provide correct flags for release mode', () { + expect( + FuchsiaKernelCompiler.getBuildInfoFlags( + buildInfo: BuildInfo.release, + manifestPath: '', + ), + allOf([ + contains('-Ddart.vm.profile=false'), + contains('-Ddart.vm.product=true'), + ])); + }); + + test('provide correct flags for profile mode', () { + expect( + FuchsiaKernelCompiler.getBuildInfoFlags( + buildInfo: BuildInfo.profile, + manifestPath: '', + ), + allOf([ + contains('-Ddart.vm.profile=true'), + contains('-Ddart.vm.product=false'), + ]), + ); + }); + + test('provide correct flags for custom dart define', () { + expect( + FuchsiaKernelCompiler.getBuildInfoFlags( + buildInfo: const BuildInfo( + BuildMode.debug, + null, + treeShakeIcons: true, + dartDefines: ['abc=efg'], + ), + manifestPath: ''), + allOf([ + contains('-Dabc=efg'), + ])); + }); + }); +}