Feat: dSYM debug info for iOS & macOS builds (#101586)

This commit is contained in:
Ivan Dlugos
2022-09-05 20:16:16 +02:00
committed by GitHub
parent 96345a4bb9
commit 723b82e4f0
15 changed files with 601 additions and 81 deletions

View File

@@ -69,7 +69,7 @@ void main() {
OutputPreferences: () => OutputPreferences.test(),
});
testUsingContext('symbolize exits when --debug-info file is missing', () async {
testUsingContext('symbolize exits when --debug-info dwarf file is missing', () async {
final SymbolizeCommand command = SymbolizeCommand(
stdio: stdio,
fileSystem: fileSystem,
@@ -83,6 +83,20 @@ void main() {
OutputPreferences: () => OutputPreferences.test(),
});
testUsingContext('symbolize exits when --debug-info dSYM is missing', () async {
final SymbolizeCommand command = SymbolizeCommand(
stdio: stdio,
fileSystem: fileSystem,
dwarfSymbolizationService: DwarfSymbolizationService.test(),
);
final Future<void> result = createTestCommandRunner(command)
.run(const <String>['symbolize', '--debug-info=app.dSYM']);
expect(result, throwsToolExit(message: 'app.dSYM does not exist.'));
}, overrides: <Type, Generator>{
OutputPreferences: () => OutputPreferences.test(),
});
testUsingContext('symbolize exits when --input file is missing', () async {
final SymbolizeCommand command = SymbolizeCommand(
stdio: stdio,

View File

@@ -210,7 +210,6 @@ void main() {
'--deterministic',
'--snapshot_kind=app-aot-assembly',
'--assembly=$assembly',
'--strip',
'main.dill',
]),
kWhichSysctlCommand,
@@ -253,6 +252,21 @@ void main() {
'build/foo/App.framework/App',
'build/foo/snapshot_assembly.o',
]),
const FakeCommand(command: <String>[
'xcrun',
'dsymutil',
'-o',
'build/foo/App.framework.dSYM',
'build/foo/App.framework/App',
]),
const FakeCommand(command: <String>[
'xcrun',
'strip',
'-S',
'build/foo/App.framework/App',
'-o',
'build/foo/App.framework/App',
]),
]);
final int genSnapshotExitCode = await snapshotter.build(
@@ -285,7 +299,6 @@ void main() {
'--deterministic',
'--snapshot_kind=app-aot-assembly',
'--assembly=$assembly',
'--strip',
'--dwarf-stack-traces',
'--save-debugging-info=$debugPath',
'main.dill',
@@ -312,6 +325,21 @@ void main() {
'arm64',
...kDefaultClang,
]),
const FakeCommand(command: <String>[
'xcrun',
'dsymutil',
'-o',
'build/foo/App.framework.dSYM',
'build/foo/App.framework/App',
]),
const FakeCommand(command: <String>[
'xcrun',
'strip',
'-S',
'build/foo/App.framework/App',
'-o',
'build/foo/App.framework/App',
]),
]);
final int genSnapshotExitCode = await snapshotter.build(
@@ -344,7 +372,6 @@ void main() {
'--deterministic',
'--snapshot_kind=app-aot-assembly',
'--assembly=$assembly',
'--strip',
'--obfuscate',
'main.dill',
]),
@@ -370,6 +397,21 @@ void main() {
'arm64',
...kDefaultClang,
]),
const FakeCommand(command: <String>[
'xcrun',
'dsymutil',
'-o',
'build/foo/App.framework.dSYM',
'build/foo/App.framework/App',
]),
const FakeCommand(command: <String>[
'xcrun',
'strip',
'-S',
'build/foo/App.framework/App',
'-o',
'build/foo/App.framework/App',
]),
]);
final int genSnapshotExitCode = await snapshotter.build(
@@ -400,7 +442,6 @@ void main() {
'--deterministic',
'--snapshot_kind=app-aot-assembly',
'--assembly=${fileSystem.path.join(outputPath, 'snapshot_assembly.S')}',
'--strip',
'main.dill',
]),
kWhichSysctlCommand,
@@ -425,6 +466,21 @@ void main() {
'arm64',
...kDefaultClang,
]),
const FakeCommand(command: <String>[
'xcrun',
'dsymutil',
'-o',
'build/foo/App.framework.dSYM',
'build/foo/App.framework/App',
]),
const FakeCommand(command: <String>[
'xcrun',
'strip',
'-S',
'build/foo/App.framework/App',
'-o',
'build/foo/App.framework/App',
]),
]);
final int genSnapshotExitCode = await snapshotter.build(

View File

@@ -477,7 +477,6 @@ void main() {
'--deterministic',
kAssemblyAot,
'--assembly=$build/arm64/snapshot_assembly.S',
'--strip',
'$build/app.dill',
]),
FakeCommand(command: <String>[
@@ -520,6 +519,21 @@ void main() {
'$build/arm64/App.framework/App',
'$build/arm64/snapshot_assembly.o',
]),
FakeCommand(command: <String>[
'xcrun',
'dsymutil',
'-o',
'$build/arm64/App.framework.dSYM',
'$build/arm64/App.framework/App',
]),
FakeCommand(command: <String>[
'xcrun',
'strip',
'-S',
'$build/arm64/App.framework/App',
'-o',
'$build/arm64/App.framework/App',
]),
FakeCommand(command: <String>[
'lipo',
'$build/arm64/App.framework/App',
@@ -553,7 +567,6 @@ void main() {
'--trace-precompiler-to=code_size_1/trace.arm64.json',
kAssemblyAot,
'--assembly=$build/arm64/snapshot_assembly.S',
'--strip',
'$build/app.dill',
]),
FakeCommand(command: <String>[
@@ -596,6 +609,21 @@ void main() {
'$build/arm64/App.framework/App',
'$build/arm64/snapshot_assembly.o',
]),
FakeCommand(command: <String>[
'xcrun',
'dsymutil',
'-o',
'$build/arm64/App.framework.dSYM',
'$build/arm64/App.framework/App',
]),
FakeCommand(command: <String>[
'xcrun',
'strip',
'-S',
'$build/arm64/App.framework/App',
'-o',
'$build/arm64/App.framework/App',
]),
FakeCommand(command: <String>[
'lipo',
'$build/arm64/App.framework/App',

View File

@@ -239,6 +239,14 @@ void main() {
.childFile('App')
.createSync(recursive: true);
// Input dSYM
environment.buildDir
.childDirectory('App.framework.dSYM')
.childDirectory('Contents')
.childDirectory('Resources')
.childDirectory('DWARF')
.childFile('App')
.createSync(recursive: true);
final Directory frameworkDirectory = environment.outputDir.childDirectory('App.framework');
final File frameworkDirectoryBinary = frameworkDirectory.childFile('App');
@@ -257,6 +265,12 @@ void main() {
expect(frameworkDirectoryBinary, exists);
expect(frameworkDirectory.childFile('Info.plist'), exists);
expect(environment.outputDir
.childDirectory('App.framework.dSYM')
.childDirectory('Contents')
.childDirectory('Resources')
.childDirectory('DWARF')
.childFile('App'), exists);
final Directory assetDirectory = frameworkDirectory.childDirectory('flutter_assets');
expect(assetDirectory.childFile('kernel_blob.bin'), isNot(exists));

View File

@@ -295,6 +295,28 @@ void main() {
ProcessManager: () => processManager,
});
testUsingContext('release macOS application creates App.framework.dSYM', () async {
fileSystem.file('bin/cache/artifacts/engine/darwin-x64/vm_isolate_snapshot.bin')
.createSync(recursive: true);
fileSystem.file('bin/cache/artifacts/engine/darwin-x64/isolate_snapshot.bin')
.createSync(recursive: true);
fileSystem.file('${environment.buildDir.path}/App.framework/App')
.createSync(recursive: true);
fileSystem.file('${environment.buildDir.path}/App.framework.dSYM/Contents/Resources/DWARF/App')
.createSync(recursive: true);
await const ReleaseMacOSBundleFlutterAssets()
.build(environment..defines[kBuildMode] = 'release');
expect(fileSystem.file(
'App.framework.dSYM/Contents/Resources/DWARF/App'),
exists,
);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});
testUsingContext('release/profile macOS application updates when App.framework updates', () async {
fileSystem.file('bin/cache/artifacts/engine/darwin-x64/vm_isolate_snapshot.bin')
.createSync(recursive: true);
@@ -415,13 +437,20 @@ void main() {
environment.defines[kDarwinArchs] = 'arm64 x86_64';
environment.defines[kBuildMode] = 'release';
// Input dSYMs need to exist for `lipo` to combine them
environment.buildDir
.childFile('arm64/App.framework.dSYM/Contents/Resources/DWARF/App')
.createSync(recursive: true);
environment.buildDir
.childFile('x86_64/App.framework.dSYM/Contents/Resources/DWARF/App')
.createSync(recursive: true);
processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
'Artifact.genSnapshot.TargetPlatform.darwin.release_arm64',
'--deterministic',
'--snapshot_kind=app-aot-assembly',
'--assembly=${environment.buildDir.childFile('arm64/snapshot_assembly.S').path}',
'--strip',
environment.buildDir.childFile('app.dill').path,
]),
FakeCommand(command: <String>[
@@ -429,7 +458,6 @@ void main() {
'--deterministic',
'--snapshot_kind=app-aot-assembly',
'--assembly=${environment.buildDir.childFile('x86_64/snapshot_assembly.S').path}',
'--strip',
environment.buildDir.childFile('app.dill').path,
]),
FakeCommand(command: <String>[
@@ -458,6 +486,36 @@ void main() {
'-o', environment.buildDir.childFile('x86_64/App.framework/App').path,
environment.buildDir.childFile('x86_64/snapshot_assembly.o').path,
]),
FakeCommand(command: <String>[
'xcrun',
'dsymutil',
'-o',
environment.buildDir.childFile('arm64/App.framework.dSYM').path,
environment.buildDir.childFile('arm64/App.framework/App').path,
]),
FakeCommand(command: <String>[
'xcrun',
'dsymutil',
'-o',
environment.buildDir.childFile('x86_64/App.framework.dSYM').path,
environment.buildDir.childFile('x86_64/App.framework/App').path,
]),
FakeCommand(command: <String>[
'xcrun',
'strip',
'-S',
environment.buildDir.childFile('arm64/App.framework/App').path,
'-o',
environment.buildDir.childFile('arm64/App.framework/App').path,
]),
FakeCommand(command: <String>[
'xcrun',
'strip',
'-S',
environment.buildDir.childFile('x86_64/App.framework/App').path,
'-o',
environment.buildDir.childFile('x86_64/App.framework/App').path,
]),
FakeCommand(command: <String>[
'lipo',
environment.buildDir.childFile('arm64/App.framework/App').path,
@@ -466,6 +524,14 @@ void main() {
'-output',
environment.buildDir.childFile('App.framework/App').path,
]),
FakeCommand(command: <String>[
'lipo',
environment.buildDir.childFile('arm64/App.framework.dSYM/Contents/Resources/DWARF/App').path,
environment.buildDir.childFile('x86_64/App.framework.dSYM/Contents/Resources/DWARF/App').path,
'-create',
'-output',
environment.buildDir.childFile('App.framework.dSYM/Contents/Resources/DWARF/App').path,
]),
]);
await const CompileMacOSFramework().build(environment);

View File

@@ -5,6 +5,7 @@
import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/utils.dart';
import 'package:flutter_tools/src/build_info.dart';
import '../integration.shard/test_utils.dart';
@@ -75,7 +76,7 @@ void main() {
for (final BuildMode buildMode in <BuildMode>[BuildMode.debug, BuildMode.release]) {
group('build in ${buildMode.name} mode', () {
late Directory buildPath;
late Directory outputPath;
late Directory outputApp;
late Directory frameworkDirectory;
late Directory outputFlutterFramework;
@@ -83,6 +84,9 @@ void main() {
late Directory outputAppFramework;
late File outputAppFrameworkBinary;
late File outputPluginFrameworkBinary;
late Directory buildPath;
late Directory buildAppFrameworkDsym;
late File buildAppFrameworkDsymBinary;
late ProcessResult buildResult;
setUpAll(() {
@@ -98,14 +102,14 @@ void main() {
'--split-debug-info=foo debug info/',
], workingDirectory: projectRoot);
buildPath = fileSystem.directory(fileSystem.path.join(
outputPath = fileSystem.directory(fileSystem.path.join(
projectRoot,
'build',
'ios',
'iphoneos',
));
outputApp = buildPath.childDirectory('Runner.app');
outputApp = outputPath.childDirectory('Runner.app');
frameworkDirectory = outputApp.childDirectory('Frameworks');
outputFlutterFramework = frameworkDirectory.childDirectory('Flutter.framework');
@@ -115,6 +119,16 @@ void main() {
outputAppFrameworkBinary = outputAppFramework.childFile('App');
outputPluginFrameworkBinary = frameworkDirectory.childDirectory('hello.framework').childFile('hello');
buildPath = fileSystem.directory(fileSystem.path.join(
projectRoot,
'build',
'ios',
'${sentenceCase(buildMode.name)}-iphoneos',
));
buildAppFrameworkDsym = buildPath.childDirectory('App.framework.dSYM');
buildAppFrameworkDsymBinary = buildAppFrameworkDsym.childFile('Contents/Resources/DWARF/App');
});
testWithoutContext('flutter build ios builds a valid app', () {
@@ -128,6 +142,8 @@ void main() {
expect(outputAppFrameworkBinary, exists);
expect(outputAppFramework.childFile('Info.plist'), exists);
expect(buildAppFrameworkDsymBinary.existsSync(), buildMode != BuildMode.debug);
final File vmSnapshot = fileSystem.file(fileSystem.path.join(
outputAppFramework.path,
'flutter_assets',
@@ -190,6 +206,25 @@ void main() {
expect(aotSymbolsFound, buildMode != BuildMode.debug);
});
// dSYM is not created for a debug build so nothing to check.
if (buildMode != BuildMode.debug) {
testWithoutContext('check symbols in dSYM', () {
final ProcessResult nm = processManager.runSync(
<String>[
'nm',
'--debug-syms',
'--defined-only',
'--just-symbol-name',
buildAppFrameworkDsymBinary.path,
'-arch',
'arm64',
],
);
final List<String> symbols = (nm.stdout as String).split('\n');
expect(symbols, contains('_kDartVmSnapshotInstructions'));
});
}
testWithoutContext('xcode_backend embed_and_thin', () {
outputFlutterFramework.deleteSync(recursive: true);
outputAppFramework.deleteSync(recursive: true);
@@ -219,7 +254,7 @@ void main() {
'ios',
'Release-iphoneos',
),
'TARGET_BUILD_DIR': buildPath.path,
'TARGET_BUILD_DIR': outputPath.path,
'FRAMEWORKS_FOLDER_PATH': 'Runner.app/Frameworks',
'VERBOSE_SCRIPT_LOGGING': '1',
'FLUTTER_BUILD_MODE': 'release',

View File

@@ -67,18 +67,18 @@ void main() {
expect(result.exitCode, 0);
expect(result.stdout, contains('Running pod install'));
expect(podfile.lastModifiedSync().isBefore(podfileLock.lastModifiedSync()), isTrue);
final Directory outputApp = fileSystem.directory(fileSystem.path.join(
final Directory buildPath = fileSystem.directory(fileSystem.path.join(
workingDirectory,
'build',
'macos',
'Build',
'Products',
buildMode,
'flutter_gallery.app',
));
expect(podfile.lastModifiedSync().isBefore(podfileLock.lastModifiedSync()), isTrue);
final Directory outputApp = buildPath.childDirectory('flutter_gallery.app');
final Directory outputAppFramework =
fileSystem.directory(fileSystem.path.join(
outputApp.path,
@@ -87,19 +87,19 @@ void main() {
'App.framework',
));
final File outputAppFrameworkBinary = outputAppFramework.childFile('App');
final String archs = processManager.runSync(
<String>['file', outputAppFrameworkBinary.path],
).stdout as String;
_checkFatBinary(
outputAppFramework.childFile('App'),
buildModeLower,
'dynamically linked shared library',
);
final bool containsX64 = archs.contains('Mach-O 64-bit dynamically linked shared library x86_64');
final bool containsArm = archs.contains('Mach-O 64-bit dynamically linked shared library arm64');
if (buildModeLower == 'debug') {
// Only build the architecture matching the machine running this test, not both.
expect(containsX64 ^ containsArm, isTrue, reason: 'Unexpected architecture $archs');
} else {
expect(containsX64, isTrue, reason: 'Unexpected architecture $archs');
expect(containsArm, isTrue, reason: 'Unexpected architecture $archs');
// dSYM is not created for a debug build so nothing to check.
if (buildMode != 'Debug') {
_checkFatBinary(
buildPath.childFile('App.framework.dSYM/Contents/Resources/DWARF/App'),
buildModeLower,
'dSYM companion file',
);
}
expect(outputAppFramework.childLink('Resources'), exists);
@@ -172,3 +172,19 @@ void main() {
}, skip: !platform.isMacOS); // [intended] only makes sense for macos platform.
}
}
void _checkFatBinary(File file, String buildModeLower, String expectedType) {
final String archs = processManager.runSync(
<String>['file', file.path],
).stdout as String;
final bool containsX64 = archs.contains('Mach-O 64-bit $expectedType x86_64');
final bool containsArm = archs.contains('Mach-O 64-bit $expectedType arm64');
if (buildModeLower == 'debug') {
// Only build the architecture matching the machine running this test, not both.
expect(containsX64 ^ containsArm, isTrue, reason: 'Unexpected architecture $archs');
} else {
expect(containsX64, isTrue, reason: 'Unexpected architecture $archs');
expect(containsArm, isTrue, reason: 'Unexpected architecture $archs');
}
}