Allow passing --initialize-from-dill
to flutter run and flutter attach (#83454)
To specify the dill file that will be used to initialize the resident compiler, instead of the default cached version.
This commit is contained in:
parent
a96e763155
commit
a9d6131df8
@ -41,6 +41,7 @@ class BuildInfo {
|
||||
this.codeSizeDirectory,
|
||||
this.androidGradleDaemon = true,
|
||||
this.packageConfig = PackageConfig.empty,
|
||||
this.initializeFromDill,
|
||||
}) : extraFrontEndOptions = extraFrontEndOptions ?? const <String>[],
|
||||
extraGenSnapshotOptions = extraGenSnapshotOptions ?? const <String>[],
|
||||
fileSystemRoots = fileSystemRoots ?? const <String>[],
|
||||
@ -153,6 +154,11 @@ class BuildInfo {
|
||||
/// may change during a 'flutter run` workflow.
|
||||
final PackageConfig packageConfig;
|
||||
|
||||
/// The kernel file that the resident compiler will be initialized with.
|
||||
///
|
||||
/// If this is null, it will be initialized from the default cached location.
|
||||
final String? initializeFromDill;
|
||||
|
||||
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);
|
||||
|
@ -70,6 +70,7 @@ class AttachCommand extends FlutterCommand {
|
||||
usesDeviceUserOption();
|
||||
addEnableExperimentation(hide: !verboseHelp);
|
||||
addNullSafetyModeOptions(hide: !verboseHelp);
|
||||
usesInitializeFromDillOption(hide: !verboseHelp);
|
||||
argParser
|
||||
..addOption(
|
||||
'debug-port',
|
||||
|
@ -236,6 +236,7 @@ class RunCommand extends RunCommandBase {
|
||||
usesFilesystemOptions(hide: !verboseHelp);
|
||||
usesExtraDartFlagOptions(verboseHelp: verboseHelp);
|
||||
addEnableExperimentation(hide: !verboseHelp);
|
||||
usesInitializeFromDillOption(hide: !verboseHelp);
|
||||
|
||||
// By default, the app should to publish the VM service port over mDNS.
|
||||
// This will allow subsequent "flutter attach" commands to connect to the VM
|
||||
|
@ -125,7 +125,7 @@ class FlutterDevice {
|
||||
// Override the filesystem scheme so that the frontend_server can find
|
||||
// the generated entrypoint code.
|
||||
fileSystemScheme: 'org-dartlang-app',
|
||||
initializeFromDill: getDefaultCachedKernelPath(
|
||||
initializeFromDill: buildInfo.initializeFromDill ?? getDefaultCachedKernelPath(
|
||||
trackWidgetCreation: buildInfo.trackWidgetCreation,
|
||||
dartDefines: buildInfo.dartDefines,
|
||||
extraFrontEndOptions: extraFrontEndOptions,
|
||||
@ -168,7 +168,7 @@ class FlutterDevice {
|
||||
targetModel: targetModel,
|
||||
dartDefines: buildInfo.dartDefines,
|
||||
extraFrontEndOptions: extraFrontEndOptions,
|
||||
initializeFromDill: getDefaultCachedKernelPath(
|
||||
initializeFromDill: buildInfo.initializeFromDill ?? getDefaultCachedKernelPath(
|
||||
trackWidgetCreation: buildInfo.trackWidgetCreation,
|
||||
dartDefines: buildInfo.dartDefines,
|
||||
extraFrontEndOptions: extraFrontEndOptions,
|
||||
|
@ -119,6 +119,7 @@ class FlutterOptions {
|
||||
static const String kAndroidGradleDaemon = 'android-gradle-daemon';
|
||||
static const String kDeferredComponents = 'deferred-components';
|
||||
static const String kAndroidProjectArgs = 'android-project-arg';
|
||||
static const String kInitializeFromDill = 'initialize-from-dill';
|
||||
}
|
||||
|
||||
abstract class FlutterCommand extends Command<void> {
|
||||
@ -807,6 +808,14 @@ abstract class FlutterCommand extends Command<void> {
|
||||
);
|
||||
}
|
||||
|
||||
void usesInitializeFromDillOption({ @required bool hide }) {
|
||||
argParser.addOption(FlutterOptions.kInitializeFromDill,
|
||||
help: 'Initializes the resident compiler with a specific kernel file instead of '
|
||||
'the default cached location.',
|
||||
hide: hide,
|
||||
);
|
||||
}
|
||||
|
||||
/// Adds build options common to all of the desktop build commands.
|
||||
void addCommonDesktopBuildOptions({ @required bool verboseHelp }) {
|
||||
addBuildModeFlags(verboseHelp: verboseHelp);
|
||||
@ -1067,6 +1076,9 @@ abstract class FlutterCommand extends Command<void> {
|
||||
androidGradleDaemon: androidGradleDaemon,
|
||||
packageConfig: packageConfig,
|
||||
androidProjectArgs: androidProjectArgs,
|
||||
initializeFromDill: argParser.options.containsKey(FlutterOptions.kInitializeFromDill)
|
||||
? stringArg(FlutterOptions.kInitializeFromDill)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -2189,6 +2189,29 @@ void main() {
|
||||
FeatureFlags: () => TestFeatureFlags(isExperimentalInvalidationStrategyEnabled: true)
|
||||
});
|
||||
|
||||
testUsingContext('FlutterDevice passes initializeFromDill parameter if specified', () async {
|
||||
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
|
||||
final FakeDevice mockDevice = FakeDevice(targetPlatform: TargetPlatform.android_arm);
|
||||
|
||||
final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create(
|
||||
mockDevice,
|
||||
buildInfo: const BuildInfo(
|
||||
BuildMode.debug,
|
||||
'',
|
||||
treeShakeIcons: false,
|
||||
extraFrontEndOptions: <String>[],
|
||||
initializeFromDill: '/foo/bar.dill',
|
||||
),
|
||||
target: null, platform: null,
|
||||
)).generator as DefaultResidentCompiler;
|
||||
|
||||
expect(residentCompiler.initializeFromDill, '/foo/bar.dill');
|
||||
}, overrides: <Type, Generator>{
|
||||
Artifacts: () => Artifacts.test(),
|
||||
FileSystem: () => MemoryFileSystem.test(),
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
|
||||
testUsingContext('Handle existing VM service clients DDS error', () => testbed.run(() async {
|
||||
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
|
||||
final FakeDevice mockDevice = FakeDevice()
|
||||
|
@ -521,6 +521,14 @@ void main() {
|
||||
expect(buildInfo.fileSystemRoots, <String>['foo', 'bar']);
|
||||
});
|
||||
|
||||
testUsingContext('includes initializeFromDill in BuildInfo', () async {
|
||||
final DummyFlutterCommand flutterCommand = DummyFlutterCommand()..usesInitializeFromDillOption(hide: false);
|
||||
final CommandRunner<void> runner = createTestCommandRunner(flutterCommand);
|
||||
await runner.run(<String>['dummy', '--initialize-from-dill=/foo/bar.dill']);
|
||||
final BuildInfo buildInfo = await flutterCommand.getBuildInfo(forcedBuildMode: BuildMode.debug);
|
||||
expect(buildInfo.initializeFromDill, '/foo/bar.dill');
|
||||
});
|
||||
|
||||
testUsingContext('dds options', () async {
|
||||
final FakeDdsCommand ddsCommand = FakeDdsCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(ddsCommand);
|
||||
|
Loading…
x
Reference in New Issue
Block a user