From 3e6fe491f3689973f61f62ceba60908b6c03e14f Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Thu, 6 May 2021 16:34:04 -0700 Subject: [PATCH] Remove extended attributes from entire Flutter project (#81435) --- .../lib/src/build_system/targets/ios.dart | 19 +---- packages/flutter_tools/lib/src/ios/mac.dart | 8 +- .../hermetic/build_ios_test.dart | 2 +- .../hermetic/build_ipa_test.dart | 2 +- .../build_system/targets/ios_test.dart | 81 +------------------ .../ios_device_start_nonprebuilt_test.dart | 2 +- .../test/general.shard/ios/mac_test.dart | 12 +-- 7 files changed, 20 insertions(+), 106 deletions(-) diff --git a/packages/flutter_tools/lib/src/build_system/targets/ios.dart b/packages/flutter_tools/lib/src/build_system/targets/ios.dart index eb9a7775b8..dbef1fa0c0 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/ios.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/ios.dart @@ -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([ - '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([ + final ProcessResult result = environment.processManager.runSync([ '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}'); } } diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart index eea194798e..1438d736d8 100644 --- a/packages/flutter_tools/lib/src/ios/mac.dart +++ b/packages/flutter_tools/lib/src/ios/mac.dart @@ -122,7 +122,7 @@ Future 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 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 removeFinderExtendedAttributes(Directory iosProjectDirectory, ProcessUtils processUtils, Logger logger) async { +Future removeFinderExtendedAttributes(Directory projectDirectory, ProcessUtils processUtils, Logger logger) async { final bool success = await processUtils.exitsHappy( [ '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}'); } } diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_ios_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_ios_test.dart index bb25637a60..9974e564a3 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_ios_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_ios_test.dart @@ -75,7 +75,7 @@ void main() { } const FakeCommand xattrCommand = FakeCommand(command: [ - 'xattr', '-r', '-d', 'com.apple.FinderInfo', '/ios' + 'xattr', '-r', '-d', 'com.apple.FinderInfo', '/' ]); FakeCommand _setUpRsyncCommand({void Function() onRun}) { 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 50d359a64d..52220cd0fe 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 @@ -76,7 +76,7 @@ void main() { } const FakeCommand xattrCommand = FakeCommand(command: [ - 'xattr', '-r', '-d', 'com.apple.FinderInfo', '/ios' + 'xattr', '-r', '-d', 'com.apple.FinderInfo', '/' ]); // Creates a FakeCommand for the xcodebuild call to build the app diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/ios_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/ios_test.dart index b0efc01f24..d3e1c238e8 100644 --- a/packages/flutter_tools/test/general.shard/build_system/targets/ios_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/targets/ios_test.dart @@ -138,14 +138,7 @@ void main() { final Directory frameworkDirectory = environment.outputDir.childDirectory('App.framework'); final File frameworkDirectoryBinary = frameworkDirectory.childFile('App'); - processManager.addCommands([ - FakeCommand(command: [ - 'xattr', - '-r', - '-d', - 'com.apple.FinderInfo', - frameworkDirectoryBinary.path, - ]), + processManager.addCommand( FakeCommand(command: [ '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(command: [ - 'xattr', - '-r', - '-d', - 'com.apple.FinderInfo', - frameworkDirectoryBinary.path, - ]), + processManager.addCommand( FakeCommand(command: [ '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: [ - '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: { - kIosArchs: 'arm64', - kSdkRoot: 'path/to/iPhoneOS.sdk', - kBitcodeFlag: '', - kCodesignIdentity: 'ABC123', - }, - ); - - processManager.addCommands([ - copyPhysicalFrameworkCommand, - lipoCommandNonFatResult, - lipoVerifyArm64Command, - bitcodeStripCommand, - FakeCommand( - command: [ - 'xattr', - '-r', - '-d', - 'com.apple.FinderInfo', - binary.path, - ], - exitCode: 1, - stderr: 'Failed to remove extended attributes', - ), - FakeCommand(command: [ - '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: [ 'codesign', '--force', @@ -760,7 +688,6 @@ void main() { lipoCommandNonFatResult, lipoVerifyArm64Command, bitcodeStripCommand, - xattrRemoveCommand, FakeCommand(command: [ 'codesign', '--force', diff --git a/packages/flutter_tools/test/general.shard/ios/ios_device_start_nonprebuilt_test.dart b/packages/flutter_tools/test/general.shard/ios/ios_device_start_nonprebuilt_test.dart index bde5fcb7f8..bc8589daa3 100644 --- a/packages/flutter_tools/test/general.shard/ios/ios_device_start_nonprebuilt_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/ios_device_start_nonprebuilt_test.dart @@ -37,7 +37,7 @@ List _xattrArgs(FlutterProject flutterProject) { '-r', '-d', 'com.apple.FinderInfo', - flutterProject.ios.hostAppRoot.path, + flutterProject.directory.path, ]; } diff --git a/packages/flutter_tools/test/general.shard/ios/mac_test.dart b/packages/flutter_tools/test/general.shard/ios/mac_test.dart index dcabee550d..0cd3e90f58 100644 --- a/packages/flutter_tools/test/general.shard/ios/mac_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/mac_test.dart @@ -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); });