Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 1dd7f45

Browse files
a-wallena-wallen
and
a-wallen
authored
Add build macos --config-only option. (#118649)
Co-authored-by: a-wallen <[email protected]>
1 parent 2258590 commit 1dd7f45

File tree

3 files changed

+96
-1
lines changed

3 files changed

+96
-1
lines changed

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

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ class BuildMacosCommand extends BuildSubCommand {
2020
required bool verboseHelp,
2121
}) : super(verboseHelp: verboseHelp) {
2222
addCommonDesktopBuildOptions(verboseHelp: verboseHelp);
23+
usesFlavorOption();
24+
argParser
25+
.addFlag('config-only',
26+
help: 'Update the project configuration without performing a build. '
27+
'This can be used in CI/CD process that create an archive to avoid '
28+
'performing duplicate work.'
29+
);
2330
}
2431

2532
@override
@@ -39,6 +46,8 @@ class BuildMacosCommand extends BuildSubCommand {
3946
@override
4047
bool get supported => globals.platform.isMacOS;
4148

49+
bool get configOnly => boolArgDeprecated('config-only');
50+
4251
@override
4352
Future<FlutterCommandResult> runCommand() async {
4453
final BuildInfo buildInfo = await getBuildInfo();
@@ -55,6 +64,7 @@ class BuildMacosCommand extends BuildSubCommand {
5564
buildInfo: buildInfo,
5665
targetOverride: targetFile,
5766
verboseLogging: globals.logger.isVerbose,
67+
configOnly: configOnly,
5868
sizeAnalyzer: SizeAnalyzer(
5969
fileSystem: globals.fs,
6070
logger: globals.logger,

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Future<void> buildMacOS({
3535
required BuildInfo buildInfo,
3636
String? targetOverride,
3737
required bool verboseLogging,
38+
bool configOnly = false,
3839
SizeAnalyzer? sizeAnalyzer,
3940
}) async {
4041
final Directory? xcodeWorkspace = flutterProject.macos.xcodeWorkspace;
@@ -78,6 +79,9 @@ Future<void> buildMacOS({
7879
if (!flutterProject.macos.outputFileList.existsSync()) {
7980
flutterProject.macos.outputFileList.createSync(recursive: true);
8081
}
82+
if (configOnly) {
83+
return;
84+
}
8185

8286
final Directory xcodeProject = flutterProject.macos.xcodeProject;
8387

@@ -97,7 +101,6 @@ Future<void> buildMacOS({
97101
if (configuration == null) {
98102
throwToolExit('Unable to find expected configuration in Xcode project.');
99103
}
100-
101104
// Run the Xcode build.
102105
final Stopwatch sw = Stopwatch()..start();
103106
final Status status = globals.logger.startProgress(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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:file_testing/file_testing.dart';
6+
import 'package:flutter_tools/src/base/file_system.dart';
7+
import 'package:flutter_tools/src/base/io.dart';
8+
9+
import '../src/common.dart';
10+
import 'test_utils.dart';
11+
12+
void main() {
13+
test('flutter build macOS --config only updates generated xcconfig file without performing build', () async {
14+
final String workingDirectory = fileSystem.path.join(
15+
getFlutterRoot(),
16+
'dev',
17+
'integration_tests',
18+
'flutter_gallery',
19+
);
20+
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
21+
22+
await processManager.run(<String>[
23+
flutterBin,
24+
...getLocalEngineArguments(),
25+
'clean',
26+
], workingDirectory: workingDirectory);
27+
final List<String> buildCommand = <String>[
28+
flutterBin,
29+
...getLocalEngineArguments(),
30+
'build',
31+
'macos',
32+
'--config-only',
33+
'--release',
34+
'--obfuscate',
35+
'--split-debug-info=info',
36+
];
37+
final ProcessResult firstRunResult = await processManager.run(buildCommand, workingDirectory: workingDirectory);
38+
39+
printOnFailure('Output of flutter build macOS:');
40+
final String firstRunStdout = firstRunResult.stdout.toString();
41+
printOnFailure('First run stdout: $firstRunStdout');
42+
printOnFailure('First run stderr: ${firstRunResult.stderr}');
43+
44+
expect(firstRunResult.exitCode, 0);
45+
expect(firstRunStdout, contains('Running pod install'));
46+
47+
final File generatedConfig = fileSystem.file(fileSystem.path.join(
48+
workingDirectory,
49+
'macos',
50+
'Flutter',
51+
'ephemeral',
52+
'Flutter-Generated.xcconfig',
53+
));
54+
55+
// Config is updated if command succeeded.
56+
expect(generatedConfig, exists);
57+
expect(generatedConfig.readAsStringSync(), contains('DART_OBFUSCATION=true'));
58+
59+
// file that only exists if app was fully built.
60+
final File frameworkPlist = fileSystem.file(fileSystem.path.join(
61+
workingDirectory,
62+
'build',
63+
'macos',
64+
'Build',
65+
'Products',
66+
'Release',
67+
'App.framework',
68+
'Resources',
69+
'Info.plist'
70+
));
71+
72+
expect(frameworkPlist, isNot(exists));
73+
74+
// Run again with no changes.
75+
final ProcessResult secondRunResult = await processManager.run(buildCommand, workingDirectory: workingDirectory);
76+
final String secondRunStdout = secondRunResult.stdout.toString();
77+
printOnFailure('Second run stdout: $secondRunStdout');
78+
printOnFailure('Second run stderr: ${secondRunResult.stderr}');
79+
80+
expect(secondRunResult.exitCode, 0);
81+
}, skip: !platform.isMacOS); // [intended] macOS builds only work on macos.
82+
}

0 commit comments

Comments
 (0)