[go: nahoru, domu]

Skip to content

Commit

Permalink
[flutter_tools] support --split-debug-info option in android builds (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahwilliams committed Feb 6, 2020
1 parent de7908f commit da4b5d6
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ unlinked_spec.ds
# Coverage
coverage/

# Symbols
app.*.symbols

# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
Expand Down
9 changes: 8 additions & 1 deletion packages/flutter_tools/bin/macos_assemble.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ if [[ -n "$FLUTTER_ENGINE" ]]; then
flutter_engine_flag="--local-engine-src-path=${FLUTTER_ENGINE}"
fi

# Provide location to split debug info
split_debug_info_option=""
if [[ -n "$SPLIT_DEBUG_INFO" ]]; then
split_debug_info_option="-dSplitDebugInfo=${SPLIT_DEBUG_INFO}"
fi

# Set the build mode
build_mode="$(echo "${FLUTTER_BUILD_MODE:-${CONFIGURATION}}" | tr "[:upper:]" "[:lower:]")"

Expand Down Expand Up @@ -75,7 +81,8 @@ RunCommand "${FLUTTER_ROOT}/bin/flutter" --suppress-analytics \
-dTargetPlatform=darwin-x64 \
-dTargetFile="${target_path}" \
-dBuildMode="${build_mode}" \
-dFontSubset="${icon_tree_shaker_flag}" \
"${split_debug_info_option}" \
-dFontSubset="${icon_tree_shaker_flag}" \
--build-inputs="${build_inputs_path}" \
--build-outputs="${build_outputs_path}" \
--output="${ephemeral_dir}" \
Expand Down
10 changes: 10 additions & 0 deletions packages/flutter_tools/gradle/flutter.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,10 @@ class FlutterPlugin implements Plugin<Project> {
if (project.hasProperty('extra-gen-snapshot-options')) {
extraGenSnapshotOptionsValue = project.property('extra-gen-snapshot-options')
}
String splitDebugInfoValue = null
if (project.hasProperty('split-debug-info')) {
splitDebugInfoValue = project.property('split-debug-info')
}
Boolean treeShakeIconsOptionsValue = false
if (project.hasProperty('tree-shake-icons')) {
treeShakeIconsOptionsValue = project.property('tree-shake-icons').toBoolean()
Expand Down Expand Up @@ -641,6 +645,7 @@ class FlutterPlugin implements Plugin<Project> {
intermediateDir project.file("${project.buildDir}/${AndroidProject.FD_INTERMEDIATES}/flutter/${variant.name}/")
extraFrontEndOptions extraFrontEndOptionsValue
extraGenSnapshotOptions extraGenSnapshotOptionsValue
splitDebugInfo splitDebugInfoValue
treeShakeIcons treeShakeIconsOptionsValue
}
File libJar = project.file("${project.buildDir}/${AndroidProject.FD_INTERMEDIATES}/flutter/${variant.name}/libs.jar")
Expand Down Expand Up @@ -775,6 +780,8 @@ abstract class BaseFlutterTask extends DefaultTask {
@Optional @Input
String extraGenSnapshotOptions
@Optional @Input
String splitDebugInfo
@Optional @Input
Boolean treeShakeIcons

@OutputFiles
Expand Down Expand Up @@ -832,6 +839,9 @@ abstract class BaseFlutterTask extends DefaultTask {
if (extraFrontEndOptions != null) {
args "-dExtraFrontEndOptions=${extraFrontEndOptions}"
}
if (splitDebugInfo != null) {
args "-dSplitDebugInfo=${splitDebugInfo}"
}
if (treeShakeIcons == true) {
args "-dTreeShakeIcons=true"
}
Expand Down
3 changes: 3 additions & 0 deletions packages/flutter_tools/lib/src/android/gradle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
2 changes: 2 additions & 0 deletions packages/flutter_tools/lib/src/aot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class AotBuilder {
extraGenSnapshotOptions: extraGenSnapshotOptions,
bitcode: bitcode,
quiet: quiet,
splitDebugInfo: null,
).then<int>((int buildExitCode) {
return buildExitCode;
});
Expand Down Expand Up @@ -128,6 +129,7 @@ class AotBuilder {
outputPath: outputPath,
extraGenSnapshotOptions: extraGenSnapshotOptions,
bitcode: false,
splitDebugInfo: null,
);
if (snapshotExitCode != 0) {
status?.cancel();
Expand Down
15 changes: 15 additions & 0 deletions packages/flutter_tools/lib/src/base/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion packages/flutter_tools/lib/src/build_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class BuildInfo {
this.fileSystemScheme,
this.buildNumber,
this.buildName,
this.splitDebugInfoPath,
@required this.treeShakeIcons,
});

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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';
Expand All @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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');
Expand Down
5 changes: 5 additions & 0 deletions packages/flutter_tools/lib/src/build_system/targets/dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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');
Expand Down
2 changes: 2 additions & 0 deletions packages/flutter_tools/lib/src/build_system/targets/ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.');
Expand Down
1 change: 1 addition & 0 deletions packages/flutter_tools/lib/src/commands/build_apk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class BuildApkCommand extends BuildSubCommand {
usesBuildNumberOption();
usesBuildNameOption();
addShrinkingFlag();
addSplitDebugInfoOption();
argParser
..addFlag('split-per-abi',
negatable: false,
Expand Down
5 changes: 5 additions & 0 deletions packages/flutter_tools/lib/src/ios/xcodeproj.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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()}');

Expand Down
18 changes: 18 additions & 0 deletions packages/flutter_tools/lib/src/runner/flutter_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions packages/flutter_tools/templates/app/.gitignore.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@
# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

# Exceptions to above rules.
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ build/
.ios/
.flutter-plugins
.flutter-plugins-dependencies

# Symbolication related
app.*.symbols
Loading

0 comments on commit da4b5d6

Please sign in to comment.