[flutter_tools] support all engine debugging options with FLUTTER_ENGINE_SWITCH environment variables (#67150)
Allow providing all debugging options to the desktop engine via the FLUTTER_ENGINE_SWITCH_ environment variables. Fixes #66532 Fixes #46005 Fixes #58882 The underling engine changes have already landed for Windows, macOS, but linux is still in progress
This commit is contained in:
@@ -111,8 +111,8 @@ abstract class DesktopDevice extends Device {
|
||||
ApplicationPackage package, {
|
||||
String mainPath,
|
||||
String route,
|
||||
DebuggingOptions debuggingOptions,
|
||||
Map<String, dynamic> platformArgs,
|
||||
@required DebuggingOptions debuggingOptions,
|
||||
Map<String, dynamic> platformArgs = const <String, dynamic>{},
|
||||
bool prebuiltApplication = false,
|
||||
bool ipv6 = false,
|
||||
String userIdentifier,
|
||||
@@ -120,13 +120,14 @@ abstract class DesktopDevice extends Device {
|
||||
if (!prebuiltApplication) {
|
||||
await buildForDevice(
|
||||
package,
|
||||
buildInfo: debuggingOptions?.buildInfo,
|
||||
buildInfo: debuggingOptions.buildInfo,
|
||||
mainPath: mainPath,
|
||||
);
|
||||
}
|
||||
|
||||
// Ensure that the executable is locatable.
|
||||
final BuildMode buildMode = debuggingOptions?.buildInfo?.mode;
|
||||
final bool traceStartup = platformArgs['trace-startup'] as bool ?? false;
|
||||
final String executable = executablePathForDevice(package, buildMode);
|
||||
if (executable == null) {
|
||||
_logger.printError('Unable to find executable to run');
|
||||
@@ -137,6 +138,7 @@ abstract class DesktopDevice extends Device {
|
||||
<String>[
|
||||
executable,
|
||||
],
|
||||
environment: _computeEnvironment(debuggingOptions, traceStartup, route),
|
||||
);
|
||||
_runningProcesses.add(process);
|
||||
unawaited(process.exitCode.then((_) => _runningProcesses.remove(process)));
|
||||
@@ -202,6 +204,92 @@ abstract class DesktopDevice extends Device {
|
||||
/// Called after a process is attached, allowing any device-specific extra
|
||||
/// steps to be run.
|
||||
void onAttached(ApplicationPackage package, BuildMode buildMode, Process process) {}
|
||||
|
||||
/// Computes a set of environment variables used to pass debugging information
|
||||
/// to the engine without interfering with application level command line
|
||||
/// arguments.
|
||||
///
|
||||
/// The format of the environment variables is:
|
||||
/// * FLUTTER_ENGINE_SWITCHES to the number of switches.
|
||||
/// * FLUTTER_ENGINE_SWITCH_<N> (indexing from 1) to the individual switches.
|
||||
Map<String, String> _computeEnvironment(DebuggingOptions debuggingOptions, bool traceStartup, String route) {
|
||||
int flags = 0;
|
||||
final Map<String, String> environment = <String, String>{};
|
||||
|
||||
void addFlag(String value) {
|
||||
flags += 1;
|
||||
environment['FLUTTER_ENGINE_SWITCH_$flags'] = value;
|
||||
}
|
||||
void finish() {
|
||||
environment['FLUTTER_ENGINE_SWITCHES'] = flags.toString();
|
||||
}
|
||||
|
||||
addFlag('enable-dart-profiling=true');
|
||||
addFlag('enable-background-compilation=true');
|
||||
|
||||
if (traceStartup) {
|
||||
addFlag('trace-startup=true');
|
||||
}
|
||||
if (route != null) {
|
||||
addFlag('route=$route');
|
||||
}
|
||||
if (debuggingOptions.enableSoftwareRendering) {
|
||||
addFlag('enable-software-rendering=true');
|
||||
}
|
||||
if (debuggingOptions.skiaDeterministicRendering) {
|
||||
addFlag('skia-deterministic-rendering=true');
|
||||
}
|
||||
if (debuggingOptions.traceSkia) {
|
||||
addFlag('trace-skia=true');
|
||||
}
|
||||
if (debuggingOptions.traceAllowlist != null) {
|
||||
addFlag('trace-allowlist=${debuggingOptions.traceAllowlist}');
|
||||
}
|
||||
if (debuggingOptions.traceSystrace) {
|
||||
addFlag('trace-systrace=true');
|
||||
}
|
||||
if (debuggingOptions.endlessTraceBuffer) {
|
||||
addFlag('endless-trace-buffer=true');
|
||||
}
|
||||
if (debuggingOptions.dumpSkpOnShaderCompilation) {
|
||||
addFlag('dump-skp-on-shader-compilation=true');
|
||||
}
|
||||
if (debuggingOptions.cacheSkSL) {
|
||||
addFlag('cache-sksl=true');
|
||||
}
|
||||
if (debuggingOptions.purgePersistentCache) {
|
||||
addFlag('purge-persistent-cache=true');
|
||||
}
|
||||
// Options only supported when there is a VM Service connection between the
|
||||
// tool and the device, usually in debug or profile mode.
|
||||
if (debuggingOptions.debuggingEnabled) {
|
||||
if (debuggingOptions.deviceVmServicePort != null) {
|
||||
addFlag('observatory-port=${debuggingOptions.deviceVmServicePort}');
|
||||
}
|
||||
if (debuggingOptions.buildInfo.isDebug) {
|
||||
addFlag('enable-checked-mode=true');
|
||||
addFlag('verify-entry-points=true');
|
||||
}
|
||||
if (debuggingOptions.startPaused) {
|
||||
addFlag('start-paused=true');
|
||||
}
|
||||
if (debuggingOptions.disableServiceAuthCodes) {
|
||||
addFlag('disable-service-auth-codes=true');
|
||||
}
|
||||
final String dartVmFlags = computeDartVmFlags(debuggingOptions);
|
||||
if (dartVmFlags.isNotEmpty) {
|
||||
addFlag('dart-flags=$dartVmFlags');
|
||||
}
|
||||
if (debuggingOptions.useTestFonts) {
|
||||
addFlag('use-test-fonts=true');
|
||||
}
|
||||
if (debuggingOptions.verboseSystemLogs) {
|
||||
addFlag('verbose-logging=true');
|
||||
}
|
||||
}
|
||||
finish();
|
||||
return environment;
|
||||
}
|
||||
}
|
||||
|
||||
/// A log reader for desktop applications that delegates to a [Process] stdout
|
||||
|
||||
Reference in New Issue
Block a user