Add an option to specify the output for code size intermediate files (#80310)
This commit is contained in:
@@ -115,6 +115,7 @@ class FlutterOptions {
|
||||
static const String kDeviceUser = 'device-user';
|
||||
static const String kDeviceTimeout = 'device-timeout';
|
||||
static const String kAnalyzeSize = 'analyze-size';
|
||||
static const String kCodeSizeDirectory = 'code-size-directory';
|
||||
static const String kNullAssertions = 'null-assertions';
|
||||
static const String kAndroidGradleDaemon = 'android-gradle-daemon';
|
||||
static const String kDeferredComponents = 'deferred-components';
|
||||
@@ -831,8 +832,16 @@ abstract class FlutterCommand extends Command<void> {
|
||||
'This flag is only supported on "--release" builds. When building for Android, a single '
|
||||
'ABI must be specified at a time with the "--target-platform" flag. When building for iOS, '
|
||||
'only the symbols from the arm64 architecture are used to analyze code size.\n'
|
||||
'By default, the intermediate output files will be placed in a transient directory in the '
|
||||
'build directory. This can be overriden with the "--${FlutterOptions.kCodeSizeDirectory}" option.\n'
|
||||
'This flag cannot be combined with "--${FlutterOptions.kSplitDebugInfoOption}".'
|
||||
);
|
||||
|
||||
argParser.addOption(
|
||||
FlutterOptions.kCodeSizeDirectory,
|
||||
help: 'The location to write code size analysis files. If this is not specified, files '
|
||||
'are written to a temporary directory under the build directory.'
|
||||
);
|
||||
}
|
||||
|
||||
/// Compute the [BuildInfo] for the current flutter command.
|
||||
@@ -877,10 +886,13 @@ abstract class FlutterCommand extends Command<void> {
|
||||
|
||||
String codeSizeDirectory;
|
||||
if (argParser.options.containsKey(FlutterOptions.kAnalyzeSize) && boolArg(FlutterOptions.kAnalyzeSize)) {
|
||||
final Directory directory = globals.fsUtils.getUniqueDirectory(
|
||||
Directory directory = globals.fsUtils.getUniqueDirectory(
|
||||
globals.fs.directory(getBuildDirectory()),
|
||||
'flutter_size',
|
||||
);
|
||||
if (argParser.options.containsKey(FlutterOptions.kCodeSizeDirectory) && stringArg(FlutterOptions.kCodeSizeDirectory) != null) {
|
||||
directory = globals.fs.directory(stringArg(FlutterOptions.kCodeSizeDirectory));
|
||||
}
|
||||
directory.createSync(recursive: true);
|
||||
codeSizeDirectory = directory.path;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file_testing/file_testing.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
|
||||
@@ -117,4 +118,27 @@ void main() {
|
||||
|
||||
expect(result.exitCode, 1);
|
||||
});
|
||||
|
||||
testWithoutContext('--analyze-size allows overriding the directory for code size files', () async {
|
||||
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
|
||||
final Directory tempDir = fileSystem.systemTempDirectory.createTempSync('size_test');
|
||||
|
||||
final ProcessResult result = await processManager.run(<String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'build',
|
||||
'apk',
|
||||
'--analyze-size',
|
||||
'--code-size-directory=${tempDir.path}',
|
||||
'--target-platform=android-arm64',
|
||||
'--release',
|
||||
], workingDirectory: fileSystem.path.join(getFlutterRoot(), 'examples', 'hello_world'));
|
||||
|
||||
expect(result.exitCode, 0);
|
||||
expect(tempDir.existsSync(), true);
|
||||
expect(tempDir.childFile('snapshot.arm64-v8a.json').existsSync(), true);
|
||||
expect(tempDir.childFile('trace.arm64-v8a.json').existsSync(), true);
|
||||
|
||||
tempDir.deleteSync(recursive: true);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ void test(String description, FutureOr<void> Function() body, {
|
||||
|
||||
/// Executes a test body in zone that does not allow context-based injection.
|
||||
///
|
||||
/// For classes which have been refactored to excluded context-based injection
|
||||
/// For classes which have been refactored to exclude context-based injection
|
||||
/// or globals like [fs] or [platform], prefer using this test method as it
|
||||
/// will prevent accidentally including these context getters in future code
|
||||
/// changes.
|
||||
|
||||
Reference in New Issue
Block a user