Skip to content

Commit 3a656b1

Browse files
authored
Add more supported simulator debugging options and improve tests (#114628)
* add debugging options to simulator, test more debugging flags, add tests for other launch arguements * refactor iOS launch arguments to use one function for both simulator and physical devices * treat dart flags differently between physical and simulator * Simplify some flags between devices. Change --disable-service-auth-codes to not always be included for physical devices, only if disableServiceAuthCodes is true. Change --disable-observatory-publication to be used for simulator devices too. Change --enable-checked-mode & --verify-entry-points to be used if debuggingEnabled is true regardless of device type. Chnage --trace-startup to be used for simulator devices too. * fix ios release mode with buildable app startApp test * determine observatory-port from deviceVmServicePort and hostVmServicePort * add comments and remove hasObservatoryPort
1 parent d3dcd7d commit 3a656b1

File tree

8 files changed

+413
-57
lines changed

8 files changed

+413
-57
lines changed

packages/flutter_tools/lib/src/device.dart

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,45 @@ class DebuggingOptions {
913913
/// * https://github.com/dart-lang/sdk/blob/main/sdk/lib/html/doc/NATIVE_NULL_ASSERTIONS.md
914914
final bool nativeNullAssertions;
915915

916-
bool get hasObservatoryPort => hostVmServicePort != null;
916+
List<String> getIOSLaunchArguments(EnvironmentType environmentType, String? route, Map<String, Object?> platformArgs) {
917+
final String dartVmFlags = computeDartVmFlags(this);
918+
return <String>[
919+
'--enable-dart-profiling',
920+
if (disableServiceAuthCodes) '--disable-service-auth-codes',
921+
if (disablePortPublication) '--disable-observatory-publication',
922+
if (startPaused) '--start-paused',
923+
// Wrap dart flags in quotes for physical devices
924+
if (environmentType == EnvironmentType.physical && dartVmFlags.isNotEmpty)
925+
'--dart-flags="$dartVmFlags"',
926+
if (environmentType == EnvironmentType.simulator && dartVmFlags.isNotEmpty)
927+
'--dart-flags=$dartVmFlags',
928+
if (useTestFonts) '--use-test-fonts',
929+
if (debuggingEnabled) ...<String>[
930+
'--enable-checked-mode',
931+
'--verify-entry-points',
932+
],
933+
if (enableSoftwareRendering) '--enable-software-rendering',
934+
if (traceSystrace) '--trace-systrace',
935+
if (skiaDeterministicRendering) '--skia-deterministic-rendering',
936+
if (traceSkia) '--trace-skia',
937+
if (traceAllowlist != null) '--trace-allowlist="$traceAllowlist"',
938+
if (traceSkiaAllowlist != null) '--trace-skia-allowlist="$traceSkiaAllowlist"',
939+
if (endlessTraceBuffer) '--endless-trace-buffer',
940+
if (dumpSkpOnShaderCompilation) '--dump-skp-on-shader-compilation',
941+
if (verboseSystemLogs) '--verbose-logging',
942+
if (cacheSkSL) '--cache-sksl',
943+
if (purgePersistentCache) '--purge-persistent-cache',
944+
if (route != null) '--route=$route',
945+
if (platformArgs['trace-startup'] as bool? ?? false) '--trace-startup',
946+
if (enableImpeller) '--enable-impeller',
947+
if (environmentType == EnvironmentType.physical && deviceVmServicePort != null)
948+
'--observatory-port=$deviceVmServicePort',
949+
// The simulator "device" is actually on the host machine so no ports will be forwarded.
950+
// Use the suggested host port.
951+
if (environmentType == EnvironmentType.simulator && hostVmServicePort != null)
952+
'--observatory-port=$hostVmServicePort',
953+
];
954+
}
917955

918956
Map<String, Object?> toJson() => <String, Object?>{
919957
'debuggingEnabled': debuggingEnabled,

packages/flutter_tools/lib/src/ios/devices.dart

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -348,34 +348,11 @@ class IOSDevice extends Device {
348348
}
349349

350350
// Step 3: Attempt to install the application on the device.
351-
final String dartVmFlags = computeDartVmFlags(debuggingOptions);
352-
final List<String> launchArguments = <String>[
353-
'--enable-dart-profiling',
354-
'--disable-service-auth-codes',
355-
if (debuggingOptions.disablePortPublication) '--disable-observatory-publication',
356-
if (debuggingOptions.startPaused) '--start-paused',
357-
if (dartVmFlags.isNotEmpty) '--dart-flags="$dartVmFlags"',
358-
if (debuggingOptions.useTestFonts) '--use-test-fonts',
359-
if (debuggingOptions.debuggingEnabled) ...<String>[
360-
'--enable-checked-mode',
361-
'--verify-entry-points',
362-
],
363-
if (debuggingOptions.enableSoftwareRendering) '--enable-software-rendering',
364-
if (debuggingOptions.traceSystrace) '--trace-systrace',
365-
if (debuggingOptions.skiaDeterministicRendering) '--skia-deterministic-rendering',
366-
if (debuggingOptions.traceSkia) '--trace-skia',
367-
if (debuggingOptions.traceAllowlist != null) '--trace-allowlist="${debuggingOptions.traceAllowlist}"',
368-
if (debuggingOptions.traceSkiaAllowlist != null) '--trace-skia-allowlist="${debuggingOptions.traceSkiaAllowlist}"',
369-
if (debuggingOptions.endlessTraceBuffer) '--endless-trace-buffer',
370-
if (debuggingOptions.dumpSkpOnShaderCompilation) '--dump-skp-on-shader-compilation',
371-
if (debuggingOptions.verboseSystemLogs) '--verbose-logging',
372-
if (debuggingOptions.cacheSkSL) '--cache-sksl',
373-
if (debuggingOptions.purgePersistentCache) '--purge-persistent-cache',
374-
if (route != null) '--route=$route',
375-
if (platformArgs['trace-startup'] as bool? ?? false) '--trace-startup',
376-
if (debuggingOptions.enableImpeller) '--enable-impeller',
377-
];
378-
351+
final List<String> launchArguments = debuggingOptions.getIOSLaunchArguments(
352+
EnvironmentType.physical,
353+
route,
354+
platformArgs,
355+
);
379356
final Status installStatus = _logger.startProgress(
380357
'Installing and launching...',
381358
);

packages/flutter_tools/lib/src/ios/simulators.dart

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -445,27 +445,11 @@ class IOSSimulator extends Device {
445445
}
446446

447447
// Prepare launch arguments.
448-
final String dartVmFlags = computeDartVmFlags(debuggingOptions);
449-
final List<String> args = <String>[
450-
'--enable-dart-profiling',
451-
if (debuggingOptions.debuggingEnabled) ...<String>[
452-
if (debuggingOptions.buildInfo.isDebug) ...<String>[
453-
'--enable-checked-mode',
454-
'--verify-entry-points',
455-
],
456-
if (debuggingOptions.enableSoftwareRendering) '--enable-software-rendering',
457-
if (debuggingOptions.startPaused) '--start-paused',
458-
if (debuggingOptions.disableServiceAuthCodes) '--disable-service-auth-codes',
459-
if (debuggingOptions.skiaDeterministicRendering) '--skia-deterministic-rendering',
460-
if (debuggingOptions.useTestFonts) '--use-test-fonts',
461-
if (debuggingOptions.traceAllowlist != null) '--trace-allowlist="${debuggingOptions.traceAllowlist}"',
462-
if (debuggingOptions.traceSkiaAllowlist != null) '--trace-skia-allowlist="${debuggingOptions.traceSkiaAllowlist}"',
463-
if (dartVmFlags.isNotEmpty) '--dart-flags=$dartVmFlags',
464-
if (debuggingOptions.enableImpeller) '--enable-impeller',
465-
'--observatory-port=${debuggingOptions.hostVmServicePort ?? 0}',
466-
if (route != null) '--route=$route',
467-
],
468-
];
448+
final List<String> launchArguments = debuggingOptions.getIOSLaunchArguments(
449+
EnvironmentType.simulator,
450+
route,
451+
platformArgs,
452+
);
469453

470454
ProtocolDiscovery? observatoryDiscovery;
471455
if (debuggingOptions.debuggingEnabled) {
@@ -491,7 +475,7 @@ class IOSSimulator extends Device {
491475
return LaunchResult.failed();
492476
}
493477

494-
await _simControl.launch(id, bundleIdentifier, args);
478+
await _simControl.launch(id, bundleIdentifier, launchArguments);
495479
} on Exception catch (error) {
496480
globals.printError('$error');
497481
return LaunchResult.failed();

packages/flutter_tools/lib/src/tester/flutter_tester.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class FlutterTesterDevice extends Device {
172172
'--start-paused',
173173
if (debuggingOptions.disableServiceAuthCodes)
174174
'--disable-service-auth-codes',
175-
if (debuggingOptions.hasObservatoryPort)
175+
if (debuggingOptions.hostVmServicePort != null)
176176
'--observatory-port=${debuggingOptions.hostVmServicePort}',
177177
applicationKernelFilePath,
178178
];

packages/flutter_tools/test/general.shard/device_test.dart

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,205 @@ void main() {
466466
expect(deserialized.enableImpeller, original.enableImpeller);
467467
});
468468
});
469+
470+
group('Get iOS launch arguments from DebuggingOptions', () {
471+
testWithoutContext('Get launch arguments for physical device with debugging enabled with all launch arguments', () {
472+
final DebuggingOptions original = DebuggingOptions.enabled(
473+
BuildInfo.debug,
474+
startPaused: true,
475+
disableServiceAuthCodes: true,
476+
disablePortPublication: true,
477+
dartFlags: '--foo',
478+
useTestFonts: true,
479+
enableSoftwareRendering: true,
480+
skiaDeterministicRendering: true,
481+
traceSkia: true,
482+
traceAllowlist: 'foo',
483+
traceSkiaAllowlist: 'skia.a,skia.b',
484+
traceSystrace: true,
485+
endlessTraceBuffer: true,
486+
dumpSkpOnShaderCompilation: true,
487+
cacheSkSL: true,
488+
purgePersistentCache: true,
489+
verboseSystemLogs: true,
490+
nullAssertions: true,
491+
enableImpeller: true,
492+
deviceVmServicePort: 0,
493+
hostVmServicePort: 1,
494+
);
495+
496+
final List<String> launchArguments = original.getIOSLaunchArguments(
497+
EnvironmentType.physical,
498+
'/test',
499+
<String, dynamic>{
500+
'trace-startup': true,
501+
},
502+
);
503+
504+
expect(
505+
launchArguments.join(' '),
506+
<String>[
507+
'--enable-dart-profiling',
508+
'--disable-service-auth-codes',
509+
'--disable-observatory-publication',
510+
'--start-paused',
511+
'--dart-flags="--foo,--null_assertions"',
512+
'--use-test-fonts',
513+
'--enable-checked-mode',
514+
'--verify-entry-points',
515+
'--enable-software-rendering',
516+
'--trace-systrace',
517+
'--skia-deterministic-rendering',
518+
'--trace-skia',
519+
'--trace-allowlist="foo"',
520+
'--trace-skia-allowlist="skia.a,skia.b"',
521+
'--endless-trace-buffer',
522+
'--dump-skp-on-shader-compilation',
523+
'--verbose-logging',
524+
'--cache-sksl',
525+
'--purge-persistent-cache',
526+
'--route=/test',
527+
'--trace-startup',
528+
'--enable-impeller',
529+
'--observatory-port=0',
530+
].join(' '),
531+
);
532+
});
533+
534+
testWithoutContext('Get launch arguments for physical device with debugging enabled with no launch arguments', () {
535+
final DebuggingOptions original = DebuggingOptions.enabled(
536+
BuildInfo.debug,
537+
);
538+
539+
final List<String> launchArguments = original.getIOSLaunchArguments(
540+
EnvironmentType.physical,
541+
null,
542+
<String, Object?>{},
543+
);
544+
545+
expect(
546+
launchArguments.join(' '),
547+
<String>[
548+
'--enable-dart-profiling',
549+
'--enable-checked-mode',
550+
'--verify-entry-points',
551+
].join(' '),
552+
);
553+
});
554+
555+
testWithoutContext('Get launch arguments for physical device with debugging disabled with available launch arguments', () {
556+
final DebuggingOptions original = DebuggingOptions.disabled(
557+
BuildInfo.debug,
558+
traceAllowlist: 'foo',
559+
cacheSkSL: true,
560+
enableImpeller: true,
561+
);
562+
563+
final List<String> launchArguments = original.getIOSLaunchArguments(
564+
EnvironmentType.physical,
565+
'/test',
566+
<String, dynamic>{
567+
'trace-startup': true,
568+
},
569+
);
570+
571+
expect(
572+
launchArguments.join(' '),
573+
<String>[
574+
'--enable-dart-profiling',
575+
'--trace-allowlist="foo"',
576+
'--cache-sksl',
577+
'--route=/test',
578+
'--trace-startup',
579+
'--enable-impeller',
580+
].join(' '),
581+
);
582+
});
583+
584+
testWithoutContext('Get launch arguments for simulator device with debugging enabled with all launch arguments', () {
585+
final DebuggingOptions original = DebuggingOptions.enabled(
586+
BuildInfo.debug,
587+
startPaused: true,
588+
disableServiceAuthCodes: true,
589+
disablePortPublication: true,
590+
dartFlags: '--foo',
591+
useTestFonts: true,
592+
enableSoftwareRendering: true,
593+
skiaDeterministicRendering: true,
594+
traceSkia: true,
595+
traceAllowlist: 'foo',
596+
traceSkiaAllowlist: 'skia.a,skia.b',
597+
traceSystrace: true,
598+
endlessTraceBuffer: true,
599+
dumpSkpOnShaderCompilation: true,
600+
cacheSkSL: true,
601+
purgePersistentCache: true,
602+
verboseSystemLogs: true,
603+
nullAssertions: true,
604+
enableImpeller: true,
605+
deviceVmServicePort: 0,
606+
hostVmServicePort: 1,
607+
);
608+
609+
final List<String> launchArguments = original.getIOSLaunchArguments(
610+
EnvironmentType.simulator,
611+
'/test',
612+
<String, dynamic>{
613+
'trace-startup': true,
614+
},
615+
);
616+
617+
expect(
618+
launchArguments.join(' '),
619+
<String>[
620+
'--enable-dart-profiling',
621+
'--disable-service-auth-codes',
622+
'--disable-observatory-publication',
623+
'--start-paused',
624+
'--dart-flags=--foo,--null_assertions',
625+
'--use-test-fonts',
626+
'--enable-checked-mode',
627+
'--verify-entry-points',
628+
'--enable-software-rendering',
629+
'--trace-systrace',
630+
'--skia-deterministic-rendering',
631+
'--trace-skia',
632+
'--trace-allowlist="foo"',
633+
'--trace-skia-allowlist="skia.a,skia.b"',
634+
'--endless-trace-buffer',
635+
'--dump-skp-on-shader-compilation',
636+
'--verbose-logging',
637+
'--cache-sksl',
638+
'--purge-persistent-cache',
639+
'--route=/test',
640+
'--trace-startup',
641+
'--enable-impeller',
642+
'--observatory-port=1',
643+
].join(' '),
644+
);
645+
});
646+
647+
testWithoutContext('Get launch arguments for simulator device with debugging enabled with no launch arguments', () {
648+
final DebuggingOptions original = DebuggingOptions.enabled(
649+
BuildInfo.debug,
650+
);
651+
652+
final List<String> launchArguments = original.getIOSLaunchArguments(
653+
EnvironmentType.simulator,
654+
null,
655+
<String, Object?>{},
656+
);
657+
658+
expect(
659+
launchArguments.join(' '),
660+
<String>[
661+
'--enable-dart-profiling',
662+
'--enable-checked-mode',
663+
'--verify-entry-points',
664+
].join(' '),
665+
);
666+
});
667+
});
469668
}
470669

471670
class TestDeviceManager extends DeviceManager {

packages/flutter_tools/test/general.shard/ios/ios_device_start_nonprebuilt_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ void main() {
205205
'--args',
206206
const <String>[
207207
'--enable-dart-profiling',
208-
'--disable-service-auth-codes',
209208
].join(' '),
210209
])
211210
);

0 commit comments

Comments
 (0)