Skip to content

Commit 3ac59c9

Browse files
knoppvashworth
andauthored
[flutter_tools] Add --no-codesign support for macOS build (flutter#169034)
Unlike iOS, the macOS build currently does not support `--no-codesign` option to skip signing of application bundle. Having this option is useful for situation where the code-signing step is happens separately after the bundle is built (i.e. on CI). ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Victoria Ashworth <[email protected]>
1 parent 3c9b128 commit 3ac59c9

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class BuildMacosCommand extends BuildSubCommand {
2525
'This can be used in CI/CD process that create an archive to avoid '
2626
'performing duplicate work.',
2727
);
28+
argParser.addFlag('codesign', defaultsTo: true, help: 'Codesign the application bundle.');
2829
}
2930

3031
@override
@@ -46,6 +47,8 @@ class BuildMacosCommand extends BuildSubCommand {
4647

4748
bool get configOnly => boolArg('config-only');
4849

50+
bool get shouldCodesign => boolArg('codesign');
51+
4952
@override
5053
Future<FlutterCommandResult> runCommand() async {
5154
final BuildInfo buildInfo = await getBuildInfo();
@@ -57,6 +60,9 @@ class BuildMacosCommand extends BuildSubCommand {
5760
if (!supported) {
5861
throwToolExit('"build macos" only supported on macOS hosts.');
5962
}
63+
if (!shouldCodesign) {
64+
globals.printStatus('Warning: Building with codesigning disabled.');
65+
}
6066
await buildMacOS(
6167
flutterProject: project,
6268
buildInfo: buildInfo,
@@ -70,6 +76,7 @@ class BuildMacosCommand extends BuildSubCommand {
7076
analytics: analytics,
7177
),
7278
usingCISystem: usingCISystem,
79+
codesign: shouldCodesign,
7380
);
7481
return FlutterCommandResult.success();
7582
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Future<void> buildMacOS({
7272
bool configOnly = false,
7373
SizeAnalyzer? sizeAnalyzer,
7474
bool usingCISystem = false,
75+
bool codesign = true,
7576
}) async {
7677
final Directory? xcodeWorkspace = flutterProject.macos.xcodeWorkspace;
7778
if (xcodeWorkspace == null) {
@@ -224,6 +225,11 @@ Future<void> buildMacOS({
224225
if (disabledSandboxEntitlementFile != null)
225226
'CODE_SIGN_ENTITLEMENTS=${disabledSandboxEntitlementFile.path}',
226227
...environmentVariablesAsXcodeBuildSettings(globals.platform),
228+
if (!codesign) ...<String>[
229+
'CODE_SIGNING_ALLOWED=NO',
230+
'CODE_SIGNING_REQUIRED=NO',
231+
'CODE_SIGNING_IDENTITY=""',
232+
],
227233
],
228234
trace: true,
229235
stdoutErrorMatcher: verboseLogging ? null : _filteredOutput,

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,4 +1010,58 @@ STDERR STUFF
10101010
OperatingSystemUtils: () => FakeOperatingSystemUtils(hostPlatform: HostPlatform.darwin_x64),
10111011
},
10121012
);
1013+
1014+
testUsingContext(
1015+
'macos build --no-codesign skips codesigning',
1016+
() async {
1017+
final BuildCommand command = BuildCommand(
1018+
androidSdk: FakeAndroidSdk(),
1019+
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
1020+
logger: logger,
1021+
fileSystem: fileSystem,
1022+
osUtils: FakeOperatingSystemUtils(hostPlatform: HostPlatform.darwin_arm64),
1023+
);
1024+
fakeProcessManager.addCommands(<FakeCommand>[
1025+
const FakeCommand(
1026+
command: <String>[
1027+
'/usr/bin/env',
1028+
'xcrun',
1029+
'xcodebuild',
1030+
'-workspace',
1031+
'/macos/Runner.xcworkspace',
1032+
'-configuration',
1033+
'Release',
1034+
'-scheme',
1035+
'Runner',
1036+
'-derivedDataPath',
1037+
'/build/macos',
1038+
'-destination',
1039+
'generic/platform=macOS',
1040+
'OBJROOT=/build/macos/Build/Intermediates.noindex',
1041+
'SYMROOT=/build/macos/Build/Products',
1042+
'-quiet',
1043+
'COMPILER_INDEX_STORE_ENABLE=NO',
1044+
'CODE_SIGNING_ALLOWED=NO',
1045+
'CODE_SIGNING_REQUIRED=NO',
1046+
'CODE_SIGNING_IDENTITY=""',
1047+
],
1048+
),
1049+
]);
1050+
createMinimalMockProjectFiles();
1051+
1052+
await createTestCommandRunner(
1053+
command,
1054+
).run(const <String>['build', 'macos', '--no-pub', '--no-codesign']);
1055+
expect(fakeProcessManager, hasNoRemainingExpectations);
1056+
expect(logger.statusText, contains('Warning: Building with codesigning disabled.'));
1057+
},
1058+
overrides: <Type, Generator>{
1059+
FileSystem: () => fileSystem,
1060+
Logger: () => logger,
1061+
ProcessManager: () => fakeProcessManager,
1062+
Pub: ThrowingPub.new,
1063+
Platform: () => macosPlatform,
1064+
OperatingSystemUtils: () => FakeOperatingSystemUtils(hostPlatform: HostPlatform.darwin_arm64),
1065+
},
1066+
);
10131067
}

0 commit comments

Comments
 (0)