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')
|
||||
}
|
||||
|
||||
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 ->
|
||||
String flutterBuildMode = buildModeFor(variant.buildType)
|
||||
if (flutterBuildMode == 'debug' && project.tasks.findByName('flutterBuildX86Jar')) {
|
||||
@ -259,6 +268,8 @@ class FlutterPlugin implements Plugin<Project> {
|
||||
previewDart2 previewDart2Value
|
||||
sourceDir project.file(project.flutter.source)
|
||||
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) {
|
||||
@ -285,10 +296,14 @@ abstract class BaseFlutterTask extends DefaultTask {
|
||||
String localEngineSrcPath
|
||||
@Input
|
||||
String targetPath
|
||||
@Optional
|
||||
@Optional @Input
|
||||
Boolean previewDart2
|
||||
File sourceDir
|
||||
File intermediateDir
|
||||
@Optional @Input
|
||||
String extraFrontEndOptions
|
||||
@Optional @Input
|
||||
String extraGenSnapshotOptions
|
||||
|
||||
@OutputFile
|
||||
File getDependenciesFile() {
|
||||
@ -322,6 +337,12 @@ abstract class BaseFlutterTask extends DefaultTask {
|
||||
if (previewDart2) {
|
||||
args "--preview-dart-2"
|
||||
}
|
||||
if (extraFrontEndOptions != null) {
|
||||
args "--extra-front-end-options", "${extraFrontEndOptions}"
|
||||
}
|
||||
if (extraGenSnapshotOptions != null) {
|
||||
args "--extra-gen-snapshot-options", "${extraGenSnapshotOptions}"
|
||||
}
|
||||
args "--${buildMode}"
|
||||
}
|
||||
}
|
||||
|
@ -291,6 +291,10 @@ Future<Null> _buildGradleProjectV2(String gradle, BuildInfo buildInfo, String ta
|
||||
}
|
||||
if (buildInfo.previewDart2)
|
||||
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);
|
||||
final int exitCode = await runCommandAndStreamOutput(
|
||||
command,
|
||||
|
@ -10,7 +10,10 @@ import 'globals.dart';
|
||||
|
||||
/// Information about a build to be performed or used.
|
||||
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;
|
||||
/// 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.
|
||||
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 profile = const BuildInfo(BuildMode.profile, null);
|
||||
static const BuildInfo release = const BuildInfo(BuildMode.release, null);
|
||||
|
@ -17,6 +17,7 @@ import '../compile.dart';
|
||||
import '../dart/package_map.dart';
|
||||
import '../globals.dart';
|
||||
import '../resident_runner.dart';
|
||||
import '../runner/flutter_command.dart';
|
||||
import 'build.dart';
|
||||
|
||||
// Files generated by the ahead-of-time snapshot builder.
|
||||
@ -37,7 +38,17 @@ class BuildAotCommand extends BuildSubCommand {
|
||||
)
|
||||
..addFlag('interpreter')
|
||||
..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
|
||||
@ -67,6 +78,8 @@ class BuildAotCommand extends BuildSubCommand {
|
||||
outputPath: argResults['output-dir'],
|
||||
interpreter: argResults['interpreter'],
|
||||
previewDart2: argResults['preview-dart-2'],
|
||||
extraFrontEndOptions: argResults[FlutterOptions.kExtraFrontEndOptions],
|
||||
extraGenSnapshotOptions: argResults[FlutterOptions.kExtraGenSnapshotOptions],
|
||||
);
|
||||
status?.stop();
|
||||
|
||||
@ -95,6 +108,8 @@ Future<String> buildAotSnapshot(
|
||||
String outputPath,
|
||||
bool interpreter: false,
|
||||
bool previewDart2: false,
|
||||
List<String> extraFrontEndOptions,
|
||||
List<String> extraGenSnapshotOptions,
|
||||
}) async {
|
||||
outputPath ??= getAotBuildDirectory();
|
||||
try {
|
||||
@ -105,6 +120,8 @@ Future<String> buildAotSnapshot(
|
||||
outputPath: outputPath,
|
||||
interpreter: interpreter,
|
||||
previewDart2: previewDart2,
|
||||
extraFrontEndOptions: extraFrontEndOptions,
|
||||
extraGenSnapshotOptions: extraGenSnapshotOptions,
|
||||
);
|
||||
} on String catch (error) {
|
||||
// Catch the String exceptions thrown from the `runCheckedSync` methods below.
|
||||
@ -121,6 +138,8 @@ Future<String> _buildAotSnapshot(
|
||||
String outputPath,
|
||||
bool interpreter: false,
|
||||
bool previewDart2: false,
|
||||
List<String> extraFrontEndOptions,
|
||||
List<String> extraGenSnapshotOptions,
|
||||
}) async {
|
||||
outputPath ??= getAotBuildDirectory();
|
||||
if (!isAotBuildMode(buildMode) && !interpreter) {
|
||||
@ -220,6 +239,14 @@ Future<String> _buildAotSnapshot(
|
||||
'--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) {
|
||||
genSnapshotCmd.add('--embedder_entry_points_manifest=$vmEntryPoints');
|
||||
genSnapshotCmd.add('--embedder_entry_points_manifest=$ioEntryPoints');
|
||||
@ -280,6 +307,7 @@ Future<String> _buildAotSnapshot(
|
||||
mainPath = await compile(
|
||||
sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
|
||||
mainPath: mainPath,
|
||||
extraFrontEndOptions: extraFrontEndOptions,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -155,6 +155,9 @@ class RunCommand extends RunCommandBase {
|
||||
'measure the startup time and the app restart time, write the\n'
|
||||
'results out to "refresh_benchmark.json", and exit. This flag is\n'
|
||||
'intended for use in generating automated flutter benchmarks.');
|
||||
|
||||
argParser.addOption(FlutterOptions.kExtraFrontEndOptions, hide: true);
|
||||
argParser.addOption(FlutterOptions.kExtraGenSnapshotOptions, hide: true);
|
||||
}
|
||||
|
||||
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(
|
||||
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.
|
||||
if (!sdkRoot.endsWith('/'))
|
||||
sdkRoot = '$sdkRoot/';
|
||||
final Process server = await processManager.start(<String>[
|
||||
final List<String> command = <String>[
|
||||
_dartExecutable(),
|
||||
frontendServer,
|
||||
'--sdk-root',
|
||||
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');
|
||||
});
|
||||
|
||||
|
@ -54,6 +54,12 @@ class FlutterCommandResult {
|
||||
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> {
|
||||
@override
|
||||
FlutterCommandRunner get runner => super.runner;
|
||||
@ -149,7 +155,13 @@ abstract class FlutterCommand extends Command<Null> {
|
||||
: null,
|
||||
previewDart2: argParser.options.containsKey('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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user