Skip to content

Commit 715e476

Browse files
authored
Add xcresulttool --legacy flag for deprecated usage (#152988)
Workaround to add the `--legacy` flag until flutter/flutter#151502 can adopt the non-deprecated usage. This will allow Xcode errors to be parseable again. Fixes flutter/flutter#152989
1 parent ede2e27 commit 715e476

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:meta/meta.dart';
77
import '../../src/base/process.dart';
88
import '../../src/convert.dart' show json;
99
import '../../src/macos/xcode.dart';
10+
import '../base/version.dart';
1011
import '../convert.dart';
1112

1213
/// The generator of xcresults.
@@ -35,18 +36,22 @@ class XCResultGenerator {
3536

3637
/// Generates the XCResult.
3738
///
38-
/// Calls `xcrun xcresulttool get --path <resultPath> --format json`,
39+
/// Calls `xcrun xcresulttool get --legacy --path <resultPath> --format json`,
3940
/// then stores the useful information the json into an [XCResult] object.
4041
///
4142
/// A`issueDiscarders` can be passed to discard any issues that matches the description of any [XCResultIssueDiscarder] in the list.
4243
Future<XCResult> generate(
4344
{List<XCResultIssueDiscarder> issueDiscarders =
4445
const <XCResultIssueDiscarder>[]}) async {
46+
final Version? xcodeVersion = xcode.currentVersion;
4547
final RunResult result = await processUtils.run(
4648
<String>[
4749
...xcode.xcrunCommand(),
4850
'xcresulttool',
4951
'get',
52+
// See https://github.com/flutter/flutter/issues/151502
53+
if (xcodeVersion != null && xcodeVersion >= Version(16, 0, 0))
54+
'--legacy',
5055
'--path',
5156
resultPath,
5257
'--format',
@@ -74,7 +79,7 @@ class XCResultGenerator {
7479

7580
/// The xcresult of an `xcodebuild` command.
7681
///
77-
/// This is the result from an `xcrun xcresulttool get --path <resultPath> --format json` run.
82+
/// This is the result from an `xcrun xcresulttool get --legacy --path <resultPath> --format json` run.
7883
/// The result contains useful information such as build errors and warnings.
7984
class XCResult {
8085
/// Parse the `resultJson` and stores useful information in the returned `XCResult`.

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:flutter_tools/src/base/logger.dart';
66
import 'package:flutter_tools/src/base/process.dart';
7+
import 'package:flutter_tools/src/base/version.dart';
78
import 'package:flutter_tools/src/ios/xcodeproj.dart';
89
import 'package:flutter_tools/src/ios/xcresult.dart';
910
import 'package:flutter_tools/src/macos/xcode.dart';
@@ -21,12 +22,15 @@ void main() {
2122
required Xcode xcode,
2223
int exitCode = 0,
2324
String stderr = '',
25+
bool useLegacyFlag = true,
2426
}) {
2527
return FakeCommand(
2628
command: <String>[
2729
...xcode.xcrunCommand(),
2830
'xcresulttool',
2931
'get',
32+
if (useLegacyFlag)
33+
'--legacy',
3034
'--path',
3135
tempResultPath,
3236
'--format',
@@ -58,6 +62,8 @@ void main() {
5862
required String resultJson,
5963
int exitCode = 0,
6064
String stderr = '',
65+
Version? xcodeVersion = const Version.withText(16, 0, 0, '16.0'),
66+
bool useLegacyFlag = true,
6167
}) {
6268
final FakeProcessManager fakeProcessManager =
6369
FakeProcessManager.list(<FakeCommand>[
@@ -68,7 +74,7 @@ void main() {
6874
processManager: fakeProcessManager,
6975
xcodeProjectInterpreter: XcodeProjectInterpreter.test(
7076
processManager: fakeProcessManager,
71-
version: null,
77+
version: xcodeVersion,
7278
),
7379
);
7480
fakeProcessManager.addCommands(
@@ -79,6 +85,7 @@ void main() {
7985
xcode: xcode,
8086
exitCode: exitCode,
8187
stderr: stderr,
88+
useLegacyFlag: useLegacyFlag
8289
),
8390
],
8491
);
@@ -217,6 +224,19 @@ void main() {
217224
expect(result.parsingErrorMessage, isNull);
218225
});
219226

227+
testWithoutContext(
228+
'correctly parse sample result on < Xcode 16.', () async {
229+
final XCResultGenerator generator = setupGenerator(
230+
resultJson: kSampleResultJsonNoIssues,
231+
xcodeVersion: Version(15, 0, 0),
232+
useLegacyFlag: false,
233+
);
234+
final XCResult result = await generator.generate();
235+
expect(result.issues.length, 0);
236+
expect(result.parseSuccess, isTrue);
237+
expect(result.parsingErrorMessage, isNull);
238+
});
239+
220240
testWithoutContext(
221241
'error: `xcresulttool get` process fail should return an `XCResult` with stderr as `parsingErrorMessage`.',
222242
() async {

0 commit comments

Comments
 (0)