Skip to content

Commit 6ccd993

Browse files
authored
Add flutter build ipa --no-codesign flag (#101766)
1 parent d4bfb01 commit 6ccd993

File tree

2 files changed

+57
-14
lines changed

2 files changed

+57
-14
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ class BuildIOSCommand extends _BuildIOSSubCommand {
3131
..addFlag('simulator',
3232
help: 'Build for the iOS simulator instead of the device. This changes '
3333
'the default build mode to debug if otherwise unspecified.',
34-
)
35-
..addFlag('codesign',
36-
defaultsTo: true,
37-
help: 'Codesign the application bundle (only available on device builds).',
3834
);
3935
}
4036

@@ -53,9 +49,6 @@ class BuildIOSCommand extends _BuildIOSSubCommand {
5349
@override
5450
bool get configOnly => boolArg('config-only');
5551

56-
@override
57-
bool get shouldCodesign => boolArg('codesign');
58-
5952
@override
6053
Directory _outputAppDirectory(String xcodeResultOutput) => globals.fs.directory(xcodeResultOutput).parent;
6154
}
@@ -105,9 +98,6 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
10598
@override
10699
final bool configOnly = false;
107100

108-
@override
109-
final bool shouldCodesign = true;
110-
111101
String? get exportOptionsPlist => stringArg('export-options-plist');
112102

113103
@override
@@ -141,13 +131,18 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
141131

142132
@override
143133
Future<FlutterCommandResult> runCommand() async {
144-
final FlutterCommandResult xcarchiveResult = await super.runCommand();
145-
final BuildInfo buildInfo = await getBuildInfo();
134+
final BuildInfo buildInfo = await cachedBuildInfo;
146135
displayNullSafetyMode(buildInfo);
136+
final FlutterCommandResult xcarchiveResult = await super.runCommand();
147137

148138
// xcarchive failed or not at expected location.
149139
if (xcarchiveResult.exitStatus != ExitStatus.success) {
150-
globals.printStatus('Skipping IPA');
140+
globals.printStatus('Skipping IPA.');
141+
return xcarchiveResult;
142+
}
143+
144+
if (!shouldCodesign) {
145+
globals.printStatus('Codesigning disabled with --no-codesign, skipping IPA.');
151146
return xcarchiveResult;
152147
}
153148

@@ -291,6 +286,10 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand {
291286
addBundleSkSLPathOption(hide: !verboseHelp);
292287
addNullSafetyModeOptions(hide: !verboseHelp);
293288
usesAnalyzeSizeFlag();
289+
argParser.addFlag('codesign',
290+
defaultsTo: true,
291+
help: 'Codesign the application bundle (only available on device builds).',
292+
);
294293
}
295294

296295
@override
@@ -305,7 +304,8 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand {
305304
XcodeBuildResult? xcodeBuildResult;
306305
EnvironmentType get environmentType;
307306
bool get configOnly;
308-
bool get shouldCodesign;
307+
308+
bool get shouldCodesign => boolArg('codesign');
309309

310310
late final Future<BuildInfo> cachedBuildInfo = getBuildInfo();
311311

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,49 @@ void main() {
501501
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
502502
});
503503

504+
testUsingContext('ipa build --no-codesign skips codesigning and IPA creation', () async {
505+
final BuildCommand command = BuildCommand();
506+
fakeProcessManager.addCommands(<FakeCommand>[
507+
xattrCommand,
508+
const FakeCommand(
509+
command: <String>[
510+
'xcrun',
511+
'xcodebuild',
512+
'-configuration', 'Release',
513+
'-quiet',
514+
'-workspace', 'Runner.xcworkspace',
515+
'-scheme', 'Runner',
516+
'-sdk', 'iphoneos',
517+
'-destination',
518+
'generic/platform=iOS',
519+
'CODE_SIGNING_ALLOWED=NO',
520+
'CODE_SIGNING_REQUIRED=NO',
521+
'CODE_SIGNING_IDENTITY=""',
522+
'-resultBundlePath',
523+
'/.tmp_rand0/flutter_ios_build_temp_dirrand0/temporary_xcresult_bundle',
524+
'-resultBundleVersion', '3',
525+
'FLUTTER_SUPPRESS_ANALYTICS=true',
526+
'COMPILER_INDEX_STORE_ENABLE=NO',
527+
'-archivePath',
528+
'/build/ios/archive/Runner',
529+
'archive',
530+
],
531+
),
532+
]);
533+
_createMinimalMockProjectFiles();
534+
535+
await createTestCommandRunner(command).run(
536+
const <String>['build', 'ipa', '--no-pub', '--no-codesign']
537+
);
538+
expect(fakeProcessManager, hasNoRemainingExpectations);
539+
expect(testLogger.statusText, contains('Codesigning disabled with --no-codesign, skipping IPA'));
540+
}, overrides: <Type, Generator>{
541+
FileSystem: () => fileSystem,
542+
ProcessManager: () => fakeProcessManager,
543+
Platform: () => macosPlatform,
544+
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
545+
});
546+
504547
testUsingContext('code size analysis fails when app not found', () async {
505548
final BuildCommand command = BuildCommand();
506549
_createMinimalMockProjectFiles();

0 commit comments

Comments
 (0)