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 ...@@ -626,20 +626,7 @@ void _signFramework(Environment environment, String binaryPath, BuildMode buildM
if (codesignIdentity == null || codesignIdentity.isEmpty) { if (codesignIdentity == null || codesignIdentity.isEmpty) {
return; return;
} }
final ProcessResult result = environment.processManager.runSync(<String>[
// 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>[
'codesign', 'codesign',
'--force', '--force',
'--sign', '--sign',
...@@ -650,7 +637,7 @@ void _signFramework(Environment environment, String binaryPath, BuildMode buildM ...@@ -650,7 +637,7 @@ void _signFramework(Environment environment, String binaryPath, BuildMode buildM
], ],
binaryPath, binaryPath,
]); ]);
if (codesignResult.exitCode != 0) { if (result.exitCode != 0) {
throw Exception('Failed to codesign $binaryPath with identity $codesignIdentity.\n${codesignResult.stderr}'); throw Exception('Failed to codesign $binaryPath with identity $codesignIdentity.\n${result.stderr}');
} }
} }
...@@ -122,7 +122,7 @@ Future<XcodeBuildResult> buildXcodeProject({ ...@@ -122,7 +122,7 @@ Future<XcodeBuildResult> buildXcodeProject({
return XcodeBuildResult(success: false); 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 XcodeProjectInfo projectInfo = await app.project.projectInfo();
final String scheme = projectInfo.schemeFor(buildInfo); final String scheme = projectInfo.schemeFor(buildInfo);
...@@ -445,19 +445,19 @@ Future<XcodeBuildResult> buildXcodeProject({ ...@@ -445,19 +445,19 @@ 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 @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( final bool success = await processUtils.exitsHappy(
<String>[ <String>[
'xattr', 'xattr',
'-r', '-r',
'-d', '-d',
'com.apple.FinderInfo', 'com.apple.FinderInfo',
iosProjectDirectory.path, projectDirectory.path,
] ]
); );
// Ignore all errors, for example if directory is missing. // Ignore all errors, for example if directory is missing.
if (!success) { 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() { ...@@ -75,7 +75,7 @@ void main() {
} }
const FakeCommand xattrCommand = FakeCommand(command: <String>[ const FakeCommand xattrCommand = FakeCommand(command: <String>[
'xattr', '-r', '-d', 'com.apple.FinderInfo', '/ios' 'xattr', '-r', '-d', 'com.apple.FinderInfo', '/'
]); ]);
FakeCommand _setUpRsyncCommand({void Function() onRun}) { FakeCommand _setUpRsyncCommand({void Function() onRun}) {
......
...@@ -76,7 +76,7 @@ void main() { ...@@ -76,7 +76,7 @@ void main() {
} }
const FakeCommand xattrCommand = FakeCommand(command: <String>[ 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 // Creates a FakeCommand for the xcodebuild call to build the app
......
...@@ -138,14 +138,7 @@ void main() { ...@@ -138,14 +138,7 @@ 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.addCommands(<FakeCommand>[ processManager.addCommand(
FakeCommand(command: <String>[
'xattr',
'-r',
'-d',
'com.apple.FinderInfo',
frameworkDirectoryBinary.path,
]),
FakeCommand(command: <String>[ FakeCommand(command: <String>[
'codesign', 'codesign',
'--force', '--force',
...@@ -154,7 +147,7 @@ void main() { ...@@ -154,7 +147,7 @@ void main() {
'--timestamp=none', '--timestamp=none',
frameworkDirectoryBinary.path, frameworkDirectoryBinary.path,
]), ]),
]); );
await const DebugIosApplicationBundle().build(environment); await const DebugIosApplicationBundle().build(environment);
expect(processManager.hasRemainingExpectations, isFalse); expect(processManager.hasRemainingExpectations, isFalse);
...@@ -191,14 +184,7 @@ void main() { ...@@ -191,14 +184,7 @@ 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.addCommands(<FakeCommand>[ processManager.addCommand(
FakeCommand(command: <String>[
'xattr',
'-r',
'-d',
'com.apple.FinderInfo',
frameworkDirectoryBinary.path,
]),
FakeCommand(command: <String>[ FakeCommand(command: <String>[
'codesign', 'codesign',
'--force', '--force',
...@@ -206,7 +192,7 @@ void main() { ...@@ -206,7 +192,7 @@ void main() {
'ABC123', 'ABC123',
frameworkDirectoryBinary.path, frameworkDirectoryBinary.path,
]), ]),
]); );
await const ReleaseIosApplicationBundle().build(environment); await const ReleaseIosApplicationBundle().build(environment);
expect(processManager.hasRemainingExpectations, isFalse); expect(processManager.hasRemainingExpectations, isFalse);
...@@ -291,7 +277,6 @@ void main() { ...@@ -291,7 +277,6 @@ void main() {
FakeCommand lipoCommandNonFatResult; FakeCommand lipoCommandNonFatResult;
FakeCommand lipoVerifyArm64Command; FakeCommand lipoVerifyArm64Command;
FakeCommand bitcodeStripCommand; FakeCommand bitcodeStripCommand;
FakeCommand xattrRemoveCommand;
setUp(() { setUp(() {
final FileSystem fileSystem = MemoryFileSystem.test(); final FileSystem fileSystem = MemoryFileSystem.test();
...@@ -328,14 +313,6 @@ void main() { ...@@ -328,14 +313,6 @@ void main() {
'-o', '-o',
binary.path, binary.path,
]); ]);
xattrRemoveCommand = FakeCommand(command: <String>[
'xattr',
'-r',
'-d',
'com.apple.FinderInfo',
binary.path,
]);
}); });
testWithoutContext('iphonesimulator', () async { testWithoutContext('iphonesimulator', () async {
...@@ -644,54 +621,6 @@ void main() { ...@@ -644,54 +621,6 @@ void main() {
expect(processManager.hasRemainingExpectations, isFalse); 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 { testWithoutContext('fails when codesign fails', () async {
binary.createSync(recursive: true); binary.createSync(recursive: true);
...@@ -715,7 +644,6 @@ void main() { ...@@ -715,7 +644,6 @@ void main() {
lipoCommandNonFatResult, lipoCommandNonFatResult,
lipoVerifyArm64Command, lipoVerifyArm64Command,
bitcodeStripCommand, bitcodeStripCommand,
xattrRemoveCommand,
FakeCommand(command: <String>[ FakeCommand(command: <String>[
'codesign', 'codesign',
'--force', '--force',
...@@ -760,7 +688,6 @@ void main() { ...@@ -760,7 +688,6 @@ void main() {
lipoCommandNonFatResult, lipoCommandNonFatResult,
lipoVerifyArm64Command, lipoVerifyArm64Command,
bitcodeStripCommand, bitcodeStripCommand,
xattrRemoveCommand,
FakeCommand(command: <String>[ FakeCommand(command: <String>[
'codesign', 'codesign',
'--force', '--force',
......
...@@ -37,7 +37,7 @@ List<String> _xattrArgs(FlutterProject flutterProject) { ...@@ -37,7 +37,7 @@ List<String> _xattrArgs(FlutterProject flutterProject) {
'-r', '-r',
'-d', '-d',
'com.apple.FinderInfo', 'com.apple.FinderInfo',
flutterProject.ios.hostAppRoot.path, flutterProject.directory.path,
]; ];
} }
......
...@@ -445,10 +445,10 @@ Exited (sigterm)''', ...@@ -445,10 +445,10 @@ Exited (sigterm)''',
}); });
group('remove Finder extended attributes', () { group('remove Finder extended attributes', () {
Directory iosProjectDirectory; Directory projectDirectory;
setUp(() { setUp(() {
final MemoryFileSystem fs = MemoryFileSystem.test(); final MemoryFileSystem fs = MemoryFileSystem.test();
iosProjectDirectory = fs.directory('ios'); projectDirectory = fs.directory('flutter_project');
}); });
testWithoutContext('removes xattr', () async { testWithoutContext('removes xattr', () async {
...@@ -458,11 +458,11 @@ Exited (sigterm)''', ...@@ -458,11 +458,11 @@ Exited (sigterm)''',
'-r', '-r',
'-d', '-d',
'com.apple.FinderInfo', '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); expect(processManager, hasNoRemainingExpectations);
}); });
...@@ -473,12 +473,12 @@ Exited (sigterm)''', ...@@ -473,12 +473,12 @@ Exited (sigterm)''',
'-r', '-r',
'-d', '-d',
'com.apple.FinderInfo', 'com.apple.FinderInfo',
iosProjectDirectory.path, projectDirectory.path,
], exitCode: 1, ], 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(logger.traceText, contains('Failed to remove xattr com.apple.FinderInfo'));
expect(processManager, hasNoRemainingExpectations); 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