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].

<!-- Links -->
[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
This commit is contained in:
Victoria Ashworth 2025-03-10 18:27:53 -05:00 committed by GitHub
parent 4fef40c0f6
commit 84b38b8dfc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 11 deletions

View File

@ -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.',
);

View File

@ -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: <Type, Generator>{
@ -1261,3 +1264,20 @@ class FakeXcodeProjectInterpreter extends Fake implements XcodeProjectInterprete
return XcodeProjectInfo(<String>[], <String>[], schemes, BufferLogger.test());
}
}
/// Capture console print events into a string buffer.
Future<StringBuffer> capturedConsolePrint(Future<void> Function() body) async {
final StringBuffer buffer = StringBuffer();
await runZoned<Future<void>>(
() async {
// Service the event loop.
await body();
},
zoneSpecification: ZoneSpecification(
print: (Zone self, ZoneDelegate parent, Zone zone, String line) {
buffer.writeln(line);
},
),
);
return buffer;
}