Skip to content

Commit 34b8f83

Browse files
authored
[flutter_tools] add --dart-define option for fuchsia build (flutter#55715)
1 parent 7eb3df4 commit 34b8f83

File tree

4 files changed

+101
-22
lines changed

4 files changed

+101
-22
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ Alek Åström <alek.astrom@gmail.com>
5252
Efthymios Sarpmpanis <e.sarbanis@gmail.com>
5353
Cédric Wyss <cedi.wyss@gmail.com>
5454
Michel Feinstein <michel@feinstein.com.br>
55+
Michael Lee <ckmichael8@gmail.com>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class BuildFuchsiaCommand extends BuildSubCommand {
1919
BuildFuchsiaCommand({bool verboseHelp = false}) {
2020
addTreeShakeIconsFlag();
2121
usesTargetOption();
22+
usesDartDefineOption();
2223
addBuildModeFlags(verboseHelp: verboseHelp);
2324
argParser.addOption(
2425
'runner-source',

packages/flutter_tools/lib/src/fuchsia/fuchsia_kernel_compiler.dart

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,7 @@ class FuchsiaKernelCompiler {
5656
'--packages', '$multiRootScheme:///$relativePackagesFile',
5757
'--output', globals.fs.path.join(outDir, '$appName.dil'),
5858
'--component-name', appName,
59-
60-
// AOT/JIT:
61-
if (buildInfo.usesAot) ...<String>['--aot', '--tfa']
62-
else ...<String>[
63-
'--no-link-platform',
64-
'--split-output-by-packages',
65-
'--manifest', manifestPath
66-
],
67-
68-
// debug, profile, jit release, release:
69-
if (buildInfo.isDebug) '--embed-sources'
70-
else '--no-embed-sources',
71-
72-
if (buildInfo.isProfile) '-Ddart.vm.profile=true',
73-
if (buildInfo.mode.isRelease) '-Ddart.vm.release=true',
74-
'-Ddart.developer.causal_async_stacks=${buildInfo.isDebug}',
75-
76-
// Use bytecode and drop the ast in JIT release mode.
77-
if (buildInfo.isJitRelease) ...<String>[
78-
'--gen-bytecode',
79-
'--drop-ast',
80-
],
59+
...getBuildInfoFlags(buildInfo: buildInfo, manifestPath: manifestPath)
8160
];
8261

8362
flags += <String>[
@@ -103,4 +82,50 @@ class FuchsiaKernelCompiler {
10382
throwToolExit('Build process failed');
10483
}
10584
}
85+
86+
/// Provide flags that are affected by [BuildInfo]
87+
@visibleForTesting
88+
static List<String> getBuildInfoFlags({
89+
@required BuildInfo buildInfo,
90+
@required String manifestPath,
91+
}) {
92+
return <String>[
93+
// AOT/JIT:
94+
if (buildInfo.usesAot) ...<String>[
95+
'--aot',
96+
'--tfa'
97+
] else ...<String>[
98+
'--no-link-platform',
99+
'--split-output-by-packages',
100+
'--manifest',
101+
manifestPath
102+
],
103+
104+
// debug, profile, jit release, release:
105+
if (buildInfo.isDebug)
106+
'--embed-sources'
107+
else
108+
'--no-embed-sources',
109+
110+
if (buildInfo.isProfile) ...<String>[
111+
'-Ddart.vm.profile=true',
112+
'-Ddart.vm.product=false',
113+
],
114+
115+
if (buildInfo.mode.isRelease) ...<String>[
116+
'-Ddart.vm.profile=false',
117+
'-Ddart.vm.product=true',
118+
],
119+
'-Ddart.developer.causal_async_stacks=${buildInfo.isDebug}',
120+
121+
// Use bytecode and drop the ast in JIT release mode.
122+
if (buildInfo.isJitRelease) ...<String>[
123+
'--gen-bytecode',
124+
'--drop-ast',
125+
],
126+
127+
for (final String dartDefine in buildInfo.dartDefines)
128+
'-D$dartDefine',
129+
];
130+
}
106131
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter_tools/src/build_info.dart';
6+
import 'package:flutter_tools/src/fuchsia/fuchsia_kernel_compiler.dart';
7+
8+
import '../../src/common.dart';
9+
10+
void main() {
11+
group('Fuchsia Kernel Compiler', () {
12+
test('provide correct flags for release mode', () {
13+
expect(
14+
FuchsiaKernelCompiler.getBuildInfoFlags(
15+
buildInfo: BuildInfo.release,
16+
manifestPath: '',
17+
),
18+
allOf(<Matcher>[
19+
contains('-Ddart.vm.profile=false'),
20+
contains('-Ddart.vm.product=true'),
21+
]));
22+
});
23+
24+
test('provide correct flags for profile mode', () {
25+
expect(
26+
FuchsiaKernelCompiler.getBuildInfoFlags(
27+
buildInfo: BuildInfo.profile,
28+
manifestPath: '',
29+
),
30+
allOf(<Matcher>[
31+
contains('-Ddart.vm.profile=true'),
32+
contains('-Ddart.vm.product=false'),
33+
]),
34+
);
35+
});
36+
37+
test('provide correct flags for custom dart define', () {
38+
expect(
39+
FuchsiaKernelCompiler.getBuildInfoFlags(
40+
buildInfo: const BuildInfo(
41+
BuildMode.debug,
42+
null,
43+
treeShakeIcons: true,
44+
dartDefines: <String>['abc=efg'],
45+
),
46+
manifestPath: ''),
47+
allOf(<Matcher>[
48+
contains('-Dabc=efg'),
49+
]));
50+
});
51+
});
52+
}

0 commit comments

Comments
 (0)