Unverified Commit 3e6fe491 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Remove extended attributes from entire Flutter project (#81435)

parent 0bba935b
......@@ -626,20 +626,7 @@ void _signFramework(Environment environment, String binaryPath, BuildMode buildM
if (codesignIdentity == null || codesignIdentity.isEmpty) {
return;
}
// Extended attributes applied by Finder can cause code signing errors. Remove them.
// https://developer.apple.com/library/archive/qa/qa1940/_index.html
final ProcessResult xattrResult = environment.processManager.runSync(<String>[
'xattr',
'-r',
'-d',
'com.apple.FinderInfo',
binaryPath,
]);
if (xattrResult.exitCode != 0) {
environment.logger.printTrace('Failed to remove FinderInfo extended attributes from $binaryPath.\n${xattrResult.stderr}');
}
final ProcessResult codesignResult = environment.processManager.runSync(<String>[
final ProcessResult result = environment.processManager.runSync(<String>[
'codesign',
'--force',
'--sign',
......@@ -650,7 +637,7 @@ void _signFramework(Environment environment, String binaryPath, BuildMode buildM
],
binaryPath,
]);
if (codesignResult.exitCode != 0) {
throw Exception('Failed to codesign $binaryPath with identity $codesignIdentity.\n${codesignResult.stderr}');
if (result.exitCode != 0) {
throw Exception('Failed to codesign $binaryPath with identity $codesignIdentity.\n${result.stderr}');
}
}
......@@ -122,7 +122,7 @@ Future<XcodeBuildResult> buildXcodeProject({
return XcodeBuildResult(success: false);
}
await removeFinderExtendedAttributes(app.project.hostAppRoot, globals.processUtils, globals.logger);
await removeFinderExtendedAttributes(app.project.parent.directory, globals.processUtils, globals.logger);
final XcodeProjectInfo projectInfo = await app.project.projectInfo();
final String scheme = projectInfo.schemeFor(buildInfo);
......@@ -445,19 +445,19 @@ Future<XcodeBuildResult> buildXcodeProject({
/// Extended attributes applied by Finder can cause code signing errors. Remove them.
/// https://developer.apple.com/library/archive/qa/qa1940/_index.html
@visibleForTesting
Future<void> removeFinderExtendedAttributes(Directory iosProjectDirectory, ProcessUtils processUtils, Logger logger) async {
Future<void> removeFinderExtendedAttributes(Directory projectDirectory, ProcessUtils processUtils, Logger logger) async {
final bool success = await processUtils.exitsHappy(
<String>[
'xattr',
'-r',
'-d',
'com.apple.FinderInfo',
iosProjectDirectory.path,
projectDirectory.path,
]
);
// Ignore all errors, for example if directory is missing.
if (!success) {
logger.printTrace('Failed to remove xattr com.apple.FinderInfo from ${iosProjectDirectory.path}');
logger.printTrace('Failed to remove xattr com.apple.FinderInfo from ${projectDirectory.path}');
}
}
......
......@@ -75,7 +75,7 @@ void main() {
}
const FakeCommand xattrCommand = FakeCommand(command: <String>[
'xattr', '-r', '-d', 'com.apple.FinderInfo', '/ios'
'xattr', '-r', '-d', 'com.apple.FinderInfo', '/'
]);
FakeCommand _setUpRsyncCommand({void Function() onRun}) {
......
......@@ -76,7 +76,7 @@ void main() {
}
const FakeCommand xattrCommand = FakeCommand(command: <String>[
'xattr', '-r', '-d', 'com.apple.FinderInfo', '/ios'
'xattr', '-r', '-d', 'com.apple.FinderInfo', '/'
]);
// Creates a FakeCommand for the xcodebuild call to build the app
......
......@@ -138,14 +138,7 @@ void main() {
final Directory frameworkDirectory = environment.outputDir.childDirectory('App.framework');
final File frameworkDirectoryBinary = frameworkDirectory.childFile('App');
processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
'xattr',
'-r',
'-d',
'com.apple.FinderInfo',
frameworkDirectoryBinary.path,
]),
processManager.addCommand(
FakeCommand(command: <String>[
'codesign',
'--force',
......@@ -154,7 +147,7 @@ void main() {
'--timestamp=none',
frameworkDirectoryBinary.path,
]),
]);
);
await const DebugIosApplicationBundle().build(environment);
expect(processManager.hasRemainingExpectations, isFalse);
......@@ -191,14 +184,7 @@ void main() {
final Directory frameworkDirectory = environment.outputDir.childDirectory('App.framework');
final File frameworkDirectoryBinary = frameworkDirectory.childFile('App');
processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
'xattr',
'-r',
'-d',
'com.apple.FinderInfo',
frameworkDirectoryBinary.path,
]),
processManager.addCommand(
FakeCommand(command: <String>[
'codesign',
'--force',
......@@ -206,7 +192,7 @@ void main() {
'ABC123',
frameworkDirectoryBinary.path,
]),
]);
);
await const ReleaseIosApplicationBundle().build(environment);
expect(processManager.hasRemainingExpectations, isFalse);
......@@ -291,7 +277,6 @@ void main() {
FakeCommand lipoCommandNonFatResult;
FakeCommand lipoVerifyArm64Command;
FakeCommand bitcodeStripCommand;
FakeCommand xattrRemoveCommand;
setUp(() {
final FileSystem fileSystem = MemoryFileSystem.test();
......@@ -328,14 +313,6 @@ void main() {
'-o',
binary.path,
]);
xattrRemoveCommand = FakeCommand(command: <String>[
'xattr',
'-r',
'-d',
'com.apple.FinderInfo',
binary.path,
]);
});
testWithoutContext('iphonesimulator', () async {
......@@ -644,54 +621,6 @@ void main() {
expect(processManager.hasRemainingExpectations, isFalse);
});
testWithoutContext('logs when extended attribute fails', () async {
binary.createSync(recursive: true);
final Environment environment = Environment.test(
fileSystem.currentDirectory,
processManager: processManager,
artifacts: artifacts,
logger: logger,
fileSystem: fileSystem,
outputDir: outputDir,
defines: <String, String>{
kIosArchs: 'arm64',
kSdkRoot: 'path/to/iPhoneOS.sdk',
kBitcodeFlag: '',
kCodesignIdentity: 'ABC123',
},
);
processManager.addCommands(<FakeCommand>[
copyPhysicalFrameworkCommand,
lipoCommandNonFatResult,
lipoVerifyArm64Command,
bitcodeStripCommand,
FakeCommand(
command: <String>[
'xattr',
'-r',
'-d',
'com.apple.FinderInfo',
binary.path,
],
exitCode: 1,
stderr: 'Failed to remove extended attributes',
),
FakeCommand(command: <String>[
'codesign',
'--force',
'--sign',
'ABC123',
'--timestamp=none',
binary.path,
]),
]);
await const DebugUnpackIOS().build(environment);
expect(logger.traceText, contains('Failed to remove extended attributes'));
});
testWithoutContext('fails when codesign fails', () async {
binary.createSync(recursive: true);
......@@ -715,7 +644,6 @@ void main() {
lipoCommandNonFatResult,
lipoVerifyArm64Command,
bitcodeStripCommand,
xattrRemoveCommand,
FakeCommand(command: <String>[
'codesign',
'--force',
......@@ -760,7 +688,6 @@ void main() {
lipoCommandNonFatResult,
lipoVerifyArm64Command,
bitcodeStripCommand,
xattrRemoveCommand,
FakeCommand(command: <String>[
'codesign',
'--force',
......
......@@ -37,7 +37,7 @@ List<String> _xattrArgs(FlutterProject flutterProject) {
'-r',
'-d',
'com.apple.FinderInfo',
flutterProject.ios.hostAppRoot.path,
flutterProject.directory.path,
];
}
......
......@@ -445,10 +445,10 @@ Exited (sigterm)''',
});
group('remove Finder extended attributes', () {
Directory iosProjectDirectory;
Directory projectDirectory;
setUp(() {
final MemoryFileSystem fs = MemoryFileSystem.test();
iosProjectDirectory = fs.directory('ios');
projectDirectory = fs.directory('flutter_project');
});
testWithoutContext('removes xattr', () async {
......@@ -458,11 +458,11 @@ Exited (sigterm)''',
'-r',
'-d',
'com.apple.FinderInfo',
iosProjectDirectory.path,
projectDirectory.path,
])
]);
await removeFinderExtendedAttributes(iosProjectDirectory, ProcessUtils(processManager: processManager, logger: logger), logger);
await removeFinderExtendedAttributes(projectDirectory, ProcessUtils(processManager: processManager, logger: logger), logger);
expect(processManager, hasNoRemainingExpectations);
});
......@@ -473,12 +473,12 @@ Exited (sigterm)''',
'-r',
'-d',
'com.apple.FinderInfo',
iosProjectDirectory.path,
projectDirectory.path,
], exitCode: 1,
)
]);
await removeFinderExtendedAttributes(iosProjectDirectory, ProcessUtils(processManager: processManager, logger: logger), logger);
await removeFinderExtendedAttributes(projectDirectory, ProcessUtils(processManager: processManager, logger: logger), logger);
expect(logger.traceText, contains('Failed to remove xattr com.apple.FinderInfo'));
expect(processManager, hasNoRemainingExpectations);
});
......
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