[flutter_tools] support --split-debug-info option in android builds (#49650)

This commit is contained in:
Jonah Williams
2020-02-05 17:45:24 -08:00
committed by GitHub
parent de7908f9e9
commit da4b5d68c4
19 changed files with 231 additions and 2 deletions

View File

@@ -338,6 +338,9 @@ Future<void> buildGradleApp({
if (androidBuildInfo.fastStart) {
command.add('-Pfast-start=true');
}
if (androidBuildInfo.buildInfo.splitDebugInfoPath != null) {
command.add('-Psplit-debug-info=${androidBuildInfo.buildInfo.splitDebugInfoPath}');
}
if (androidBuildInfo.buildInfo.treeShakeIcons) {
command.add('-Ptree-shake-icons=true');
}

View File

@@ -92,6 +92,7 @@ class AotBuilder {
extraGenSnapshotOptions: extraGenSnapshotOptions,
bitcode: bitcode,
quiet: quiet,
splitDebugInfo: null,
).then<int>((int buildExitCode) {
return buildExitCode;
});
@@ -128,6 +129,7 @@ class AotBuilder {
outputPath: outputPath,
extraGenSnapshotOptions: extraGenSnapshotOptions,
bitcode: false,
splitDebugInfo: null,
);
if (snapshotExitCode != 0) {
status?.cancel();

View File

@@ -94,6 +94,7 @@ class AOTSnapshotter {
DarwinArch darwinArch,
List<String> extraGenSnapshotOptions = const <String>[],
@required bool bitcode,
@required String splitDebugInfo,
bool quiet = false,
}) async {
if (bitcode && platform != TargetPlatform.ios) {
@@ -157,11 +158,25 @@ class AOTSnapshotter {
genSnapshotArgs.add('--no-use-integer-division');
}
// The name of the debug file must contain additonal information about
// the architecture, since a single build command may produce
// multiple debug files.
final String archName = getNameForTargetPlatform(platform, darwinArch: darwinArch);
final String debugFilename = 'app.$archName.symbols';
if (splitDebugInfo != null) {
globals.fs.directory(splitDebugInfo)
.createSync(recursive: true);
}
// Optimization arguments.
genSnapshotArgs.addAll(<String>[
// Faster async/await
'--no-causal-async-stacks',
'--lazy-async-stacks',
if (splitDebugInfo != null) ...<String>[
'--dwarf-stack-traces',
'--save-debugging-info=${globals.fs.path.join(splitDebugInfo, debugFilename)}'
]
]);
genSnapshotArgs.add(mainPath);

View File

@@ -21,6 +21,7 @@ class BuildInfo {
this.fileSystemScheme,
this.buildNumber,
this.buildName,
this.splitDebugInfoPath,
@required this.treeShakeIcons,
});
@@ -62,6 +63,11 @@ class BuildInfo {
/// On Xcode builds it is used as CFBundleShortVersionString,
final String buildName;
/// An optional directory path to save debugging information from dwarf stack
/// traces. If null, stack trace information is not stripped from the
/// executable.
final String splitDebugInfoPath;
static const BuildInfo debug = BuildInfo(BuildMode.debug, null, treeShakeIcons: false);
static const BuildInfo profile = BuildInfo(BuildMode.profile, null, treeShakeIcons: kIconTreeShakerEnabledDefault);
static const BuildInfo jitRelease = BuildInfo(BuildMode.jitRelease, null, treeShakeIcons: kIconTreeShakerEnabledDefault);
@@ -392,7 +398,7 @@ DarwinArch getIOSArchForName(String arch) {
return null;
}
String getNameForTargetPlatform(TargetPlatform platform) {
String getNameForTargetPlatform(TargetPlatform platform, {DarwinArch darwinArch}) {
switch (platform) {
case TargetPlatform.android_arm:
return 'android-arm';
@@ -403,6 +409,9 @@ String getNameForTargetPlatform(TargetPlatform platform) {
case TargetPlatform.android_x86:
return 'android-x86';
case TargetPlatform.ios:
if (darwinArch != null) {
return 'ios-${getNameForDarwinArch(darwinArch)}';
}
return 'ios';
case TargetPlatform.darwin_x64:
return 'darwin-x64';

View File

@@ -204,6 +204,7 @@ class AndroidAot extends AotElfBase {
Future<void> build(Environment environment) async {
final AOTSnapshotter snapshotter = AOTSnapshotter(reportTimings: false);
final Directory output = environment.buildDir.childDirectory(_androidAbiName);
final String splitDebugInfo = environment.defines[kSplitDebugInfo];
if (environment.defines[kBuildMode] == null) {
throw MissingDefineException(kBuildMode, 'aot_elf');
}
@@ -221,6 +222,7 @@ class AndroidAot extends AotElfBase {
outputPath: output.path,
bitcode: false,
extraGenSnapshotOptions: extraGenSnapshotOptions,
splitDebugInfo: splitDebugInfo,
);
if (snapshotExitCode != 0) {
throw Exception('AOT snapshotter exited with code $snapshotExitCode');

View File

@@ -41,6 +41,9 @@ const String kExtraFrontEndOptions = 'ExtraFrontEndOptions';
/// This is expected to be a comma separated list of strings.
const String kExtraGenSnapshotOptions = 'ExtraGenSnapshotOptions';
/// Whether to strip source code information out of release builds and where to save it.
const String kSplitDebugInfo = 'SplitDebugInfo';
/// Alternative scheme for file URIs.
///
/// May be used along with [kFileSystemRoots] to support a multi-root
@@ -259,6 +262,7 @@ abstract class AotElfBase extends Target {
?? const <String>[];
final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]);
final TargetPlatform targetPlatform = getTargetPlatformForName(environment.defines[kTargetPlatform]);
final String saveDebuggingInformation = environment.defines[kSplitDebugInfo];
final int snapshotExitCode = await snapshotter.build(
platform: targetPlatform,
buildMode: buildMode,
@@ -267,6 +271,7 @@ abstract class AotElfBase extends Target {
outputPath: outputPath,
bitcode: false,
extraGenSnapshotOptions: extraGenSnapshotOptions,
splitDebugInfo: saveDebuggingInformation
);
if (snapshotExitCode != 0) {
throw Exception('AOT snapshotter exited with code $snapshotExitCode');

View File

@@ -38,6 +38,7 @@ abstract class AotAssemblyBase extends Target {
final bool bitcode = environment.defines[kBitcodeFlag] == 'true';
final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]);
final TargetPlatform targetPlatform = getTargetPlatformForName(environment.defines[kTargetPlatform]);
final String splitDebugInfo = environment.defines[kSplitDebugInfo];
final List<DarwinArch> iosArchs = environment.defines[kIosArchs]
?.split(' ')
?.map(getIOSArchForName)
@@ -60,6 +61,7 @@ abstract class AotAssemblyBase extends Target {
darwinArch: iosArch,
bitcode: bitcode,
quiet: true,
splitDebugInfo: splitDebugInfo,
));
}
final List<int> results = await Future.wait(pending);

View File

@@ -200,6 +200,7 @@ class CompileMacOSFramework extends Target {
if (buildMode == BuildMode.debug) {
throw Exception('precompiled macOS framework only supported in release/profile builds.');
}
final String splitDebugInfo = environment.defines[kSplitDebugInfo];
final int result = await AOTSnapshotter(reportTimings: false).build(
bitcode: false,
buildMode: buildMode,
@@ -208,6 +209,7 @@ class CompileMacOSFramework extends Target {
platform: TargetPlatform.darwin_x64,
darwinArch: DarwinArch.x86_64,
packagesPath: environment.projectDir.childFile('.packages').path,
splitDebugInfo: splitDebugInfo,
);
if (result != 0) {
throw Exception('gen shapshot failed.');

View File

@@ -26,6 +26,7 @@ class BuildApkCommand extends BuildSubCommand {
usesBuildNumberOption();
usesBuildNameOption();
addShrinkingFlag();
addSplitDebugInfoOption();
argParser
..addFlag('split-per-abi',
negatable: false,

View File

@@ -167,6 +167,11 @@ List<String> _xcodeBuildSettingsLines({
xcodeBuildSettings.add('FLUTTER_TARGET=$targetOverride');
}
// This is an optional path to split debug info
if (buildInfo.splitDebugInfoPath != null) {
xcodeBuildSettings.add('SPLIT_DEBUG_INFO=${buildInfo.splitDebugInfoPath}');
}
// The build outputs directory, relative to FLUTTER_APPLICATION_PATH.
xcodeBuildSettings.add('FLUTTER_BUILD_DIR=${buildDirOverride ?? getBuildDirectory()}');

View File

@@ -107,6 +107,7 @@ class FlutterOptions {
static const String kEnableExperiment = 'enable-experiment';
static const String kFileSystemRoot = 'filesystem-root';
static const String kFileSystemScheme = 'filesystem-scheme';
static const String kSplitDebugInfoOption = 'split-debug-info';
}
abstract class FlutterCommand extends Command<void> {
@@ -366,6 +367,20 @@ abstract class FlutterCommand extends Command<void> {
help: 'Build a JIT release version of your app${defaultToRelease ? ' (default mode)' : ''}.');
}
void addSplitDebugInfoOption() {
argParser.addOption(FlutterOptions.kSplitDebugInfoOption,
help: 'In a release build, this flag reduces application size by storing '
'Dart program symbols in a separate file on the host rather than in the '
'application. The value of the flag should be a directory where program '
'symbol files can be stored for later use. These symbol files contain '
'the information needed to symbolize Dart stack traces. For an app built '
'with this flag, the \'flutter symbolize\' command with the right program '
'symbol file is required to obtain a human readable stack trace. This '
'command is tracked by https://github.com/flutter/flutter/issues/50206',
valueHelp: '/project-name/v1.2.3/',
);
}
void addTreeShakeIconsFlag() {
argParser.addFlag('tree-shake-icons',
negatable: true,
@@ -499,6 +514,9 @@ abstract class FlutterCommand extends Command<void> {
buildName: argParser.options.containsKey('build-name')
? stringArg('build-name')
: null,
splitDebugInfoPath: argParser.options.containsKey(FlutterOptions.kSplitDebugInfoOption)
? stringArg(FlutterOptions.kSplitDebugInfoOption)
: null,
treeShakeIcons: argParser.options.containsKey('tree-shake-icons')
? boolArg('tree-shake-icons')
: kIconTreeShakerEnabledDefault,