From 84b38b8dfcc148ff45e62f5719cf09c1c668e48d Mon Sep 17 00:00:00 2001 From: Victoria Ashworth <15619084+vashworth@users.noreply.github.com> Date: Mon, 10 Mar 2025 18:27:53 -0500 Subject: [PATCH] Make LLDB check a warning instead of a failure (#164828) We added LLDB file in https://github.com/flutter/flutter/pull/164344. This adjusts it so if the LLDB file is missing it gives a warning rather than an error that fails the build. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [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 documentation (doc comments with `///`). - [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. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [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 [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 --- .../lib/src/build_system/targets/ios.dart | 20 +++++++++---- .../build_system/targets/ios_test.dart | 30 +++++++++++++++---- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/packages/flutter_tools/lib/src/build_system/targets/ios.dart b/packages/flutter_tools/lib/src/build_system/targets/ios.dart index a8a2753cf85..e1e5fcaada1 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/ios.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/ios.dart @@ -503,11 +503,13 @@ abstract class IosLLDBInit extends Target { // an error. final String? srcRoot = environment.defines[kSrcRoot]; if (srcRoot == null) { - throw MissingDefineException(kSdkRoot, name); + environment.logger.printError('Failed to find $srcRoot'); + return; } final Directory xcodeProjectDir = environment.fileSystem.directory(srcRoot); if (!xcodeProjectDir.existsSync()) { - throw Exception('Failed to find ${xcodeProjectDir.path}'); + environment.logger.printError('Failed to find ${xcodeProjectDir.path}'); + return; } bool anyLLDBInitFound = false; @@ -522,14 +524,20 @@ abstract class IosLLDBInit extends Target { if (!anyLLDBInitFound) { final FlutterProject flutterProject = FlutterProject.fromDirectory(environment.projectDir); if (flutterProject.isModule) { - throwToolExit( - 'Debugging Flutter on new iOS versions requires an LLDB Init File. To ' + // We use print here to make sure Xcode adds the message to the build logs. See + // https://developer.apple.com/documentation/xcode/running-custom-scripts-during-a-build#Log-errors-and-warnings-from-your-script + // ignore: avoid_print + print( + 'warning: Debugging Flutter on new iOS versions requires an LLDB Init File. To ' 'ensure debug mode works, please run "flutter build ios --config-only" ' 'in your Flutter project and follow the instructions to add the file.', ); } else { - throwToolExit( - 'Debugging Flutter on new iOS versions requires an LLDB Init File. To ' + // We use print here to make sure Xcode adds the message to the build logs. See + // https://developer.apple.com/documentation/xcode/running-custom-scripts-during-a-build#Log-errors-and-warnings-from-your-script + // ignore: avoid_print + print( + 'warning: Debugging Flutter on new iOS versions requires an LLDB Init File. To ' 'ensure debug mode works, please run "flutter build ios --config-only" ' 'in your Flutter project and automatically add the files.', ); diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/ios_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/ios_test.dart index 9a9cbb14a50..8e4b2fc7652 100644 --- a/packages/flutter_tools/test/general.shard/build_system/targets/ios_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/targets/ios_test.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:async'; + import 'package:file/memory.dart'; import 'package:file_testing/file_testing.dart'; import 'package:flutter_tools/src/artifacts.dart'; @@ -1155,7 +1157,7 @@ void main() { group('DebugIosLLDBInit', () { testUsingContext( - 'throws error if missing LLDB Init File in all schemes', + 'prints warning if missing LLDB Init File in all schemes', () async { const String projectPath = 'path/to/project'; fileSystem.directory(projectPath).createSync(recursive: true); @@ -1165,11 +1167,12 @@ void main() { environment.defines[kSrcRoot] = projectPath; environment.defines[kTargetDeviceOSVersion] = '18.4.1'; + final StringBuffer buffer = await capturedConsolePrint(() async { + await const DebugIosLLDBInit().build(environment); + }); expect( - const DebugIosLLDBInit().build(environment), - throwsToolExit( - message: 'Debugging Flutter on new iOS versions requires an LLDB Init File.', - ), + buffer.toString(), + contains('warning: Debugging Flutter on new iOS versions requires an LLDB Init File.'), ); }, overrides: { @@ -1261,3 +1264,20 @@ class FakeXcodeProjectInterpreter extends Fake implements XcodeProjectInterprete return XcodeProjectInfo([], [], schemes, BufferLogger.test()); } } + +/// Capture console print events into a string buffer. +Future capturedConsolePrint(Future Function() body) async { + final StringBuffer buffer = StringBuffer(); + await runZoned>( + () async { + // Service the event loop. + await body(); + }, + zoneSpecification: ZoneSpecification( + print: (Zone self, ZoneDelegate parent, Zone zone, String line) { + buffer.writeln(line); + }, + ), + ); + return buffer; +}