From 6ccd993976267b370c5b189df1b34a1e81453db1 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Tue, 12 Apr 2022 14:49:09 -0700 Subject: [PATCH] Add `flutter build ipa --no-codesign` flag (#101766) --- .../lib/src/commands/build_ios.dart | 28 ++++++------ .../hermetic/build_ipa_test.dart | 43 +++++++++++++++++++ 2 files changed, 57 insertions(+), 14 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/build_ios.dart b/packages/flutter_tools/lib/src/commands/build_ios.dart index 704c808de8..0caf406ce4 100644 --- a/packages/flutter_tools/lib/src/commands/build_ios.dart +++ b/packages/flutter_tools/lib/src/commands/build_ios.dart @@ -31,10 +31,6 @@ class BuildIOSCommand extends _BuildIOSSubCommand { ..addFlag('simulator', help: 'Build for the iOS simulator instead of the device. This changes ' 'the default build mode to debug if otherwise unspecified.', - ) - ..addFlag('codesign', - defaultsTo: true, - help: 'Codesign the application bundle (only available on device builds).', ); } @@ -53,9 +49,6 @@ class BuildIOSCommand extends _BuildIOSSubCommand { @override bool get configOnly => boolArg('config-only'); - @override - bool get shouldCodesign => boolArg('codesign'); - @override Directory _outputAppDirectory(String xcodeResultOutput) => globals.fs.directory(xcodeResultOutput).parent; } @@ -105,9 +98,6 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand { @override final bool configOnly = false; - @override - final bool shouldCodesign = true; - String? get exportOptionsPlist => stringArg('export-options-plist'); @override @@ -141,13 +131,18 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand { @override Future runCommand() async { - final FlutterCommandResult xcarchiveResult = await super.runCommand(); - final BuildInfo buildInfo = await getBuildInfo(); + final BuildInfo buildInfo = await cachedBuildInfo; displayNullSafetyMode(buildInfo); + final FlutterCommandResult xcarchiveResult = await super.runCommand(); // xcarchive failed or not at expected location. if (xcarchiveResult.exitStatus != ExitStatus.success) { - globals.printStatus('Skipping IPA'); + globals.printStatus('Skipping IPA.'); + return xcarchiveResult; + } + + if (!shouldCodesign) { + globals.printStatus('Codesigning disabled with --no-codesign, skipping IPA.'); return xcarchiveResult; } @@ -291,6 +286,10 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand { addBundleSkSLPathOption(hide: !verboseHelp); addNullSafetyModeOptions(hide: !verboseHelp); usesAnalyzeSizeFlag(); + argParser.addFlag('codesign', + defaultsTo: true, + help: 'Codesign the application bundle (only available on device builds).', + ); } @override @@ -305,7 +304,8 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand { XcodeBuildResult? xcodeBuildResult; EnvironmentType get environmentType; bool get configOnly; - bool get shouldCodesign; + + bool get shouldCodesign => boolArg('codesign'); late final Future cachedBuildInfo = getBuildInfo(); diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_ipa_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_ipa_test.dart index cd940589bd..68bce82851 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_ipa_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_ipa_test.dart @@ -501,6 +501,49 @@ void main() { XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(), }); + testUsingContext('ipa build --no-codesign skips codesigning and IPA creation', () async { + final BuildCommand command = BuildCommand(); + fakeProcessManager.addCommands([ + xattrCommand, + const FakeCommand( + command: [ + 'xcrun', + 'xcodebuild', + '-configuration', 'Release', + '-quiet', + '-workspace', 'Runner.xcworkspace', + '-scheme', 'Runner', + '-sdk', 'iphoneos', + '-destination', + 'generic/platform=iOS', + 'CODE_SIGNING_ALLOWED=NO', + 'CODE_SIGNING_REQUIRED=NO', + 'CODE_SIGNING_IDENTITY=""', + '-resultBundlePath', + '/.tmp_rand0/flutter_ios_build_temp_dirrand0/temporary_xcresult_bundle', + '-resultBundleVersion', '3', + 'FLUTTER_SUPPRESS_ANALYTICS=true', + 'COMPILER_INDEX_STORE_ENABLE=NO', + '-archivePath', + '/build/ios/archive/Runner', + 'archive', + ], + ), + ]); + _createMinimalMockProjectFiles(); + + await createTestCommandRunner(command).run( + const ['build', 'ipa', '--no-pub', '--no-codesign'] + ); + expect(fakeProcessManager, hasNoRemainingExpectations); + expect(testLogger.statusText, contains('Codesigning disabled with --no-codesign, skipping IPA')); + }, overrides: { + FileSystem: () => fileSystem, + ProcessManager: () => fakeProcessManager, + Platform: () => macosPlatform, + XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(), + }); + testUsingContext('code size analysis fails when app not found', () async { final BuildCommand command = BuildCommand(); _createMinimalMockProjectFiles();