Skip to content

Commit 6eef5f2

Browse files
Share build command flag configuration on desktop (flutter#64983)
Almost all of the flag setup on Linux, macOS, and Windows should be identical; this pulls that common setup to a shared method. This adds support for several flags on macOS that have all the necessary plumbing already in place due to shared backend code, but were never enabled. Fixes flutter#64944
1 parent e82571a commit 6eef5f2

File tree

5 files changed

+77
-48
lines changed

5 files changed

+77
-48
lines changed

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,7 @@ import 'build.dart';
1818
/// A command to build a linux desktop target through a build shell script.
1919
class BuildLinuxCommand extends BuildSubCommand {
2020
BuildLinuxCommand({ bool verboseHelp = false }) {
21-
addTreeShakeIconsFlag();
22-
usesTargetOption();
23-
addBuildModeFlags(verboseHelp: verboseHelp);
24-
usesPubOption();
25-
addSplitDebugInfoOption();
26-
addDartObfuscationOption();
27-
usesDartDefineOption();
28-
usesExtraFrontendOptions();
29-
addEnableExperimentation(hide: !verboseHelp);
30-
usesTrackWidgetCreation(verboseHelp: verboseHelp);
31-
addBuildPerformanceFile(hide: !verboseHelp);
32-
addBundleSkSLPathOption(hide: !verboseHelp);
33-
addNullSafetyModeOptions(hide: !verboseHelp);
34-
usesAnalyzeSizeFlag();
21+
addCommonDesktopBuildOptions(verboseHelp: verboseHelp);
3522
}
3623

3724
@override

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,9 @@ import 'build.dart';
2020
/// A command to build a macOS desktop target through a build shell script.
2121
class BuildMacosCommand extends BuildSubCommand {
2222
BuildMacosCommand({ @required bool verboseHelp }) {
23-
addTreeShakeIconsFlag();
24-
addSplitDebugInfoOption();
25-
usesTargetOption();
26-
addBuildModeFlags();
27-
addDartObfuscationOption();
28-
usesExtraFrontendOptions();
23+
addCommonDesktopBuildOptions(verboseHelp: verboseHelp);
2924
usesBuildNumberOption();
3025
usesBuildNameOption();
31-
addEnableExperimentation(hide: !verboseHelp);
32-
addBuildPerformanceFile(hide: !verboseHelp);
33-
addBundleSkSLPathOption(hide: !verboseHelp);
34-
addNullSafetyModeOptions(hide: !verboseHelp);
35-
usesAnalyzeSizeFlag();
3626
}
3727

3828
@override

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,7 @@ import 'build.dart';
2121
/// A command to build a windows desktop target through a build shell script.
2222
class BuildWindowsCommand extends BuildSubCommand {
2323
BuildWindowsCommand({ bool verboseHelp = false }) {
24-
addTreeShakeIconsFlag();
25-
usesTargetOption();
26-
addBuildModeFlags(verboseHelp: verboseHelp);
27-
usesPubOption();
28-
addSplitDebugInfoOption();
29-
addDartObfuscationOption();
30-
usesDartDefineOption();
31-
usesExtraFrontendOptions();
32-
addEnableExperimentation(hide: !verboseHelp);
33-
usesTrackWidgetCreation(verboseHelp: verboseHelp);
34-
addBuildPerformanceFile(hide: !verboseHelp);
35-
addBundleSkSLPathOption(hide: !verboseHelp);
36-
addNullSafetyModeOptions(hide: !verboseHelp);
37-
usesAnalyzeSizeFlag();
24+
addCommonDesktopBuildOptions(verboseHelp: verboseHelp);
3825
}
3926

4027
@override

packages/flutter_tools/lib/src/runner/flutter_command.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,24 @@ abstract class FlutterCommand extends Command<void> {
554554
);
555555
}
556556

557+
/// Adds build options common to all of the desktop build commands.
558+
void addCommonDesktopBuildOptions({ bool verboseHelp = false }) {
559+
addBuildModeFlags(verboseHelp: verboseHelp);
560+
addBuildPerformanceFile(hide: !verboseHelp);
561+
addBundleSkSLPathOption(hide: !verboseHelp);
562+
addDartObfuscationOption();
563+
addEnableExperimentation(hide: !verboseHelp);
564+
addNullSafetyModeOptions(hide: !verboseHelp);
565+
addSplitDebugInfoOption();
566+
addTreeShakeIconsFlag();
567+
usesAnalyzeSizeFlag();
568+
usesDartDefineOption();
569+
usesExtraFrontendOptions();
570+
usesPubOption();
571+
usesTargetOption();
572+
usesTrackWidgetCreation(verboseHelp: verboseHelp);
573+
}
574+
557575
set defaultBuildMode(BuildMode value) {
558576
_defaultBuildMode = value;
559577
}

packages/flutter_tools/test/commands.shard/hermetic/build_macos_test.dart

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void main() {
112112
createCoreMockProjectFiles();
113113

114114
expect(createTestCommandRunner(command).run(
115-
const <String>['build', 'macos']
115+
const <String>['build', 'macos', '--no-pub']
116116
), throwsToolExit(message: 'No macOS desktop project configured'));
117117
}, overrides: <Type, Generator>{
118118
Platform: () => macosPlatform,
@@ -129,7 +129,7 @@ void main() {
129129
.createSync(recursive: true);
130130

131131
expect(createTestCommandRunner(command).run(
132-
const <String>['build', 'macos']
132+
const <String>['build', 'macos', '--no-pub']
133133
), throwsToolExit());
134134
}, overrides: <Type, Generator>{
135135
Platform: () => notMacosPlatform,
@@ -143,7 +143,7 @@ void main() {
143143
createMinimalMockProjectFiles();
144144

145145
await createTestCommandRunner(command).run(
146-
const <String>['build', 'macos', '--debug']
146+
const <String>['build', 'macos', '--debug', '--no-pub']
147147
);
148148
expect(testLogger.statusText, isNot(contains('STDOUT STUFF')));
149149
expect(testLogger.traceText, isNot(contains('STDOUT STUFF')));
@@ -162,7 +162,7 @@ void main() {
162162
createMinimalMockProjectFiles();
163163

164164
await createTestCommandRunner(command).run(
165-
const <String>['build', 'macos', '--debug']
165+
const <String>['build', 'macos', '--debug', '--no-pub']
166166
);
167167
}, overrides: <Type, Generator>{
168168
FileSystem: () => fileSystem,
@@ -178,7 +178,7 @@ void main() {
178178
createMinimalMockProjectFiles();
179179

180180
await createTestCommandRunner(command).run(
181-
const <String>['build', 'macos', '--debug', '-v']
181+
const <String>['build', 'macos', '--debug', '--no-pub', '-v']
182182
);
183183
}, overrides: <Type, Generator>{
184184
FileSystem: () => fileSystem,
@@ -195,7 +195,7 @@ void main() {
195195
createMinimalMockProjectFiles();
196196

197197
await createTestCommandRunner(command).run(
198-
const <String>['build', 'macos', '--profile']
198+
const <String>['build', 'macos', '--profile', '--no-pub']
199199
);
200200
}, overrides: <Type, Generator>{
201201
FileSystem: () => fileSystem,
@@ -212,7 +212,7 @@ void main() {
212212
createMinimalMockProjectFiles();
213213

214214
await createTestCommandRunner(command).run(
215-
const <String>['build', 'macos', '--release']
215+
const <String>['build', 'macos', '--release', '--no-pub']
216216
);
217217
}, overrides: <Type, Generator>{
218218
FileSystem: () => fileSystem,
@@ -223,6 +223,52 @@ void main() {
223223
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
224224
});
225225

226+
testUsingContext('macOS build supports standard desktop build options', () async {
227+
final BuildCommand command = BuildCommand();
228+
createMinimalMockProjectFiles();
229+
fileSystem.file('lib/other.dart')
230+
.createSync(recursive: true);
231+
232+
await createTestCommandRunner(command).run(
233+
const <String>[
234+
'build',
235+
'macos',
236+
'--target=lib/other.dart',
237+
'--no-pub',
238+
'--track-widget-creation',
239+
'--split-debug-info=foo/',
240+
'--enable-experiment=non-nullable',
241+
'--obfuscate',
242+
'--dart-define=foo.bar=2',
243+
'--dart-define=fizz.far=3',
244+
'--tree-shake-icons',
245+
'--bundle-sksl-path=foo/bar.sksl.json',
246+
]
247+
);
248+
final List<String> contents = fileSystem
249+
.file('./macos/Flutter/ephemeral/Flutter-Generated.xcconfig')
250+
.readAsLinesSync();
251+
252+
expect(contents, containsAll(<String>[
253+
'DART_DEFINES=foo.bar%3D2,fizz.far%3D3',
254+
'DART_OBFUSCATION=true',
255+
'EXTRA_FRONT_END_OPTIONS=--enable-experiment%3Dnon-nullable',
256+
'EXTRA_GEN_SNAPSHOT_OPTIONS=--enable-experiment%3Dnon-nullable',
257+
'SPLIT_DEBUG_INFO=foo/',
258+
'TRACK_WIDGET_CREATION=true',
259+
'TREE_SHAKE_ICONS=true',
260+
'FLUTTER_TARGET=lib/other.dart',
261+
'BUNDLE_SKSL_PATH=foo/bar.sksl.json',
262+
]));
263+
}, overrides: <Type, Generator>{
264+
FileSystem: () => fileSystem,
265+
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
266+
setUpMockXcodeBuildHandler('Release')
267+
]),
268+
Platform: () => macosPlatform,
269+
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
270+
});
271+
226272
testUsingContext('macOS build supports build-name and build-number', () async {
227273
final BuildCommand command = BuildCommand();
228274
createMinimalMockProjectFiles();
@@ -232,6 +278,7 @@ void main() {
232278
'build',
233279
'macos',
234280
'--debug',
281+
'--no-pub',
235282
'--build-name=1.2.3',
236283
'--build-number=42',
237284
],
@@ -254,7 +301,7 @@ void main() {
254301
testUsingContext('Refuses to build for macOS when feature is disabled', () {
255302
final CommandRunner<void> runner = createTestCommandRunner(BuildCommand());
256303

257-
expect(() => runner.run(<String>['build', 'macos']),
304+
expect(() => runner.run(<String>['build', 'macos', '--no-pub']),
258305
throwsToolExit());
259306
}, overrides: <Type, Generator>{
260307
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: false),
@@ -283,7 +330,7 @@ void main() {
283330
..writeAsBytesSync(List<int>.generate(10000, (int index) => 0));
284331

285332
await createTestCommandRunner(command).run(
286-
const <String>['build', 'macos', '--analyze-size']
333+
const <String>['build', 'macos', '--no-pub', '--analyze-size']
287334
);
288335

289336
expect(testLogger.statusText, contains('A summary of your macOS bundle analysis can be found at'));

0 commit comments

Comments
 (0)