Skip to content

Commit 5b39e0b

Browse files
authored
[flutter_tools] Inject CrashReportSender into SwiftPM migration (flutter#196315)
Previously, `SwiftPackageManagerIntegrationMigration` accepted `required bool reportCrashes` and instantiated `CrashReportSender` inline with an unmocked `http.Client()`. As a result, the `validate project settings` unit tests in `swift_package_manager_integration_migration_test.dart` made live HTTPS `POST` requests to `https://clients2.google.com/cr/report`, causing `tool_tests_general` presubmits to fail with `TimeoutException` whenever the remote endpoint took longer than 2 seconds. Replace `bool reportCrashes` with an optional `CrashReportSender Function()? crashReportSenderFactory` passed at the `buildXcodeProject` and `buildMacOS` production call sites (when `!botDetector.isRunningOnBot`) so `CrashReportSender` and its `http.Client` are only allocated when a migration crash occurs, pass a `FakeCrashReportSender` factory in `swift_package_manager_integration_migration_test.dart`, and re-enable the two `validate project settings` tests that were temporarily skipped in flutter#196310. Fixes flutter#196307 Previous output: ``` 00:32 +3002 ~2 -1: test/general.shard/migrations/swift_package_manager_integration_migration_test.dart: Flutter Package Migration validate project settings throw if settings fail to compile [E] TimeoutException after 0:00:02.000000: Test timed out after 2 seconds. dart:isolate _RawReceivePort._handleMessage ``` Current output: ``` +157: All tests passed! ``` ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/CONTRIBUTING.ai.md [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [flutter/website]: https://github.com/flutter/website [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent b98afb5 commit 5b39e0b

4 files changed

Lines changed: 144 additions & 125 deletions

File tree

‎packages/flutter_tools/lib/src/ios/mac.dart‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import '../migrations/xcode_script_build_phase_migration.dart';
4343
import '../migrations/xcode_thin_binary_build_phase_input_paths_migration.dart';
4444
import '../plugins.dart';
4545
import '../project.dart';
46+
import '../reporting/crash_reporting.dart';
4647
import 'application_package.dart';
4748
import 'code_signing.dart';
4849
import 'migrations/host_app_info_plist_migration.dart';
@@ -170,8 +171,15 @@ Future<XcodeBuildResult> buildXcodeProject({
170171
darwinPlatform,
171172
buildInfo,
172173
analytics: analytics,
174+
crashReportSenderFactory: botDetector.isRunningOnBot
175+
? null
176+
: () => CrashReportSender(
177+
platform: platform,
178+
logger: logger,
179+
operatingSystemUtils: os,
180+
analytics: analytics,
181+
),
173182
plistParser: plistParser,
174-
reportCrashes: !botDetector.isRunningOnBot,
175183
toolContext: toolContext,
176184
xcodeProjectInterpreter: xcodeProjectInterpreter,
177185
),

‎packages/flutter_tools/lib/src/macos/build_macos.dart‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import '../migrations/xcode_project_object_version_migration.dart';
3434
import '../migrations/xcode_script_build_phase_migration.dart';
3535
import '../migrations/xcode_thin_binary_build_phase_input_paths_migration.dart';
3636
import '../project.dart';
37+
import '../reporting/crash_reporting.dart';
3738
import 'application_package.dart';
3839
import 'cocoapod_utils.dart';
3940
import 'cocoapods.dart';
@@ -151,8 +152,15 @@ Future<void> buildMacOS({
151152
darwinPlatform,
152153
buildInfo,
153154
analytics: analytics,
155+
crashReportSenderFactory: botDetector.isRunningOnBot
156+
? null
157+
: () => CrashReportSender(
158+
platform: platform,
159+
logger: logger,
160+
operatingSystemUtils: os,
161+
analytics: analytics,
162+
),
154163
plistParser: plistParser,
155-
reportCrashes: !botDetector.isRunningOnBot,
156164
toolContext: toolContext,
157165
xcodeProjectInterpreter: xcodeProjectInterpreter,
158166
),

‎packages/flutter_tools/lib/src/migrations/swift_package_manager_integration_migration.dart‎

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import '../base/config.dart';
1212
import '../base/error_handling_io.dart';
1313
import '../base/file_system.dart';
1414
import '../base/logger.dart';
15-
import '../base/os.dart';
16-
import '../base/platform.dart';
1715
import '../base/project_migrator.dart';
1816
import '../build_info.dart';
1917
import '../context/tool_context.dart';
@@ -35,9 +33,9 @@ class SwiftPackageManagerIntegrationMigration extends ProjectMigrator {
3533
this._buildInfo, {
3634
required this._analytics,
3735
required this._plistParser,
38-
required this._reportCrashes,
3936
required this._toolContext,
4037
required this._xcodeProjectInterpreter,
38+
this._crashReportSenderFactory,
4139
}) : _xcodeProject = project,
4240
_xcodeProjectInfoFile = project.xcodeProjectInfoFile,
4341
super(_toolContext.logger);
@@ -46,8 +44,8 @@ class SwiftPackageManagerIntegrationMigration extends ProjectMigrator {
4644
final FlutterDarwinPlatform _platform;
4745
final BuildInfo _buildInfo;
4846
final Analytics _analytics;
47+
final CrashReportSender Function()? _crashReportSenderFactory;
4948
final PlistParser _plistParser;
50-
final bool _reportCrashes;
5149
final ToolContext _toolContext;
5250
final XcodeProjectInterpreter _xcodeProjectInterpreter;
5351
final File _xcodeProjectInfoFile;
@@ -171,12 +169,7 @@ class SwiftPackageManagerIntegrationMigration extends ProjectMigrator {
171169
return;
172170
}
173171

174-
final ToolContext(
175-
:Config config,
176-
:FileSystem fs,
177-
:OperatingSystemUtils os,
178-
platform: Platform hostPlatform,
179-
) = _toolContext;
172+
final ToolContext(:Config config, :FileSystem fs) = _toolContext;
180173

181174
Status? migrationStatus;
182175
SchemeInfo? schemeInfo;
@@ -247,24 +240,18 @@ class SwiftPackageManagerIntegrationMigration extends ProjectMigrator {
247240
);
248241
} on Exception catch (e, stackTrace) {
249242
// Send error to crash reporter.
250-
if (_reportCrashes) {
243+
if (_crashReportSenderFactory case final crashReportSenderFactory?) {
251244
try {
252245
await asyncGuard(() async {
253-
final crashReportSender = CrashReportSender(
254-
platform: hostPlatform,
255-
logger: logger,
256-
operatingSystemUtils: os,
257-
analytics: _analytics,
258-
);
259-
await crashReportSender.sendReport(
246+
await crashReportSenderFactory().sendReport(
260247
error: e,
261248
stackTrace: stackTrace,
262249
getFlutterVersion: _flutterVersionString,
263250
command: 'swiftpm-migration',
264251
typeId: 'XcodeBuildError',
265252
);
266253
});
267-
} on Exception catch (_) {
254+
} on Exception {
268255
// Fail silently if it fails to send crash report
269256
}
270257
}

0 commit comments

Comments
 (0)