diff --git a/packages/flutter_tools/lib/src/build_system/targets/macos.dart b/packages/flutter_tools/lib/src/build_system/targets/macos.dart index 8981bb48a02..366268d59f0 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/macos.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/macos.dart @@ -62,6 +62,8 @@ abstract class UnpackMacOS extends Target { basePath, environment.outputDir.path, ]); + + _removeDenylistedFiles(environment.outputDir); if (result.exitCode != 0) { throw Exception( 'Failed to copy framework (exit ${result.exitCode}:\n' @@ -81,6 +83,19 @@ abstract class UnpackMacOS extends Target { _thinFramework(environment, frameworkBinaryPath); } + static const List _copyDenylist = ['entitlements.txt', 'without_entitlements.txt']; + + void _removeDenylistedFiles(Directory directory) { + for (final FileSystemEntity entity in directory.listSync(recursive: true)) { + if (entity is! File) { + continue; + } + if (_copyDenylist.contains(entity.basename)) { + entity.deleteSync(); + } + } + } + void _thinFramework(Environment environment, String frameworkBinaryPath) { final String archs = environment.defines[kDarwinArchs] ?? 'x86_64 arm64'; final List archList = archs.split(' ').toList(); diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/macos_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/macos_test.dart index 176b76b9ad1..2d705301e0f 100644 --- a/packages/flutter_tools/test/general.shard/build_system/targets/macos_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/targets/macos_test.dart @@ -106,6 +106,51 @@ void main() { ProcessManager: () => processManager, }); + testUsingContext('deletes entitlements.txt and without_entitlements.txt files after copying', () async { + binary.createSync(recursive: true); + final File entitlements = environment.outputDir.childFile('entitlements.txt'); + final File withoutEntitlements = environment.outputDir.childFile('without_entitlements.txt'); + final File nestedEntitlements = environment + .outputDir + .childDirectory('first_level') + .childDirectory('second_level') + .childFile('entitlements.txt') + ..createSync(recursive: true); + + processManager.addCommands([ + FakeCommand( + command: [ + 'rsync', + '-av', + '--delete', + '--filter', + '- .DS_Store/', + // source + 'Artifact.flutterMacOSFramework.debug', + // destination + environment.outputDir.path, + ], + onRun: () { + entitlements.writeAsStringSync('foo'); + withoutEntitlements.writeAsStringSync('bar'); + nestedEntitlements.writeAsStringSync('somefile.bin'); + }, + ), + lipoInfoNonFatCommand, + lipoVerifyX86_64Command, + ]); + + await const DebugUnpackMacOS().build(environment); + expect(entitlements.existsSync(), isFalse); + expect(withoutEntitlements.existsSync(), isFalse); + expect(nestedEntitlements.existsSync(), isFalse); + + expect(processManager, hasNoRemainingExpectations); + }, overrides: { + FileSystem: () => fileSystem, + ProcessManager: () => processManager, + }); + testUsingContext('thinning fails when framework missing', () async { processManager.addCommand(copyFrameworkCommand); await expectLater(