Unverified Commit 34b8f830 authored by michaellee8's avatar michaellee8 Committed by GitHub

[flutter_tools] add --dart-define option for fuchsia build (#55715)

parent 7eb3df4a
......@@ -52,3 +52,4 @@ Alek Åström <alek.astrom@gmail.com>
Efthymios Sarpmpanis <e.sarbanis@gmail.com>
Cédric Wyss <cedi.wyss@gmail.com>
Michel Feinstein <michel@feinstein.com.br>
Michael Lee <ckmichael8@gmail.com>
......@@ -19,6 +19,7 @@ class BuildFuchsiaCommand extends BuildSubCommand {
BuildFuchsiaCommand({bool verboseHelp = false}) {
addTreeShakeIconsFlag();
usesTargetOption();
usesDartDefineOption();
addBuildModeFlags(verboseHelp: verboseHelp);
argParser.addOption(
'runner-source',
......
......@@ -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) ...<String>['--aot', '--tfa']
else ...<String>[
'--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) ...<String>[
'--gen-bytecode',
'--drop-ast',
],
...getBuildInfoFlags(buildInfo: buildInfo, manifestPath: manifestPath)
];
flags += <String>[
......@@ -103,4 +82,50 @@ class FuchsiaKernelCompiler {
throwToolExit('Build process failed');
}
}
/// Provide flags that are affected by [BuildInfo]
@visibleForTesting
static List<String> getBuildInfoFlags({
@required BuildInfo buildInfo,
@required String manifestPath,
}) {
return <String>[
// AOT/JIT:
if (buildInfo.usesAot) ...<String>[
'--aot',
'--tfa'
] else ...<String>[
'--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) ...<String>[
'-Ddart.vm.profile=true',
'-Ddart.vm.product=false',
],
if (buildInfo.mode.isRelease) ...<String>[
'-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) ...<String>[
'--gen-bytecode',
'--drop-ast',
],
for (final String dartDefine in buildInfo.dartDefines)
'-D$dartDefine',
];
}
}
// 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(<Matcher>[
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(<Matcher>[
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: <String>['abc=efg'],
),
manifestPath: ''),
allOf(<Matcher>[
contains('-Dabc=efg'),
]));
});
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment