Add --frontend-server-starter-path option to flutter run and flutter test (#135038)
This commit is contained in:
@@ -23,6 +23,7 @@ class BuildInfo {
|
||||
this.mode,
|
||||
this.flavor, {
|
||||
this.trackWidgetCreation = false,
|
||||
this.frontendServerStarterPath,
|
||||
List<String>? extraFrontEndOptions,
|
||||
List<String>? extraGenSnapshotOptions,
|
||||
List<String>? fileSystemRoots,
|
||||
@@ -82,6 +83,10 @@ class BuildInfo {
|
||||
/// Whether the build should track widget creation locations.
|
||||
final bool trackWidgetCreation;
|
||||
|
||||
/// If provided, the frontend server will be started in JIT mode from this
|
||||
/// file.
|
||||
final String? frontendServerStarterPath;
|
||||
|
||||
/// Extra command-line options for front-end.
|
||||
final List<String> extraFrontEndOptions;
|
||||
|
||||
@@ -237,6 +242,8 @@ class BuildInfo {
|
||||
if (dartDefines.isNotEmpty)
|
||||
kDartDefines: encodeDartDefines(dartDefines),
|
||||
kDartObfuscation: dartObfuscation.toString(),
|
||||
if (frontendServerStarterPath != null)
|
||||
kFrontendServerStarterPath: frontendServerStarterPath!,
|
||||
if (extraFrontEndOptions.isNotEmpty)
|
||||
kExtraFrontEndOptions: extraFrontEndOptions.join(','),
|
||||
if (extraGenSnapshotOptions.isNotEmpty)
|
||||
@@ -274,6 +281,8 @@ class BuildInfo {
|
||||
if (dartDefines.isNotEmpty)
|
||||
'DART_DEFINES': encodeDartDefines(dartDefines),
|
||||
'DART_OBFUSCATION': dartObfuscation.toString(),
|
||||
if (frontendServerStarterPath != null)
|
||||
'FRONTEND_SERVER_STARTER_PATH': frontendServerStarterPath!,
|
||||
if (extraFrontEndOptions.isNotEmpty)
|
||||
'EXTRA_FRONT_END_OPTIONS': extraFrontEndOptions.join(','),
|
||||
if (extraGenSnapshotOptions.isNotEmpty)
|
||||
@@ -310,6 +319,8 @@ class BuildInfo {
|
||||
if (dartDefines.isNotEmpty)
|
||||
'-Pdart-defines=${encodeDartDefines(dartDefines)}',
|
||||
'-Pdart-obfuscation=$dartObfuscation',
|
||||
if (frontendServerStarterPath != null)
|
||||
'-Pfrontend-server-starter-path=$frontendServerStarterPath',
|
||||
if (extraFrontEndOptions.isNotEmpty)
|
||||
'-Pextra-front-end-options=${extraFrontEndOptions.join(',')}',
|
||||
if (extraGenSnapshotOptions.isNotEmpty)
|
||||
@@ -901,6 +912,9 @@ const String kTargetFile = 'TargetFile';
|
||||
/// Whether to enable or disable track widget creation.
|
||||
const String kTrackWidgetCreation = 'TrackWidgetCreation';
|
||||
|
||||
/// If provided, the frontend server will be started in JIT mode from this file.
|
||||
const String kFrontendServerStarterPath = 'FrontendServerStarterPath';
|
||||
|
||||
/// Additional configuration passed to the dart front end.
|
||||
///
|
||||
/// This is expected to be a comma separated list of strings.
|
||||
|
||||
@@ -178,6 +178,7 @@ class KernelSnapshot extends Target {
|
||||
final TargetPlatform targetPlatform = getTargetPlatformForName(targetPlatformEnvironment);
|
||||
|
||||
// This configuration is all optional.
|
||||
final String? frontendServerStarterPath = environment.defines[kFrontendServerStarterPath];
|
||||
final List<String> extraFrontEndOptions = decodeCommaSeparated(environment.defines, kExtraFrontEndOptions);
|
||||
final List<String>? fileSystemRoots = environment.defines[kFileSystemRoots]?.split(',');
|
||||
final String? fileSystemScheme = environment.defines[kFileSystemScheme];
|
||||
@@ -254,6 +255,7 @@ class KernelSnapshot extends Target {
|
||||
linkPlatformKernelIn: forceLinkPlatform || buildMode.isPrecompiled,
|
||||
mainPath: targetFileAbsolute,
|
||||
depFilePath: environment.buildDir.childFile('kernel_snapshot.d').path,
|
||||
frontendServerStarterPath: frontendServerStarterPath,
|
||||
extraFrontEndOptions: extraFrontEndOptions,
|
||||
fileSystemRoots: fileSystemRoots,
|
||||
fileSystemScheme: fileSystemScheme,
|
||||
|
||||
@@ -315,6 +315,7 @@ class RunCommand extends RunCommandBase {
|
||||
requiresPubspecYaml();
|
||||
usesFilesystemOptions(hide: !verboseHelp);
|
||||
usesExtraDartFlagOptions(verboseHelp: verboseHelp);
|
||||
usesFrontendServerStarterPathOption(verboseHelp: verboseHelp);
|
||||
addEnableExperimentation(hide: !verboseHelp);
|
||||
usesInitializeFromDillOption(hide: !verboseHelp);
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
|
||||
requiresPubspecYaml();
|
||||
usesPubOption();
|
||||
addNullSafetyModeOptions(hide: !verboseHelp);
|
||||
usesFrontendServerStarterPathOption(verboseHelp: verboseHelp);
|
||||
usesTrackWidgetCreation(verboseHelp: verboseHelp);
|
||||
addEnableExperimentation(hide: !verboseHelp);
|
||||
usesDartDefineOption();
|
||||
|
||||
@@ -227,6 +227,7 @@ class KernelCompiler {
|
||||
TargetModel targetModel = TargetModel.flutter,
|
||||
bool linkPlatformKernelIn = false,
|
||||
bool aot = false,
|
||||
String? frontendServerStarterPath,
|
||||
List<String>? extraFrontEndOptions,
|
||||
List<String>? fileSystemRoots,
|
||||
String? fileSystemScheme,
|
||||
@@ -243,10 +244,12 @@ class KernelCompiler {
|
||||
String? nativeAssets,
|
||||
}) async {
|
||||
final TargetPlatform? platform = targetModel == TargetModel.dartdevc ? TargetPlatform.web_javascript : null;
|
||||
final String frontendServer = _artifacts.getArtifactPath(
|
||||
Artifact.frontendServerSnapshotForEngineDartSdk,
|
||||
platform: platform,
|
||||
);
|
||||
final String frontendServer = (frontendServerStarterPath == null || frontendServerStarterPath.isEmpty)
|
||||
? _artifacts.getArtifactPath(
|
||||
Artifact.frontendServerSnapshotForEngineDartSdk,
|
||||
platform: platform,
|
||||
)
|
||||
: frontendServerStarterPath;
|
||||
// This is a URI, not a file path, so the forward slash is correct even on Windows.
|
||||
if (!sdkRoot.endsWith('/')) {
|
||||
sdkRoot = '$sdkRoot/';
|
||||
@@ -490,6 +493,7 @@ abstract class ResidentCompiler {
|
||||
bool assumeInitializeFromDillUpToDate,
|
||||
TargetModel targetModel,
|
||||
bool unsafePackageSerialization,
|
||||
String? frontendServerStarterPath,
|
||||
List<String> extraFrontEndOptions,
|
||||
String platformDill,
|
||||
List<String>? dartDefines,
|
||||
@@ -605,6 +609,7 @@ class DefaultResidentCompiler implements ResidentCompiler {
|
||||
this.assumeInitializeFromDillUpToDate = false,
|
||||
this.targetModel = TargetModel.flutter,
|
||||
this.unsafePackageSerialization = false,
|
||||
this.frontendServerStarterPath,
|
||||
this.extraFrontEndOptions,
|
||||
this.platformDill,
|
||||
List<String>? dartDefines,
|
||||
@@ -635,6 +640,7 @@ class DefaultResidentCompiler implements ResidentCompiler {
|
||||
final String? initializeFromDill;
|
||||
final bool assumeInitializeFromDillUpToDate;
|
||||
final bool unsafePackageSerialization;
|
||||
final String? frontendServerStarterPath;
|
||||
final List<String>? extraFrontEndOptions;
|
||||
final List<String> dartDefines;
|
||||
final String? librariesSpec;
|
||||
@@ -771,10 +777,12 @@ class DefaultResidentCompiler implements ResidentCompiler {
|
||||
String? nativeAssetsUri,
|
||||
}) async {
|
||||
final TargetPlatform? platform = (targetModel == TargetModel.dartdevc) ? TargetPlatform.web_javascript : null;
|
||||
final String frontendServer = artifacts.getArtifactPath(
|
||||
Artifact.frontendServerSnapshotForEngineDartSdk,
|
||||
platform: platform,
|
||||
);
|
||||
final String frontendServer = (frontendServerStarterPath == null || frontendServerStarterPath!.isEmpty)
|
||||
? artifacts.getArtifactPath(
|
||||
Artifact.frontendServerSnapshotForEngineDartSdk,
|
||||
platform: platform,
|
||||
)
|
||||
: frontendServerStarterPath!;
|
||||
final List<String> command = <String>[
|
||||
artifacts.getArtifactPath(Artifact.engineDartBinary, platform: platform),
|
||||
'--disable-dart-dev',
|
||||
|
||||
@@ -67,6 +67,7 @@ class FlutterDevice {
|
||||
targetModel: targetModel,
|
||||
dartDefines: buildInfo.dartDefines,
|
||||
packagesPath: buildInfo.packagesPath,
|
||||
frontendServerStarterPath: buildInfo.frontendServerStarterPath,
|
||||
extraFrontEndOptions: buildInfo.extraFrontEndOptions,
|
||||
artifacts: globals.artifacts!,
|
||||
processManager: globals.processManager,
|
||||
@@ -155,6 +156,7 @@ class FlutterDevice {
|
||||
),
|
||||
assumeInitializeFromDillUpToDate: buildInfo.assumeInitializeFromDillUpToDate,
|
||||
targetModel: TargetModel.dartdevc,
|
||||
frontendServerStarterPath: buildInfo.frontendServerStarterPath,
|
||||
extraFrontEndOptions: extraFrontEndOptions,
|
||||
platformDill: globals.fs.file(platformDillPath).absolute.uri.toString(),
|
||||
dartDefines: buildInfo.dartDefines,
|
||||
@@ -185,6 +187,7 @@ class FlutterDevice {
|
||||
fileSystemScheme: buildInfo.fileSystemScheme,
|
||||
targetModel: targetModel,
|
||||
dartDefines: buildInfo.dartDefines,
|
||||
frontendServerStarterPath: buildInfo.frontendServerStarterPath,
|
||||
extraFrontEndOptions: extraFrontEndOptions,
|
||||
initializeFromDill: buildInfo.initializeFromDill ?? getDefaultCachedKernelPath(
|
||||
trackWidgetCreation: buildInfo.trackWidgetCreation,
|
||||
|
||||
@@ -112,6 +112,7 @@ class FlutterCommandResult {
|
||||
|
||||
/// Common flutter command line options.
|
||||
abstract final class FlutterOptions {
|
||||
static const String kFrontendServerStarterPath = 'frontend-server-starter-path';
|
||||
static const String kExtraFrontEndOptions = 'extra-front-end-options';
|
||||
static const String kExtraGenSnapshotOptions = 'extra-gen-snapshot-options';
|
||||
static const String kEnableExperiment = 'enable-experiment';
|
||||
@@ -849,6 +850,18 @@ abstract class FlutterCommand extends Command<void> {
|
||||
);
|
||||
}
|
||||
|
||||
void usesFrontendServerStarterPathOption({required bool verboseHelp}) {
|
||||
argParser.addOption(
|
||||
FlutterOptions.kFrontendServerStarterPath,
|
||||
help: 'When this value is provided, the frontend server will be started '
|
||||
'in JIT mode from the specified file, instead of from the AOT '
|
||||
'snapshot shipped with the Dart SDK. The specified file can either '
|
||||
'be a Dart source file, or an AppJIT snapshot. This option does '
|
||||
'not affect web builds.',
|
||||
hide: !verboseHelp,
|
||||
);
|
||||
}
|
||||
|
||||
/// Enables support for the hidden options --extra-front-end-options and
|
||||
/// --extra-gen-snapshot-options.
|
||||
void usesExtraDartFlagOptions({ required bool verboseHelp }) {
|
||||
@@ -1239,6 +1252,10 @@ abstract class FlutterCommand extends Command<void> {
|
||||
? stringArg('flavor')
|
||||
: null,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
frontendServerStarterPath: argParser.options
|
||||
.containsKey(FlutterOptions.kFrontendServerStarterPath)
|
||||
? stringArg(FlutterOptions.kFrontendServerStarterPath)
|
||||
: null,
|
||||
extraFrontEndOptions: extraFrontEndOptions.isNotEmpty
|
||||
? extraFrontEndOptions
|
||||
: null,
|
||||
|
||||
@@ -121,6 +121,7 @@ class TestCompiler {
|
||||
initializeFromDill: testFilePath,
|
||||
dartDefines: buildInfo.dartDefines,
|
||||
packagesPath: buildInfo.packagesPath,
|
||||
frontendServerStarterPath: buildInfo.frontendServerStarterPath,
|
||||
extraFrontEndOptions: buildInfo.extraFrontEndOptions,
|
||||
platform: globals.platform,
|
||||
testCompilation: true,
|
||||
|
||||
Reference in New Issue
Block a user