Add xcresulttool --legacy flag for deprecated usage (#152988)

Workaround to add the `--legacy` flag until https://github.com/flutter/flutter/issues/151502 can adopt the non-deprecated usage.

This will allow Xcode errors to be parseable again.

Fixes https://github.com/flutter/flutter/issues/152989
This commit is contained in:
Jenn Magder 2024-08-07 12:59:11 -07:00 committed by GitHub
parent ede2e27054
commit 715e476545
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import 'package:meta/meta.dart';
import '../../src/base/process.dart';
import '../../src/convert.dart' show json;
import '../../src/macos/xcode.dart';
import '../base/version.dart';
import '../convert.dart';
/// The generator of xcresults.
@ -35,18 +36,22 @@ class XCResultGenerator {
/// Generates the XCResult.
///
/// Calls `xcrun xcresulttool get --path <resultPath> --format json`,
/// Calls `xcrun xcresulttool get --legacy --path <resultPath> --format json`,
/// then stores the useful information the json into an [XCResult] object.
///
/// A`issueDiscarders` can be passed to discard any issues that matches the description of any [XCResultIssueDiscarder] in the list.
Future<XCResult> generate(
{List<XCResultIssueDiscarder> issueDiscarders =
const <XCResultIssueDiscarder>[]}) async {
final Version? xcodeVersion = xcode.currentVersion;
final RunResult result = await processUtils.run(
<String>[
...xcode.xcrunCommand(),
'xcresulttool',
'get',
// See https://github.com/flutter/flutter/issues/151502
if (xcodeVersion != null && xcodeVersion >= Version(16, 0, 0))
'--legacy',
'--path',
resultPath,
'--format',
@ -74,7 +79,7 @@ class XCResultGenerator {
/// The xcresult of an `xcodebuild` command.
///
/// This is the result from an `xcrun xcresulttool get --path <resultPath> --format json` run.
/// This is the result from an `xcrun xcresulttool get --legacy --path <resultPath> --format json` run.
/// The result contains useful information such as build errors and warnings.
class XCResult {
/// Parse the `resultJson` and stores useful information in the returned `XCResult`.

View File

@ -4,6 +4,7 @@
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/process.dart';
import 'package:flutter_tools/src/base/version.dart';
import 'package:flutter_tools/src/ios/xcodeproj.dart';
import 'package:flutter_tools/src/ios/xcresult.dart';
import 'package:flutter_tools/src/macos/xcode.dart';
@ -21,12 +22,15 @@ void main() {
required Xcode xcode,
int exitCode = 0,
String stderr = '',
bool useLegacyFlag = true,
}) {
return FakeCommand(
command: <String>[
...xcode.xcrunCommand(),
'xcresulttool',
'get',
if (useLegacyFlag)
'--legacy',
'--path',
tempResultPath,
'--format',
@ -58,6 +62,8 @@ void main() {
required String resultJson,
int exitCode = 0,
String stderr = '',
Version? xcodeVersion = const Version.withText(16, 0, 0, '16.0'),
bool useLegacyFlag = true,
}) {
final FakeProcessManager fakeProcessManager =
FakeProcessManager.list(<FakeCommand>[
@ -68,7 +74,7 @@ void main() {
processManager: fakeProcessManager,
xcodeProjectInterpreter: XcodeProjectInterpreter.test(
processManager: fakeProcessManager,
version: null,
version: xcodeVersion,
),
);
fakeProcessManager.addCommands(
@ -79,6 +85,7 @@ void main() {
xcode: xcode,
exitCode: exitCode,
stderr: stderr,
useLegacyFlag: useLegacyFlag
),
],
);
@ -217,6 +224,19 @@ void main() {
expect(result.parsingErrorMessage, isNull);
});
testWithoutContext(
'correctly parse sample result on < Xcode 16.', () async {
final XCResultGenerator generator = setupGenerator(
resultJson: kSampleResultJsonNoIssues,
xcodeVersion: Version(15, 0, 0),
useLegacyFlag: false,
);
final XCResult result = await generator.generate();
expect(result.issues.length, 0);
expect(result.parseSuccess, isTrue);
expect(result.parsingErrorMessage, isNull);
});
testWithoutContext(
'error: `xcresulttool get` process fail should return an `XCResult` with stderr as `parsingErrorMessage`.',
() async {