Unverified Commit 44fe615c authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Remove Finder extended attributes in build target before code signing iOS frameworks (#123896)

Remove Finder extended attributes in build target before code signing iOS frameworks
parent 3bc07c1c
...@@ -9,8 +9,10 @@ import '../../base/build.dart'; ...@@ -9,8 +9,10 @@ import '../../base/build.dart';
import '../../base/common.dart'; import '../../base/common.dart';
import '../../base/file_system.dart'; import '../../base/file_system.dart';
import '../../base/io.dart'; import '../../base/io.dart';
import '../../base/process.dart';
import '../../build_info.dart'; import '../../build_info.dart';
import '../../globals.dart' as globals; import '../../globals.dart' as globals;
import '../../ios/mac.dart';
import '../../macos/xcode.dart'; import '../../macos/xcode.dart';
import '../../project.dart'; import '../../project.dart';
import '../../reporting/reporting.dart'; import '../../reporting/reporting.dart';
...@@ -296,7 +298,7 @@ abstract class UnpackIOS extends Target { ...@@ -296,7 +298,7 @@ abstract class UnpackIOS extends Target {
if (buildMode == BuildMode.release) { if (buildMode == BuildMode.release) {
_bitcodeStripFramework(environment, frameworkBinaryPath); _bitcodeStripFramework(environment, frameworkBinaryPath);
} }
_signFramework(environment, frameworkBinaryPath, buildMode); await _signFramework(environment, frameworkBinary, buildMode);
} }
void _copyFramework(Environment environment, String sdkRoot) { void _copyFramework(Environment environment, String sdkRoot) {
...@@ -463,7 +465,7 @@ abstract class IosAssetBundle extends Target { ...@@ -463,7 +465,7 @@ abstract class IosAssetBundle extends Target {
} }
final BuildMode buildMode = BuildMode.fromCliName(environmentBuildMode); final BuildMode buildMode = BuildMode.fromCliName(environmentBuildMode);
final Directory frameworkDirectory = environment.outputDir.childDirectory('App.framework'); final Directory frameworkDirectory = environment.outputDir.childDirectory('App.framework');
final String frameworkBinaryPath = frameworkDirectory.childFile('App').path; final File frameworkBinary = frameworkDirectory.childFile('App');
final Directory assetDirectory = frameworkDirectory.childDirectory('flutter_assets'); final Directory assetDirectory = frameworkDirectory.childDirectory('flutter_assets');
frameworkDirectory.createSync(recursive: true); frameworkDirectory.createSync(recursive: true);
assetDirectory.createSync(); assetDirectory.createSync();
...@@ -474,7 +476,7 @@ abstract class IosAssetBundle extends Target { ...@@ -474,7 +476,7 @@ abstract class IosAssetBundle extends Target {
environment.buildDir environment.buildDir
.childDirectory('App.framework') .childDirectory('App.framework')
.childFile('App') .childFile('App')
.copySync(frameworkBinaryPath); .copySync(frameworkBinary.path);
final String vmSnapshotData = environment.artifacts.getArtifactPath(Artifact.vmSnapshotData, mode: BuildMode.debug); final String vmSnapshotData = environment.artifacts.getArtifactPath(Artifact.vmSnapshotData, mode: BuildMode.debug);
final String isolateSnapshotData = environment.artifacts.getArtifactPath(Artifact.isolateSnapshotData, mode: BuildMode.debug); final String isolateSnapshotData = environment.artifacts.getArtifactPath(Artifact.isolateSnapshotData, mode: BuildMode.debug);
...@@ -486,7 +488,7 @@ abstract class IosAssetBundle extends Target { ...@@ -486,7 +488,7 @@ abstract class IosAssetBundle extends Target {
.copySync(assetDirectory.childFile('isolate_snapshot_data').path); .copySync(assetDirectory.childFile('isolate_snapshot_data').path);
} else { } else {
environment.buildDir.childDirectory('App.framework').childFile('App') environment.buildDir.childDirectory('App.framework').childFile('App')
.copySync(frameworkBinaryPath); .copySync(frameworkBinary.path);
} }
// Copy the dSYM // Copy the dSYM
...@@ -539,7 +541,7 @@ abstract class IosAssetBundle extends Target { ...@@ -539,7 +541,7 @@ abstract class IosAssetBundle extends Target {
.childDirectory('App.framework') .childDirectory('App.framework')
.childFile('Info.plist').path); .childFile('Info.plist').path);
_signFramework(environment, frameworkBinaryPath, buildMode); await _signFramework(environment, frameworkBinary, buildMode);
} }
} }
...@@ -692,10 +694,16 @@ Future<void> _createStubAppFramework(File outputFile, Environment environment, ...@@ -692,10 +694,16 @@ Future<void> _createStubAppFramework(File outputFile, Environment environment,
} }
} }
_signFramework(environment, outputFile.path, BuildMode.debug); await _signFramework(environment, outputFile, BuildMode.debug);
} }
void _signFramework(Environment environment, String binaryPath, BuildMode buildMode) { Future<void> _signFramework(Environment environment, File binary, BuildMode buildMode) async {
await removeFinderExtendedAttributes(
binary,
ProcessUtils(processManager: environment.processManager, logger: environment.logger),
environment.logger,
);
String? codesignIdentity = environment.defines[kCodesignIdentity]; String? codesignIdentity = environment.defines[kCodesignIdentity];
if (codesignIdentity == null || codesignIdentity.isEmpty) { if (codesignIdentity == null || codesignIdentity.isEmpty) {
codesignIdentity = '-'; codesignIdentity = '-';
...@@ -709,13 +717,13 @@ void _signFramework(Environment environment, String binaryPath, BuildMode buildM ...@@ -709,13 +717,13 @@ void _signFramework(Environment environment, String binaryPath, BuildMode buildM
// Mimic Xcode's timestamp codesigning behavior on non-release binaries. // Mimic Xcode's timestamp codesigning behavior on non-release binaries.
'--timestamp=none', '--timestamp=none',
], ],
binaryPath, binary.path,
]); ]);
if (result.exitCode != 0) { if (result.exitCode != 0) {
final String stdout = (result.stdout as String).trim(); final String stdout = (result.stdout as String).trim();
final String stderr = (result.stderr as String).trim(); final String stderr = (result.stderr as String).trim();
final StringBuffer output = StringBuffer(); final StringBuffer output = StringBuffer();
output.writeln('Failed to codesign $binaryPath with identity $codesignIdentity.'); output.writeln('Failed to codesign ${binary.path} with identity $codesignIdentity.');
if (stdout.isNotEmpty) { if (stdout.isNotEmpty) {
output.writeln(stdout); output.writeln(stdout);
} }
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
import 'dart:async'; import 'dart:async';
import 'package:meta/meta.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
import '../artifacts.dart'; import '../artifacts.dart';
...@@ -493,8 +492,7 @@ Future<XcodeBuildResult> buildXcodeProject({ ...@@ -493,8 +492,7 @@ Future<XcodeBuildResult> buildXcodeProject({
/// Extended attributes applied by Finder can cause code signing errors. Remove them. /// Extended attributes applied by Finder can cause code signing errors. Remove them.
/// https://developer.apple.com/library/archive/qa/qa1940/_index.html /// https://developer.apple.com/library/archive/qa/qa1940/_index.html
@visibleForTesting Future<void> removeFinderExtendedAttributes(FileSystemEntity projectDirectory, ProcessUtils processUtils, Logger logger) async {
Future<void> removeFinderExtendedAttributes(Directory projectDirectory, ProcessUtils processUtils, Logger logger) async {
final bool success = await processUtils.exitsHappy( final bool success = await processUtils.exitsHappy(
<String>[ <String>[
'xattr', 'xattr',
......
...@@ -104,6 +104,13 @@ void main() { ...@@ -104,6 +104,13 @@ void main() {
'-o', '-o',
appFrameworkPath, appFrameworkPath,
]), ]),
FakeCommand(command: <String>[
'xattr',
'-r',
'-d',
'com.apple.FinderInfo',
appFrameworkPath,
]),
FakeCommand(command: <String>[ FakeCommand(command: <String>[
'codesign', 'codesign',
'--force', '--force',
...@@ -141,6 +148,13 @@ void main() { ...@@ -141,6 +148,13 @@ void main() {
'-o', '-o',
appFrameworkPath, appFrameworkPath,
]), ]),
FakeCommand(command: <String>[
'xattr',
'-r',
'-d',
'com.apple.FinderInfo',
appFrameworkPath,
]),
FakeCommand(command: <String>[ FakeCommand(command: <String>[
'codesign', 'codesign',
'--force', '--force',
...@@ -195,7 +209,14 @@ void main() { ...@@ -195,7 +209,14 @@ void main() {
final Directory frameworkDirectory = environment.outputDir.childDirectory('App.framework'); final Directory frameworkDirectory = environment.outputDir.childDirectory('App.framework');
final File frameworkDirectoryBinary = frameworkDirectory.childFile('App'); final File frameworkDirectoryBinary = frameworkDirectory.childFile('App');
processManager.addCommand( processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
'xattr',
'-r',
'-d',
'com.apple.FinderInfo',
frameworkDirectoryBinary.path,
]),
FakeCommand(command: <String>[ FakeCommand(command: <String>[
'codesign', 'codesign',
'--force', '--force',
...@@ -204,7 +225,7 @@ void main() { ...@@ -204,7 +225,7 @@ void main() {
'--timestamp=none', '--timestamp=none',
frameworkDirectoryBinary.path, frameworkDirectoryBinary.path,
]), ]),
); ]);
await const DebugIosApplicationBundle().build(environment); await const DebugIosApplicationBundle().build(environment);
expect(processManager, hasNoRemainingExpectations); expect(processManager, hasNoRemainingExpectations);
...@@ -267,6 +288,13 @@ void main() { ...@@ -267,6 +288,13 @@ void main() {
'--include=/', '--include=/',
'--include=/./shader_lib', '--include=/./shader_lib',
]), ]),
FakeCommand(command: <String>[
'xattr',
'-r',
'-d',
'com.apple.FinderInfo',
frameworkDirectoryBinary.path,
]),
FakeCommand(command: <String>[ FakeCommand(command: <String>[
'codesign', 'codesign',
'--force', '--force',
...@@ -323,7 +351,14 @@ void main() { ...@@ -323,7 +351,14 @@ void main() {
final Directory frameworkDirectory = environment.outputDir.childDirectory('App.framework'); final Directory frameworkDirectory = environment.outputDir.childDirectory('App.framework');
final File frameworkDirectoryBinary = frameworkDirectory.childFile('App'); final File frameworkDirectoryBinary = frameworkDirectory.childFile('App');
processManager.addCommand( processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
'xattr',
'-r',
'-d',
'com.apple.FinderInfo',
frameworkDirectoryBinary.path,
]),
FakeCommand(command: <String>[ FakeCommand(command: <String>[
'codesign', 'codesign',
'--force', '--force',
...@@ -331,7 +366,7 @@ void main() { ...@@ -331,7 +366,7 @@ void main() {
'ABC123', 'ABC123',
frameworkDirectoryBinary.path, frameworkDirectoryBinary.path,
]), ]),
); ]);
await const ReleaseIosApplicationBundle().build(environment); await const ReleaseIosApplicationBundle().build(environment);
expect(processManager, hasNoRemainingExpectations); expect(processManager, hasNoRemainingExpectations);
...@@ -371,7 +406,14 @@ void main() { ...@@ -371,7 +406,14 @@ void main() {
final Directory frameworkDirectory = environment.outputDir.childDirectory('App.framework'); final Directory frameworkDirectory = environment.outputDir.childDirectory('App.framework');
final File frameworkDirectoryBinary = frameworkDirectory.childFile('App'); final File frameworkDirectoryBinary = frameworkDirectory.childFile('App');
processManager.addCommand( processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
'xattr',
'-r',
'-d',
'com.apple.FinderInfo',
frameworkDirectoryBinary.path,
]),
FakeCommand(command: <String>[ FakeCommand(command: <String>[
'codesign', 'codesign',
'--force', '--force',
...@@ -379,7 +421,7 @@ void main() { ...@@ -379,7 +421,7 @@ void main() {
'-', '-',
frameworkDirectoryBinary.path, frameworkDirectoryBinary.path,
]), ]),
); ]);
await const ReleaseIosApplicationBundle().build(environment); await const ReleaseIosApplicationBundle().build(environment);
expect(usage.events, contains(const TestUsageEvent('assemble', 'ios-archive', label: 'success'))); expect(usage.events, contains(const TestUsageEvent('assemble', 'ios-archive', label: 'success')));
...@@ -466,6 +508,7 @@ void main() { ...@@ -466,6 +508,7 @@ void main() {
late FakeCommand copyPhysicalFrameworkCommand; late FakeCommand copyPhysicalFrameworkCommand;
late FakeCommand lipoCommandNonFatResult; late FakeCommand lipoCommandNonFatResult;
late FakeCommand lipoVerifyArm64Command; late FakeCommand lipoVerifyArm64Command;
late FakeCommand xattrCommand;
late FakeCommand adHocCodesignCommand; late FakeCommand adHocCodesignCommand;
setUp(() { setUp(() {
...@@ -495,6 +538,14 @@ void main() { ...@@ -495,6 +538,14 @@ void main() {
'arm64', 'arm64',
]); ]);
xattrCommand = FakeCommand(command: <String>[
'xattr',
'-r',
'-d',
'com.apple.FinderInfo',
binary.path,
]);
adHocCodesignCommand = FakeCommand(command: <String>[ adHocCodesignCommand = FakeCommand(command: <String>[
'codesign', 'codesign',
'--force', '--force',
...@@ -538,6 +589,7 @@ void main() { ...@@ -538,6 +589,7 @@ void main() {
'-verify_arch', '-verify_arch',
'x86_64', 'x86_64',
]), ]),
xattrCommand,
adHocCodesignCommand, adHocCodesignCommand,
]); ]);
await const DebugUnpackIOS().build(environment); await const DebugUnpackIOS().build(environment);
...@@ -684,6 +736,7 @@ void main() { ...@@ -684,6 +736,7 @@ void main() {
copyPhysicalFrameworkCommand, copyPhysicalFrameworkCommand,
lipoCommandNonFatResult, lipoCommandNonFatResult,
lipoVerifyArm64Command, lipoVerifyArm64Command,
xattrCommand,
adHocCodesignCommand, adHocCodesignCommand,
]); ]);
await const DebugUnpackIOS().build(environment); await const DebugUnpackIOS().build(environment);
...@@ -733,6 +786,7 @@ void main() { ...@@ -733,6 +786,7 @@ void main() {
'armv7', 'armv7',
binary.path, binary.path,
]), ]),
xattrCommand,
adHocCodesignCommand, adHocCodesignCommand,
]); ]);
...@@ -810,6 +864,7 @@ void main() { ...@@ -810,6 +864,7 @@ void main() {
copyPhysicalFrameworkCommand, copyPhysicalFrameworkCommand,
lipoCommandNonFatResult, lipoCommandNonFatResult,
lipoVerifyArm64Command, lipoVerifyArm64Command,
xattrCommand,
adHocCodesignCommand, adHocCodesignCommand,
]); ]);
await const DebugUnpackIOS().build(environment); await const DebugUnpackIOS().build(environment);
...@@ -838,6 +893,7 @@ void main() { ...@@ -838,6 +893,7 @@ void main() {
copyPhysicalFrameworkCommand, copyPhysicalFrameworkCommand,
lipoCommandNonFatResult, lipoCommandNonFatResult,
lipoVerifyArm64Command, lipoVerifyArm64Command,
xattrCommand,
FakeCommand(command: <String>[ FakeCommand(command: <String>[
'codesign', 'codesign',
'--force', '--force',
...@@ -885,6 +941,7 @@ void main() { ...@@ -885,6 +941,7 @@ void main() {
copyPhysicalFrameworkCommand, copyPhysicalFrameworkCommand,
lipoCommandNonFatResult, lipoCommandNonFatResult,
lipoVerifyArm64Command, lipoVerifyArm64Command,
xattrCommand,
FakeCommand(command: <String>[ FakeCommand(command: <String>[
'codesign', 'codesign',
'--force', '--force',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment