Add hidden options --extra-front-end-options and --extra-gen-snapshot-options to flutter tool (#12219)
This CL introduces 2 hidden options to 'flutter build aot' and 'flutter run' for passing arbitrary arguments to front-end server and to gen_snapshot tool when building and running flutter app in --profile or --release modes. The ability to pass arbitrary options simplifies various experiments, as it removes the need to change defaults and rebuild flutter engine for every tested configuration.
This commit is contained in:
parent
528d28ba03
commit
7153dea296
@ -227,6 +227,15 @@ class FlutterPlugin implements Plugin<Project> {
|
|||||||
previewDart2Value = project.property('preview-dart-2')
|
previewDart2Value = project.property('preview-dart-2')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String extraFrontEndOptionsValue = null
|
||||||
|
if (project.hasProperty('extra-front-end-options')) {
|
||||||
|
extraFrontEndOptionsValue = project.property('extra-front-end-options')
|
||||||
|
}
|
||||||
|
String extraGenSnapshotOptionsValue = null
|
||||||
|
if (project.hasProperty('extra-gen-snapshot-options')) {
|
||||||
|
extraGenSnapshotOptionsValue = project.property('extra-gen-snapshot-options')
|
||||||
|
}
|
||||||
|
|
||||||
project.android.applicationVariants.all { variant ->
|
project.android.applicationVariants.all { variant ->
|
||||||
String flutterBuildMode = buildModeFor(variant.buildType)
|
String flutterBuildMode = buildModeFor(variant.buildType)
|
||||||
if (flutterBuildMode == 'debug' && project.tasks.findByName('flutterBuildX86Jar')) {
|
if (flutterBuildMode == 'debug' && project.tasks.findByName('flutterBuildX86Jar')) {
|
||||||
@ -259,6 +268,8 @@ class FlutterPlugin implements Plugin<Project> {
|
|||||||
previewDart2 previewDart2Value
|
previewDart2 previewDart2Value
|
||||||
sourceDir project.file(project.flutter.source)
|
sourceDir project.file(project.flutter.source)
|
||||||
intermediateDir project.file("${project.buildDir}/${AndroidProject.FD_INTERMEDIATES}/flutter/${variant.name}")
|
intermediateDir project.file("${project.buildDir}/${AndroidProject.FD_INTERMEDIATES}/flutter/${variant.name}")
|
||||||
|
extraFrontEndOptions extraFrontEndOptionsValue
|
||||||
|
extraGenSnapshotOptions extraGenSnapshotOptionsValue
|
||||||
}
|
}
|
||||||
|
|
||||||
Task copyFlxTask = project.tasks.create(name: "copyFlutterAssets${variant.name.capitalize()}", type: Copy) {
|
Task copyFlxTask = project.tasks.create(name: "copyFlutterAssets${variant.name.capitalize()}", type: Copy) {
|
||||||
@ -285,10 +296,14 @@ abstract class BaseFlutterTask extends DefaultTask {
|
|||||||
String localEngineSrcPath
|
String localEngineSrcPath
|
||||||
@Input
|
@Input
|
||||||
String targetPath
|
String targetPath
|
||||||
@Optional
|
@Optional @Input
|
||||||
Boolean previewDart2
|
Boolean previewDart2
|
||||||
File sourceDir
|
File sourceDir
|
||||||
File intermediateDir
|
File intermediateDir
|
||||||
|
@Optional @Input
|
||||||
|
String extraFrontEndOptions
|
||||||
|
@Optional @Input
|
||||||
|
String extraGenSnapshotOptions
|
||||||
|
|
||||||
@OutputFile
|
@OutputFile
|
||||||
File getDependenciesFile() {
|
File getDependenciesFile() {
|
||||||
@ -322,6 +337,12 @@ abstract class BaseFlutterTask extends DefaultTask {
|
|||||||
if (previewDart2) {
|
if (previewDart2) {
|
||||||
args "--preview-dart-2"
|
args "--preview-dart-2"
|
||||||
}
|
}
|
||||||
|
if (extraFrontEndOptions != null) {
|
||||||
|
args "--extra-front-end-options", "${extraFrontEndOptions}"
|
||||||
|
}
|
||||||
|
if (extraGenSnapshotOptions != null) {
|
||||||
|
args "--extra-gen-snapshot-options", "${extraGenSnapshotOptions}"
|
||||||
|
}
|
||||||
args "--${buildMode}"
|
args "--${buildMode}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -291,6 +291,10 @@ Future<Null> _buildGradleProjectV2(String gradle, BuildInfo buildInfo, String ta
|
|||||||
}
|
}
|
||||||
if (buildInfo.previewDart2)
|
if (buildInfo.previewDart2)
|
||||||
command.add('-Ppreview-dart-2=true');
|
command.add('-Ppreview-dart-2=true');
|
||||||
|
if (buildInfo.extraFrontEndOptions != null)
|
||||||
|
command.add('-Pextra-front-end-options=${buildInfo.extraFrontEndOptions}');
|
||||||
|
if (buildInfo.extraGenSnapshotOptions != null)
|
||||||
|
command.add('-Pextra-gen-snapshot-options=${buildInfo.extraGenSnapshotOptions}');
|
||||||
command.add(assembleTask);
|
command.add(assembleTask);
|
||||||
final int exitCode = await runCommandAndStreamOutput(
|
final int exitCode = await runCommandAndStreamOutput(
|
||||||
command,
|
command,
|
||||||
|
@ -10,7 +10,10 @@ import 'globals.dart';
|
|||||||
|
|
||||||
/// Information about a build to be performed or used.
|
/// Information about a build to be performed or used.
|
||||||
class BuildInfo {
|
class BuildInfo {
|
||||||
const BuildInfo(this.mode, this.flavor, { this.previewDart2 });
|
const BuildInfo(this.mode, this.flavor,
|
||||||
|
{this.previewDart2,
|
||||||
|
this.extraFrontEndOptions,
|
||||||
|
this.extraGenSnapshotOptions});
|
||||||
|
|
||||||
final BuildMode mode;
|
final BuildMode mode;
|
||||||
/// Represents a custom Android product flavor or an Xcode scheme, null for
|
/// Represents a custom Android product flavor or an Xcode scheme, null for
|
||||||
@ -24,6 +27,12 @@ class BuildInfo {
|
|||||||
// Whether build should be done using Dart2 Frontend parser.
|
// Whether build should be done using Dart2 Frontend parser.
|
||||||
final bool previewDart2;
|
final bool previewDart2;
|
||||||
|
|
||||||
|
/// Extra command-line options for front-end.
|
||||||
|
final String extraFrontEndOptions;
|
||||||
|
|
||||||
|
/// Extra command-line options for gen_snapshot.
|
||||||
|
final String extraGenSnapshotOptions;
|
||||||
|
|
||||||
static const BuildInfo debug = const BuildInfo(BuildMode.debug, null);
|
static const BuildInfo debug = const BuildInfo(BuildMode.debug, null);
|
||||||
static const BuildInfo profile = const BuildInfo(BuildMode.profile, null);
|
static const BuildInfo profile = const BuildInfo(BuildMode.profile, null);
|
||||||
static const BuildInfo release = const BuildInfo(BuildMode.release, null);
|
static const BuildInfo release = const BuildInfo(BuildMode.release, null);
|
||||||
|
@ -17,6 +17,7 @@ import '../compile.dart';
|
|||||||
import '../dart/package_map.dart';
|
import '../dart/package_map.dart';
|
||||||
import '../globals.dart';
|
import '../globals.dart';
|
||||||
import '../resident_runner.dart';
|
import '../resident_runner.dart';
|
||||||
|
import '../runner/flutter_command.dart';
|
||||||
import 'build.dart';
|
import 'build.dart';
|
||||||
|
|
||||||
// Files generated by the ahead-of-time snapshot builder.
|
// Files generated by the ahead-of-time snapshot builder.
|
||||||
@ -37,7 +38,17 @@ class BuildAotCommand extends BuildSubCommand {
|
|||||||
)
|
)
|
||||||
..addFlag('interpreter')
|
..addFlag('interpreter')
|
||||||
..addFlag('quiet', defaultsTo: false)
|
..addFlag('quiet', defaultsTo: false)
|
||||||
..addFlag('preview-dart-2', negatable: false);
|
..addFlag('preview-dart-2', negatable: false)
|
||||||
|
..addOption(FlutterOptions.kExtraFrontEndOptions,
|
||||||
|
allowMultiple: true,
|
||||||
|
splitCommas: true,
|
||||||
|
hide: true,
|
||||||
|
)
|
||||||
|
..addOption(FlutterOptions.kExtraGenSnapshotOptions,
|
||||||
|
allowMultiple: true,
|
||||||
|
splitCommas: true,
|
||||||
|
hide: true,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -67,6 +78,8 @@ class BuildAotCommand extends BuildSubCommand {
|
|||||||
outputPath: argResults['output-dir'],
|
outputPath: argResults['output-dir'],
|
||||||
interpreter: argResults['interpreter'],
|
interpreter: argResults['interpreter'],
|
||||||
previewDart2: argResults['preview-dart-2'],
|
previewDart2: argResults['preview-dart-2'],
|
||||||
|
extraFrontEndOptions: argResults[FlutterOptions.kExtraFrontEndOptions],
|
||||||
|
extraGenSnapshotOptions: argResults[FlutterOptions.kExtraGenSnapshotOptions],
|
||||||
);
|
);
|
||||||
status?.stop();
|
status?.stop();
|
||||||
|
|
||||||
@ -95,6 +108,8 @@ Future<String> buildAotSnapshot(
|
|||||||
String outputPath,
|
String outputPath,
|
||||||
bool interpreter: false,
|
bool interpreter: false,
|
||||||
bool previewDart2: false,
|
bool previewDart2: false,
|
||||||
|
List<String> extraFrontEndOptions,
|
||||||
|
List<String> extraGenSnapshotOptions,
|
||||||
}) async {
|
}) async {
|
||||||
outputPath ??= getAotBuildDirectory();
|
outputPath ??= getAotBuildDirectory();
|
||||||
try {
|
try {
|
||||||
@ -105,6 +120,8 @@ Future<String> buildAotSnapshot(
|
|||||||
outputPath: outputPath,
|
outputPath: outputPath,
|
||||||
interpreter: interpreter,
|
interpreter: interpreter,
|
||||||
previewDart2: previewDart2,
|
previewDart2: previewDart2,
|
||||||
|
extraFrontEndOptions: extraFrontEndOptions,
|
||||||
|
extraGenSnapshotOptions: extraGenSnapshotOptions,
|
||||||
);
|
);
|
||||||
} on String catch (error) {
|
} on String catch (error) {
|
||||||
// Catch the String exceptions thrown from the `runCheckedSync` methods below.
|
// Catch the String exceptions thrown from the `runCheckedSync` methods below.
|
||||||
@ -121,6 +138,8 @@ Future<String> _buildAotSnapshot(
|
|||||||
String outputPath,
|
String outputPath,
|
||||||
bool interpreter: false,
|
bool interpreter: false,
|
||||||
bool previewDart2: false,
|
bool previewDart2: false,
|
||||||
|
List<String> extraFrontEndOptions,
|
||||||
|
List<String> extraGenSnapshotOptions,
|
||||||
}) async {
|
}) async {
|
||||||
outputPath ??= getAotBuildDirectory();
|
outputPath ??= getAotBuildDirectory();
|
||||||
if (!isAotBuildMode(buildMode) && !interpreter) {
|
if (!isAotBuildMode(buildMode) && !interpreter) {
|
||||||
@ -220,6 +239,14 @@ Future<String> _buildAotSnapshot(
|
|||||||
'--causal_async_stacks',
|
'--causal_async_stacks',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if ((extraFrontEndOptions != null) && extraFrontEndOptions.isNotEmpty)
|
||||||
|
printTrace("Extra front-end options: $extraFrontEndOptions");
|
||||||
|
|
||||||
|
if ((extraGenSnapshotOptions != null) && extraGenSnapshotOptions.isNotEmpty) {
|
||||||
|
printTrace("Extra gen-snapshot options: $extraGenSnapshotOptions");
|
||||||
|
genSnapshotCmd.addAll(extraGenSnapshotOptions);
|
||||||
|
}
|
||||||
|
|
||||||
if (!interpreter) {
|
if (!interpreter) {
|
||||||
genSnapshotCmd.add('--embedder_entry_points_manifest=$vmEntryPoints');
|
genSnapshotCmd.add('--embedder_entry_points_manifest=$vmEntryPoints');
|
||||||
genSnapshotCmd.add('--embedder_entry_points_manifest=$ioEntryPoints');
|
genSnapshotCmd.add('--embedder_entry_points_manifest=$ioEntryPoints');
|
||||||
@ -280,6 +307,7 @@ Future<String> _buildAotSnapshot(
|
|||||||
mainPath = await compile(
|
mainPath = await compile(
|
||||||
sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
|
sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
|
||||||
mainPath: mainPath,
|
mainPath: mainPath,
|
||||||
|
extraFrontEndOptions: extraFrontEndOptions,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,6 +155,9 @@ class RunCommand extends RunCommandBase {
|
|||||||
'measure the startup time and the app restart time, write the\n'
|
'measure the startup time and the app restart time, write the\n'
|
||||||
'results out to "refresh_benchmark.json", and exit. This flag is\n'
|
'results out to "refresh_benchmark.json", and exit. This flag is\n'
|
||||||
'intended for use in generating automated flutter benchmarks.');
|
'intended for use in generating automated flutter benchmarks.');
|
||||||
|
|
||||||
|
argParser.addOption(FlutterOptions.kExtraFrontEndOptions, hide: true);
|
||||||
|
argParser.addOption(FlutterOptions.kExtraGenSnapshotOptions, hide: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Device> devices;
|
List<Device> devices;
|
||||||
|
@ -56,7 +56,10 @@ class _StdoutHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> compile({String sdkRoot, String mainPath}) async {
|
Future<String> compile(
|
||||||
|
{String sdkRoot,
|
||||||
|
String mainPath,
|
||||||
|
List<String> extraFrontEndOptions}) async {
|
||||||
final String frontendServer = artifacts.getArtifactPath(
|
final String frontendServer = artifacts.getArtifactPath(
|
||||||
Artifact.frontendServerSnapshotForEngineDartSdk
|
Artifact.frontendServerSnapshotForEngineDartSdk
|
||||||
);
|
);
|
||||||
@ -64,13 +67,18 @@ Future<String> compile({String sdkRoot, String mainPath}) async {
|
|||||||
// This is a URI, not a file path, so the forward slash is correct even on Windows.
|
// This is a URI, not a file path, so the forward slash is correct even on Windows.
|
||||||
if (!sdkRoot.endsWith('/'))
|
if (!sdkRoot.endsWith('/'))
|
||||||
sdkRoot = '$sdkRoot/';
|
sdkRoot = '$sdkRoot/';
|
||||||
final Process server = await processManager.start(<String>[
|
final List<String> command = <String>[
|
||||||
_dartExecutable(),
|
_dartExecutable(),
|
||||||
frontendServer,
|
frontendServer,
|
||||||
'--sdk-root',
|
'--sdk-root',
|
||||||
sdkRoot,
|
sdkRoot,
|
||||||
mainPath
|
];
|
||||||
]).catchError((dynamic error, StackTrace stack) {
|
if (extraFrontEndOptions != null)
|
||||||
|
command.addAll(extraFrontEndOptions);
|
||||||
|
command.add(mainPath);
|
||||||
|
final Process server = await processManager
|
||||||
|
.start(command)
|
||||||
|
.catchError((dynamic error, StackTrace stack) {
|
||||||
printTrace('Failed to start frontend server $error, $stack');
|
printTrace('Failed to start frontend server $error, $stack');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -54,6 +54,12 @@ class FlutterCommandResult {
|
|||||||
final DateTime endTimeOverride;
|
final DateTime endTimeOverride;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Common flutter command line options.
|
||||||
|
class FlutterOptions {
|
||||||
|
static const String kExtraFrontEndOptions = 'extra-front-end-options';
|
||||||
|
static const String kExtraGenSnapshotOptions = 'extra-gen-snapshot-options';
|
||||||
|
}
|
||||||
|
|
||||||
abstract class FlutterCommand extends Command<Null> {
|
abstract class FlutterCommand extends Command<Null> {
|
||||||
@override
|
@override
|
||||||
FlutterCommandRunner get runner => super.runner;
|
FlutterCommandRunner get runner => super.runner;
|
||||||
@ -149,7 +155,13 @@ abstract class FlutterCommand extends Command<Null> {
|
|||||||
: null,
|
: null,
|
||||||
previewDart2: argParser.options.containsKey('preview-dart-2')
|
previewDart2: argParser.options.containsKey('preview-dart-2')
|
||||||
? argResults['preview-dart-2']
|
? argResults['preview-dart-2']
|
||||||
: false);
|
: false,
|
||||||
|
extraFrontEndOptions: argParser.options.containsKey(FlutterOptions.kExtraFrontEndOptions)
|
||||||
|
? argResults[FlutterOptions.kExtraFrontEndOptions]
|
||||||
|
: null,
|
||||||
|
extraGenSnapshotOptions: argParser.options.containsKey(FlutterOptions.kExtraGenSnapshotOptions)
|
||||||
|
? argResults[FlutterOptions.kExtraGenSnapshotOptions]
|
||||||
|
: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupApplicationPackages() {
|
void setupApplicationPackages() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user