Skip to content

Commit

Permalink
delete entitlements files after copying to macos build dir
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherfujino committed May 19, 2023
1 parent d211dc1 commit 9787320
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/flutter_tools/lib/src/build_system/targets/macos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -81,6 +83,19 @@ abstract class UnpackMacOS extends Target {
_thinFramework(environment, frameworkBinaryPath);
}

static const List<String> _copyDenylist = <String>['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<String> archList = archs.split(' ').toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>[
FakeCommand(
command: <String>[
'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: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});

testUsingContext('thinning fails when framework missing', () async {
processManager.addCommand(copyFrameworkCommand);
await expectLater(
Expand Down

0 comments on commit 9787320

Please sign in to comment.