macOS: Copy macOS framwork dSYM into build outputs (#153975)

As of Xcode 16, App Store validation now requires that apps uploaded to the App store bundle dSYM debug information bundles for each Framework they embed.

dSYM bundles are packaged in the FlutterMacOS.xcframework shipped in the `darwin-x64-release` tools archive as of engine patches:
* https://github.com/flutter/engine/pull/54696

This copies the FlutterMacOS.framework.dSYM bundle from the tools cache to the build outputs produced by `flutter build macOS`.

Fixes: https://github.com/flutter/flutter/issues/153879
This commit is contained in:
Chris Bracken
2024-08-23 17:14:15 -07:00
committed by GitHub
parent a09941dcf1
commit 11ab37ee81
4 changed files with 333 additions and 65 deletions

View File

@@ -25,11 +25,15 @@ void main() {
late Artifacts artifacts;
late FakeProcessManager processManager;
late File binary;
late File frameworkDsym;
late BufferLogger logger;
late FakeCommand copyFrameworkCommand;
late FakeCommand releaseCopyFrameworkCommand;
late FakeCommand copyFrameworkDsymCommand;
late FakeCommand lipoInfoNonFatCommand;
late FakeCommand lipoInfoFatCommand;
late FakeCommand lipoVerifyX86_64Command;
late FakeCommand lipoExtractX86_64Command;
late TestUsage usage;
late FakeAnalytics fakeAnalytics;
@@ -79,6 +83,51 @@ void main() {
],
);
releaseCopyFrameworkCommand = FakeCommand(
command: <String>[
'rsync',
'-av',
'--delete',
'--filter',
'- .DS_Store/',
'--chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r',
'Artifact.flutterMacOSFramework.release',
environment.outputDir.path,
],
);
frameworkDsym = fileSystem.directory(
artifacts.getArtifactPath(
Artifact.flutterMacOSFrameworkDsym,
platform: TargetPlatform.darwin,
mode: BuildMode.release,
),
)
.childDirectory('Contents')
.childDirectory('Resources')
.childDirectory('DWARF')
.childFile('FlutterMacOS');
environment.outputDir
.childDirectory('FlutterMacOS.framework.dSYM')
.childDirectory('Contents')
.childDirectory('Resources')
.childDirectory('DWARF')
.childFile('FlutterMacOS');
copyFrameworkDsymCommand = FakeCommand(
command: <String>[
'rsync',
'-av',
'--delete',
'--filter',
'- .DS_Store/',
'--chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r',
'Artifact.flutterMacOSFrameworkDsym.TargetPlatform.darwin.release',
environment.outputDir.path,
],
);
lipoInfoNonFatCommand = FakeCommand(command: <String>[
'lipo',
'-info',
@@ -97,6 +146,15 @@ void main() {
'-verify_arch',
'x86_64',
]);
lipoExtractX86_64Command = FakeCommand(command: <String>[
'lipo',
'-output',
binary.path,
'-extract',
'x86_64',
binary.path,
]);
});
testUsingContext('Copies files to correct cache directory', () async {
@@ -223,14 +281,7 @@ void main() {
copyFrameworkCommand,
lipoInfoFatCommand,
lipoVerifyX86_64Command,
FakeCommand(command: <String>[
'lipo',
'-output',
binary.path,
'-extract',
'x86_64',
binary.path,
]),
lipoExtractX86_64Command,
]);
await const DebugUnpackMacOS().build(environment);
@@ -238,6 +289,76 @@ void main() {
expect(processManager, hasNoRemainingExpectations);
});
testUsingContext('Copies files to correct cache directory when no dSYM available in xcframework', () async {
binary.createSync(recursive: true);
processManager.addCommands(<FakeCommand>[
releaseCopyFrameworkCommand,
lipoInfoNonFatCommand,
lipoVerifyX86_64Command,
]);
await const ReleaseUnpackMacOS().build(environment..defines[kBuildMode] = 'release');
expect(processManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});
testUsingContext('Copies files to correct cache directory when dSYM available in xcframework', () async {
binary.createSync(recursive: true);
frameworkDsym.createSync(recursive: true);
processManager.addCommands(<FakeCommand>[
releaseCopyFrameworkCommand,
lipoInfoNonFatCommand,
lipoVerifyX86_64Command,
copyFrameworkDsymCommand,
]);
await const ReleaseUnpackMacOS().build(environment..defines[kBuildMode] = 'release');
expect(processManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});
testUsingContext('Fails if framework dSYM found within framework but copy fails', () async {
binary.createSync(recursive: true);
frameworkDsym.createSync(recursive: true);
final FakeCommand failedCopyFrameworkDsymCommand = FakeCommand(
command: <String>[
'rsync',
'-av',
'--delete',
'--filter',
'- .DS_Store/',
'--chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r',
'Artifact.flutterMacOSFrameworkDsym.TargetPlatform.darwin.release',
environment.outputDir.path,
], exitCode: 1,
);
processManager.addCommands(<FakeCommand>[
releaseCopyFrameworkCommand,
lipoInfoFatCommand,
lipoVerifyX86_64Command,
lipoExtractX86_64Command,
failedCopyFrameworkDsymCommand,
]);
await expectLater(
const ReleaseUnpackMacOS().build(environment..defines[kBuildMode] = 'release'),
throwsA(isException.having(
(Exception exception) => exception.toString(),
'description',
contains('Failed to copy framework dSYM'),
)),
);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});
testUsingContext('debug macOS application fails if App.framework missing', () async {
fileSystem.directory(
artifacts.getArtifactPath(

View File

@@ -24,48 +24,68 @@ void main() {
]);
});
test('verify FlutterMacOS.xcframework artifact', () {
final String flutterRoot = getFlutterRoot();
for (final String buildMode in <String>['Debug', 'Release']) {
test('verify $buildMode FlutterMacOS.xcframework artifact', () {
final String flutterRoot = getFlutterRoot();
final Directory xcframeworkArtifact = fileSystem.directory(
fileSystem.path.join(
flutterRoot,
'bin',
'cache',
'artifacts',
'engine',
'darwin-x64',
'FlutterMacOS.xcframework',
),
);
final String artifactDir = (buildMode == 'Debug') ? 'darwin-x64' : 'darwin-x64-release';
final Directory xcframeworkArtifact = fileSystem.directory(
fileSystem.path.join(
flutterRoot,
'bin',
'cache',
'artifacts',
'engine',
artifactDir,
'FlutterMacOS.xcframework',
),
);
final Directory tempDir = createResolvedTempDirectorySync('macos_content_validation.');
final Directory tempDir = createResolvedTempDirectorySync('macos_content_validation.');
// Pre-cache macOS engine FlutterMacOS.xcframework artifacts.
final ProcessResult result = processManager.runSync(
<String>[
flutterBin,
...getLocalEngineArguments(),
'precache',
'--macos',
],
workingDirectory: tempDir.path,
);
// Pre-cache macOS engine FlutterMacOS.xcframework artifacts.
final ProcessResult result = processManager.runSync(
<String>[
flutterBin,
...getLocalEngineArguments(),
'precache',
'--macos',
],
workingDirectory: tempDir.path,
);
expect(result, const ProcessResultMatcher());
expect(xcframeworkArtifact.existsSync(), isTrue);
expect(result, const ProcessResultMatcher());
expect(xcframeworkArtifact.existsSync(), isTrue);
final Directory frameworkArtifact = fileSystem.directory(
fileSystem.path.joinAll(<String>[
xcframeworkArtifact.path,
'macos-arm64_x86_64',
'FlutterMacOS.framework',
]),
);
// Check read/write permissions are set correctly in the framework engine artifact.
final String artifactStat = frameworkArtifact.statSync().mode.toRadixString(8);
expect(artifactStat, '40755');
});
final Directory frameworkArtifact = fileSystem.directory(
fileSystem.path.joinAll(<String>[
xcframeworkArtifact.path,
'macos-arm64_x86_64',
'FlutterMacOS.framework',
]),
);
// Check read/write permissions are set correctly in the framework engine artifact.
final String artifactStat = frameworkArtifact.statSync().mode.toRadixString(8);
expect(artifactStat, '40755');
if (buildMode == 'Release') {
final Directory dsymArtifact = fileSystem.directory(
fileSystem.path.joinAll(<String>[
xcframeworkArtifact.path,
'macos-arm64_x86_64',
'dSYMs',
'FlutterMacOS.framework.dSYM',
]),
);
// Verify dSYM is present.
expect(dsymArtifact.existsSync(), isTrue);
// Check read/write permissions are set correctly in the framework engine artifact.
final String artifactStat = dsymArtifact.statSync().mode.toRadixString(8);
expect(artifactStat, '40755');
}
});
}
for (final String buildMode in <String>['Debug', 'Release']) {
final String buildModeLower = buildMode.toLowerCase();
@@ -129,6 +149,9 @@ void main() {
'App.framework',
));
final File frameworkDsymBinary =
buildPath.childFile('FlutterMacOS.framework.dSYM/Contents/Resources/DWARF/FlutterMacOS');
final File libBinary = outputAppFramework.childFile('App');
final File libDsymBinary =
buildPath.childFile('App.framework.dSYM/Contents/Resources/DWARF/App');
@@ -138,10 +161,17 @@ void main() {
final List<String> libSymbols = AppleTestUtils.getExportedSymbols(libBinary.path);
if (buildMode == 'Debug') {
// Framework dSYM is not copied for debug builds.
expect(frameworkDsymBinary.existsSync(), isFalse);
// dSYM is not created for a debug build.
expect(libDsymBinary.existsSync(), isFalse);
expect(libSymbols, isEmpty);
} else {
// Check framework dSYM file copied.
_checkFatBinary(frameworkDsymBinary, buildModeLower, 'dSYM companion file');
// Check extracted dSYM file.
_checkFatBinary(libDsymBinary, buildModeLower, 'dSYM companion file');
expect(libSymbols, equals(AppleTestUtils.requiredSymbols));
final List<String> dSymSymbols =