Unverified Commit 2b512781 authored by George Wright's avatar George Wright Committed by GitHub

Add a --dart-entrypoint-args flag to flutter run to pass through Dart...

Add a --dart-entrypoint-args flag to flutter run to pass through Dart entrypoint arguments on Flutter Desktop (#69607)
parent b8d21ad3
...@@ -115,7 +115,14 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment ...@@ -115,7 +115,14 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
help: 'Filters out all trace events except those that are specified in ' help: 'Filters out all trace events except those that are specified in '
'this comma separated list of allowed prefixes.', 'this comma separated list of allowed prefixes.',
valueHelp: 'foo,bar', valueHelp: 'foo,bar',
); )
..addMultiOption('dart-entrypoint-args',
abbr: 'a',
help: 'Pass a list of arguments to the Dart entrypoint at application '
'startup. By default this is main(List<String> args). Specify '
'this option multiple times each with one argument to pass '
'multiple arguments to the Dart entrypoint. Currently this is '
'only supported on desktop platforms.');
usesWebOptions(hide: !verboseHelp); usesWebOptions(hide: !verboseHelp);
usesTargetOption(); usesTargetOption();
usesPortOptions(); usesPortOptions();
...@@ -153,6 +160,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment ...@@ -153,6 +160,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
if (buildInfo.mode.isRelease) { if (buildInfo.mode.isRelease) {
return DebuggingOptions.disabled( return DebuggingOptions.disabled(
buildInfo, buildInfo,
dartEntrypointArgs: stringsArg('dart-entrypoint-args'),
hostname: featureFlags.isWebEnabled ? stringArg('web-hostname') : '', hostname: featureFlags.isWebEnabled ? stringArg('web-hostname') : '',
port: featureFlags.isWebEnabled ? stringArg('web-port') : '', port: featureFlags.isWebEnabled ? stringArg('web-port') : '',
webUseSseForDebugProxy: featureFlags.isWebEnabled && stringArg('web-server-debug-protocol') == 'sse', webUseSseForDebugProxy: featureFlags.isWebEnabled && stringArg('web-server-debug-protocol') == 'sse',
...@@ -167,6 +175,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment ...@@ -167,6 +175,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
startPaused: boolArg('start-paused'), startPaused: boolArg('start-paused'),
disableServiceAuthCodes: boolArg('disable-service-auth-codes'), disableServiceAuthCodes: boolArg('disable-service-auth-codes'),
disableDds: boolArg('disable-dds'), disableDds: boolArg('disable-dds'),
dartEntrypointArgs: stringsArg('dart-entrypoint-args'),
dartFlags: stringArg('dart-flags') ?? '', dartFlags: stringArg('dart-flags') ?? '',
useTestFonts: argParser.options.containsKey('use-test-fonts') && boolArg('use-test-fonts'), useTestFonts: argParser.options.containsKey('use-test-fonts') && boolArg('use-test-fonts'),
enableSoftwareRendering: argParser.options.containsKey('enable-software-rendering') && boolArg('enable-software-rendering'), enableSoftwareRendering: argParser.options.containsKey('enable-software-rendering') && boolArg('enable-software-rendering'),
......
...@@ -139,6 +139,7 @@ abstract class DesktopDevice extends Device { ...@@ -139,6 +139,7 @@ abstract class DesktopDevice extends Device {
final Process process = await _processManager.start( final Process process = await _processManager.start(
<String>[ <String>[
executable, executable,
...?debuggingOptions?.dartEntrypointArgs,
], ],
environment: _computeEnvironment(debuggingOptions, traceStartup, route), environment: _computeEnvironment(debuggingOptions, traceStartup, route),
); );
......
...@@ -835,6 +835,7 @@ class DebuggingOptions { ...@@ -835,6 +835,7 @@ class DebuggingOptions {
this.startPaused = false, this.startPaused = false,
this.disableServiceAuthCodes = false, this.disableServiceAuthCodes = false,
this.disableDds = false, this.disableDds = false,
this.dartEntrypointArgs = const <String>[],
this.dartFlags = '', this.dartFlags = '',
this.enableSoftwareRendering = false, this.enableSoftwareRendering = false,
this.skiaDeterministicRendering = false, this.skiaDeterministicRendering = false,
...@@ -865,6 +866,7 @@ class DebuggingOptions { ...@@ -865,6 +866,7 @@ class DebuggingOptions {
}) : debuggingEnabled = true; }) : debuggingEnabled = true;
DebuggingOptions.disabled(this.buildInfo, { DebuggingOptions.disabled(this.buildInfo, {
this.dartEntrypointArgs = const <String>[],
this.port, this.port,
this.hostname, this.hostname,
this.webEnableExposeUrl, this.webEnableExposeUrl,
...@@ -902,6 +904,7 @@ class DebuggingOptions { ...@@ -902,6 +904,7 @@ class DebuggingOptions {
final BuildInfo buildInfo; final BuildInfo buildInfo;
final bool startPaused; final bool startPaused;
final String dartFlags; final String dartFlags;
final List<String> dartEntrypointArgs;
final bool disableServiceAuthCodes; final bool disableServiceAuthCodes;
final bool disableDds; final bool disableDds;
final bool enableSoftwareRendering; final bool enableSoftwareRendering;
......
...@@ -247,6 +247,29 @@ void main() { ...@@ -247,6 +247,29 @@ void main() {
expect(device.createDevFSWriter(null, ''), isA<LocalDevFSWriter>()); expect(device.createDevFSWriter(null, ''), isA<LocalDevFSWriter>());
}); });
testWithoutContext('startApp supports dartEntrypointArgs', () async {
final Completer<void> completer = Completer<void>();
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: const <String>['debug', 'arg1', 'arg2'],
stdout: 'Observatory listening on http://127.0.0.1/0\n',
completer: completer
),
]);
final FakeDesktopDevice device = setUpDesktopDevice(processManager: processManager);
final FakeApplicationPackage package = FakeApplicationPackage();
final LaunchResult result = await device.startApp(
package,
prebuiltApplication: true,
debuggingOptions: DebuggingOptions.enabled(
BuildInfo.debug,
dartEntrypointArgs: <String>['arg1', 'arg2']
),
);
expect(result.started, true);
});
} }
FakeDesktopDevice setUpDesktopDevice({ FakeDesktopDevice setUpDesktopDevice({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment