mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Allow overriding the native assets yaml file in the resident runner. (#142016)
This is used when the native assets are built by a separate build system. Context: b/286799303
This commit is contained in:
parent
f04958a11b
commit
f52eaaea08
@ -90,6 +90,7 @@ class AttachCommand extends FlutterCommand {
|
|||||||
addEnableExperimentation(hide: !verboseHelp);
|
addEnableExperimentation(hide: !verboseHelp);
|
||||||
addNullSafetyModeOptions(hide: !verboseHelp);
|
addNullSafetyModeOptions(hide: !verboseHelp);
|
||||||
usesInitializeFromDillOption(hide: !verboseHelp);
|
usesInitializeFromDillOption(hide: !verboseHelp);
|
||||||
|
usesNativeAssetsOption(hide: !verboseHelp);
|
||||||
argParser
|
argParser
|
||||||
..addOption(
|
..addOption(
|
||||||
'debug-port',
|
'debug-port',
|
||||||
@ -539,6 +540,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
|
|||||||
dillOutputPath: stringArg('output-dill'),
|
dillOutputPath: stringArg('output-dill'),
|
||||||
ipv6: usesIpv6,
|
ipv6: usesIpv6,
|
||||||
flutterProject: flutterProject,
|
flutterProject: flutterProject,
|
||||||
|
nativeAssetsYamlFile: stringArg(FlutterOptions.kNativeAssetsYamlFile),
|
||||||
analytics: analytics,
|
analytics: analytics,
|
||||||
)
|
)
|
||||||
: ColdRunner(
|
: ColdRunner(
|
||||||
@ -572,6 +574,7 @@ class HotRunnerFactory {
|
|||||||
bool stayResident = true,
|
bool stayResident = true,
|
||||||
bool ipv6 = false,
|
bool ipv6 = false,
|
||||||
FlutterProject? flutterProject,
|
FlutterProject? flutterProject,
|
||||||
|
String? nativeAssetsYamlFile,
|
||||||
required Analytics analytics,
|
required Analytics analytics,
|
||||||
}) => HotRunner(
|
}) => HotRunner(
|
||||||
devices,
|
devices,
|
||||||
@ -584,6 +587,7 @@ class HotRunnerFactory {
|
|||||||
dillOutputPath: dillOutputPath,
|
dillOutputPath: dillOutputPath,
|
||||||
stayResident: stayResident,
|
stayResident: stayResident,
|
||||||
ipv6: ipv6,
|
ipv6: ipv6,
|
||||||
|
nativeAssetsYamlFile: nativeAssetsYamlFile,
|
||||||
analytics: analytics,
|
analytics: analytics,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -331,6 +331,7 @@ class RunCommand extends RunCommandBase {
|
|||||||
usesFrontendServerStarterPathOption(verboseHelp: verboseHelp);
|
usesFrontendServerStarterPathOption(verboseHelp: verboseHelp);
|
||||||
addEnableExperimentation(hide: !verboseHelp);
|
addEnableExperimentation(hide: !verboseHelp);
|
||||||
usesInitializeFromDillOption(hide: !verboseHelp);
|
usesInitializeFromDillOption(hide: !verboseHelp);
|
||||||
|
usesNativeAssetsOption(hide: !verboseHelp);
|
||||||
|
|
||||||
// By default, the app should to publish the VM service port over mDNS.
|
// 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
|
// This will allow subsequent "flutter attach" commands to connect to the VM
|
||||||
@ -641,6 +642,7 @@ class RunCommand extends RunCommandBase {
|
|||||||
ipv6: ipv6 ?? false,
|
ipv6: ipv6 ?? false,
|
||||||
multidexEnabled: boolArg('multidex'),
|
multidexEnabled: boolArg('multidex'),
|
||||||
analytics: globals.analytics,
|
analytics: globals.analytics,
|
||||||
|
nativeAssetsYamlFile: stringArg(FlutterOptions.kNativeAssetsYamlFile),
|
||||||
);
|
);
|
||||||
} else if (webMode) {
|
} else if (webMode) {
|
||||||
return webRunnerFactory!.createWebRunner(
|
return webRunnerFactory!.createWebRunner(
|
||||||
|
@ -95,11 +95,13 @@ class HotRunner extends ResidentRunner {
|
|||||||
ReloadSourcesHelper reloadSourcesHelper = defaultReloadSourcesHelper,
|
ReloadSourcesHelper reloadSourcesHelper = defaultReloadSourcesHelper,
|
||||||
ReassembleHelper reassembleHelper = _defaultReassembleHelper,
|
ReassembleHelper reassembleHelper = _defaultReassembleHelper,
|
||||||
NativeAssetsBuildRunner? buildRunner,
|
NativeAssetsBuildRunner? buildRunner,
|
||||||
|
String? nativeAssetsYamlFile,
|
||||||
required Analytics analytics,
|
required Analytics analytics,
|
||||||
}) : _stopwatchFactory = stopwatchFactory,
|
}) : _stopwatchFactory = stopwatchFactory,
|
||||||
_reloadSourcesHelper = reloadSourcesHelper,
|
_reloadSourcesHelper = reloadSourcesHelper,
|
||||||
_reassembleHelper = reassembleHelper,
|
_reassembleHelper = reassembleHelper,
|
||||||
_buildRunner = buildRunner,
|
_buildRunner = buildRunner,
|
||||||
|
_nativeAssetsYamlFile = nativeAssetsYamlFile,
|
||||||
_analytics = analytics,
|
_analytics = analytics,
|
||||||
super(
|
super(
|
||||||
hotMode: true,
|
hotMode: true,
|
||||||
@ -140,6 +142,7 @@ class HotRunner extends ResidentRunner {
|
|||||||
bool? _emulator;
|
bool? _emulator;
|
||||||
|
|
||||||
NativeAssetsBuildRunner? _buildRunner;
|
NativeAssetsBuildRunner? _buildRunner;
|
||||||
|
final String? _nativeAssetsYamlFile;
|
||||||
|
|
||||||
String? flavor;
|
String? flavor;
|
||||||
|
|
||||||
@ -371,19 +374,24 @@ class HotRunner extends ResidentRunner {
|
|||||||
}) async {
|
}) async {
|
||||||
await _calculateTargetPlatform();
|
await _calculateTargetPlatform();
|
||||||
|
|
||||||
final Uri projectUri = Uri.directory(projectRootPath);
|
final Uri? nativeAssetsYaml;
|
||||||
_buildRunner ??= NativeAssetsBuildRunnerImpl(
|
if (_nativeAssetsYamlFile != null) {
|
||||||
projectUri,
|
nativeAssetsYaml = globals.fs.path.toUri(_nativeAssetsYamlFile);
|
||||||
debuggingOptions.buildInfo.packageConfig,
|
} else {
|
||||||
fileSystem,
|
final Uri projectUri = Uri.directory(projectRootPath);
|
||||||
globals.logger,
|
_buildRunner ??= NativeAssetsBuildRunnerImpl(
|
||||||
);
|
projectUri,
|
||||||
final Uri? nativeAssetsYaml = await dryRunNativeAssets(
|
debuggingOptions.buildInfo.packageConfig,
|
||||||
projectUri: projectUri,
|
fileSystem,
|
||||||
fileSystem: fileSystem,
|
globals.logger,
|
||||||
buildRunner: _buildRunner!,
|
);
|
||||||
flutterDevices: flutterDevices,
|
nativeAssetsYaml = await dryRunNativeAssets(
|
||||||
);
|
projectUri: projectUri,
|
||||||
|
fileSystem: fileSystem,
|
||||||
|
buildRunner: _buildRunner!,
|
||||||
|
flutterDevices: flutterDevices,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
final Stopwatch appStartedTimer = Stopwatch()..start();
|
final Stopwatch appStartedTimer = Stopwatch()..start();
|
||||||
final File mainFile = globals.fs.file(mainPath);
|
final File mainFile = globals.fs.file(mainPath);
|
||||||
|
@ -150,6 +150,7 @@ abstract final class FlutterOptions {
|
|||||||
static const String kAndroidProjectArgs = 'android-project-arg';
|
static const String kAndroidProjectArgs = 'android-project-arg';
|
||||||
static const String kInitializeFromDill = 'initialize-from-dill';
|
static const String kInitializeFromDill = 'initialize-from-dill';
|
||||||
static const String kAssumeInitializeFromDillUpToDate = 'assume-initialize-from-dill-up-to-date';
|
static const String kAssumeInitializeFromDillUpToDate = 'assume-initialize-from-dill-up-to-date';
|
||||||
|
static const String kNativeAssetsYamlFile = 'native-assets-yaml-file';
|
||||||
static const String kFatalWarnings = 'fatal-warnings';
|
static const String kFatalWarnings = 'fatal-warnings';
|
||||||
static const String kUseApplicationBinary = 'use-application-binary';
|
static const String kUseApplicationBinary = 'use-application-binary';
|
||||||
static const String kWebBrowserFlag = 'web-browser-flag';
|
static const String kWebBrowserFlag = 'web-browser-flag';
|
||||||
@ -1007,6 +1008,14 @@ abstract class FlutterCommand extends Command<void> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void usesNativeAssetsOption({ required bool hide }) {
|
||||||
|
argParser.addOption(FlutterOptions.kNativeAssetsYamlFile,
|
||||||
|
help: 'Initializes the resident compiler with a custom native assets '
|
||||||
|
'yaml file instead of the default cached location.',
|
||||||
|
hide: hide,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void addMultidexOption({ bool hide = false }) {
|
void addMultidexOption({ bool hide = false }) {
|
||||||
argParser.addFlag('multidex',
|
argParser.addFlag('multidex',
|
||||||
defaultsTo: true,
|
defaultsTo: true,
|
||||||
|
@ -1208,6 +1208,7 @@ class FakeHotRunnerFactory extends Fake implements HotRunnerFactory {
|
|||||||
bool ipv6 = false,
|
bool ipv6 = false,
|
||||||
FlutterProject? flutterProject,
|
FlutterProject? flutterProject,
|
||||||
Analytics? analytics,
|
Analytics? analytics,
|
||||||
|
String? nativeAssetsYamlFile,
|
||||||
}) {
|
}) {
|
||||||
if (_artifactTester != null) {
|
if (_artifactTester != null) {
|
||||||
for (final FlutterDevice device in devices) {
|
for (final FlutterDevice device in devices) {
|
||||||
|
@ -2455,12 +2455,14 @@ flutter:
|
|||||||
targetPlatform: TargetPlatform.darwin,
|
targetPlatform: TargetPlatform.darwin,
|
||||||
sdkNameAndVersion: 'Macos',
|
sdkNameAndVersion: 'Macos',
|
||||||
);
|
);
|
||||||
|
final FakeResidentCompiler residentCompiler = FakeResidentCompiler();
|
||||||
final FakeFlutterDevice flutterDevice = FakeFlutterDevice()
|
final FakeFlutterDevice flutterDevice = FakeFlutterDevice()
|
||||||
..testUri = testUri
|
..testUri = testUri
|
||||||
..vmServiceHost = (() => fakeVmServiceHost)
|
..vmServiceHost = (() => fakeVmServiceHost)
|
||||||
..device = device
|
..device = device
|
||||||
.._devFS = devFS
|
.._devFS = devFS
|
||||||
..targetPlatform = TargetPlatform.darwin;
|
..targetPlatform = TargetPlatform.darwin
|
||||||
|
..generator = residentCompiler;
|
||||||
|
|
||||||
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
|
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
|
||||||
listViews,
|
listViews,
|
||||||
@ -2508,6 +2510,67 @@ flutter:
|
|||||||
expect(buildRunner.dryRunInvocations, 1);
|
expect(buildRunner.dryRunInvocations, 1);
|
||||||
expect(buildRunner.hasPackageConfigInvocations, 1);
|
expect(buildRunner.hasPackageConfigInvocations, 1);
|
||||||
expect(buildRunner.packagesWithNativeAssetsInvocations, 1);
|
expect(buildRunner.packagesWithNativeAssetsInvocations, 1);
|
||||||
|
|
||||||
|
expect(residentCompiler.recompileCalled, true);
|
||||||
|
expect(residentCompiler.receivedNativeAssetsYaml.toString(), endsWith('native_assets/macos/native_assets.yaml'));
|
||||||
|
}),
|
||||||
|
overrides: <Type, Generator>{
|
||||||
|
ProcessManager: () => FakeProcessManager.any(),
|
||||||
|
FeatureFlags: () => TestFeatureFlags(isNativeAssetsEnabled: true, isMacOSEnabled: true),
|
||||||
|
});
|
||||||
|
|
||||||
|
testUsingContext(
|
||||||
|
'use the nativeAssetsYamlFile when provided',
|
||||||
|
() => testbed.run(() async {
|
||||||
|
final FakeDevice device = FakeDevice(
|
||||||
|
targetPlatform: TargetPlatform.darwin,
|
||||||
|
sdkNameAndVersion: 'Macos',
|
||||||
|
);
|
||||||
|
final FakeResidentCompiler residentCompiler = FakeResidentCompiler();
|
||||||
|
final FakeFlutterDevice flutterDevice = FakeFlutterDevice()
|
||||||
|
..testUri = testUri
|
||||||
|
..vmServiceHost = (() => fakeVmServiceHost)
|
||||||
|
..device = device
|
||||||
|
.._devFS = devFS
|
||||||
|
..targetPlatform = TargetPlatform.darwin
|
||||||
|
..generator = residentCompiler;
|
||||||
|
|
||||||
|
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
|
||||||
|
listViews,
|
||||||
|
listViews,
|
||||||
|
]);
|
||||||
|
globals.fs
|
||||||
|
.file(globals.fs.path.join('lib', 'main.dart'))
|
||||||
|
.createSync(recursive: true);
|
||||||
|
final FakeNativeAssetsBuildRunner buildRunner = FakeNativeAssetsBuildRunner();
|
||||||
|
residentRunner = HotRunner(
|
||||||
|
<FlutterDevice>[
|
||||||
|
flutterDevice,
|
||||||
|
],
|
||||||
|
stayResident: false,
|
||||||
|
debuggingOptions: DebuggingOptions.enabled(const BuildInfo(
|
||||||
|
BuildMode.debug,
|
||||||
|
'',
|
||||||
|
treeShakeIcons: false,
|
||||||
|
trackWidgetCreation: true,
|
||||||
|
)),
|
||||||
|
target: 'main.dart',
|
||||||
|
devtoolsHandler: createNoOpHandler,
|
||||||
|
buildRunner: buildRunner,
|
||||||
|
analytics: fakeAnalytics,
|
||||||
|
nativeAssetsYamlFile: 'foo.yaml',
|
||||||
|
);
|
||||||
|
|
||||||
|
final int? result = await residentRunner.run();
|
||||||
|
expect(result, 0);
|
||||||
|
|
||||||
|
expect(buildRunner.buildInvocations, 0);
|
||||||
|
expect(buildRunner.dryRunInvocations, 0);
|
||||||
|
expect(buildRunner.hasPackageConfigInvocations, 0);
|
||||||
|
expect(buildRunner.packagesWithNativeAssetsInvocations, 0);
|
||||||
|
|
||||||
|
expect(residentCompiler.recompileCalled, true);
|
||||||
|
expect(residentCompiler.receivedNativeAssetsYaml, globals.fs.path.toUri('foo.yaml'));
|
||||||
}),
|
}),
|
||||||
overrides: <Type, Generator>{
|
overrides: <Type, Generator>{
|
||||||
ProcessManager: () => FakeProcessManager.any(),
|
ProcessManager: () => FakeProcessManager.any(),
|
||||||
@ -2700,6 +2763,8 @@ class FakeDelegateFlutterDevice extends FlutterDevice {
|
|||||||
class FakeResidentCompiler extends Fake implements ResidentCompiler {
|
class FakeResidentCompiler extends Fake implements ResidentCompiler {
|
||||||
CompilerOutput? nextOutput;
|
CompilerOutput? nextOutput;
|
||||||
bool didSuppressErrors = false;
|
bool didSuppressErrors = false;
|
||||||
|
Uri? receivedNativeAssetsYaml;
|
||||||
|
bool recompileCalled = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<CompilerOutput?> recompile(
|
Future<CompilerOutput?> recompile(
|
||||||
@ -2714,6 +2779,8 @@ class FakeResidentCompiler extends Fake implements ResidentCompiler {
|
|||||||
File? dartPluginRegistrant,
|
File? dartPluginRegistrant,
|
||||||
Uri? nativeAssetsYaml,
|
Uri? nativeAssetsYaml,
|
||||||
}) async {
|
}) async {
|
||||||
|
recompileCalled = true;
|
||||||
|
receivedNativeAssetsYaml = nativeAssetsYaml;
|
||||||
didSuppressErrors = suppressErrors;
|
didSuppressErrors = suppressErrors;
|
||||||
return nextOutput ?? const CompilerOutput('foo.dill', 0, <Uri>[]);
|
return nextOutput ?? const CompilerOutput('foo.dill', 0, <Uri>[]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user