From c175cf87a6a3d797fdc3f81cbd54419f639cd3d9 Mon Sep 17 00:00:00 2001 From: Victoria Ashworth <15619084+vashworth@users.noreply.github.com> Date: Thu, 31 Aug 2023 09:57:07 -0500 Subject: [PATCH] Ignore macOS Cocoapods linting failure on DT_TOOLCHAIN_DIR error (#133588) Xcode 15 introduced an [error](https://github.com/flutter/flutter/issues/132755) into Cocoapods when building macOS apps. When `pod lib lint` runs, it under the covers is building the app with `xcodebuild`, which is why this error occurs when linting. A fix has been made in Cocoapods, but is not in an official release so we can't upgrade Cocoapods yet. This is to temporarily ignore lint failure due to that error. Fixes https://github.com/flutter/flutter/issues/132980. Tracking issue to upgrade Cocoapods when fix is in a release: https://github.com/flutter/flutter/issues/133584 Since Xcode 15 isn't in CI, I tested it in a one-off led test: * [Pre-fix failure](https://chromium-swarm.appspot.com/task?id=6431f228ecf98e10) * [Post-fix success](https://chromium-swarm.appspot.com/task?id=645ba7ebdab97210) --- dev/devicelab/bin/tasks/plugin_lint_mac.dart | 50 ++++++++++++++------ dev/devicelab/lib/framework/utils.dart | 3 +- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/dev/devicelab/bin/tasks/plugin_lint_mac.dart b/dev/devicelab/bin/tasks/plugin_lint_mac.dart index 79015aa392..f4a8f0faa8 100644 --- a/dev/devicelab/bin/tasks/plugin_lint_mac.dart +++ b/dev/devicelab/bin/tasks/plugin_lint_mac.dart @@ -46,12 +46,9 @@ Future main() async { ); final String macosintegrationTestPodspec = path.join(integrationTestPackage, 'integration_test_macos', 'macos', 'integration_test_macos.podspec'); - await exec( - 'pod', + await _tryMacOSLint( + macosintegrationTestPodspec, [ - 'lib', - 'lint', - macosintegrationTestPodspec, '--verbose', // TODO(cyanglaz): remove allow-warnings when https://github.com/flutter/flutter/issues/125812 is fixed. // https://github.com/flutter/flutter/issues/125812 @@ -164,12 +161,9 @@ Future main() async { final String macOSPodspecPath = path.join(swiftPluginPath, 'macos', '$swiftPluginName.podspec'); await inDirectory(tempDir, () async { - await exec( - 'pod', + await _tryMacOSLint( + macOSPodspecPath, [ - 'lib', - 'lint', - macOSPodspecPath, '--allow-warnings', '--verbose', ], @@ -179,12 +173,9 @@ Future main() async { section('Lint Swift macOS podspec plugin as library'); await inDirectory(tempDir, () async { - await exec( - 'pod', + await _tryMacOSLint( + macOSPodspecPath, [ - 'lib', - 'lint', - macOSPodspecPath, '--allow-warnings', '--use-libraries', '--verbose', @@ -533,3 +524,32 @@ void _validateMacOSPodfile(String appPath) { 'macos', )); } + +Future _tryMacOSLint( + String podspecPath, + List extraArguments, +) async { + final StringBuffer lintStdout = StringBuffer(); + try { + await eval( + 'pod', + [ + 'lib', + 'lint', + podspecPath, + ...extraArguments, + ], + stdout: lintStdout, + ); + } on BuildFailedError { + // Temporarily ignore errors due to DT_TOOLCHAIN_DIR if it's the only error. + // This error was introduced with Xcode 15. Fix was made in Cocoapods, but + // is not in an official release yet. + // TODO(vashworth): Stop ignoring when https://github.com/flutter/flutter/issues/133584 is complete. + final String lintResult = lintStdout.toString(); + if (!(lintResult.contains('error: DT_TOOLCHAIN_DIR cannot be used to evaluate') && + lintResult.contains('did not pass validation, due to 1 error'))) { + rethrow; + } + } +} diff --git a/dev/devicelab/lib/framework/utils.dart b/dev/devicelab/lib/framework/utils.dart index 8b97890ac2..40b5820c21 100644 --- a/dev/devicelab/lib/framework/utils.dart +++ b/dev/devicelab/lib/framework/utils.dart @@ -430,11 +430,12 @@ Future eval( Map? environment, bool canFail = false, // as in, whether failures are ok. False means that they are fatal. String? workingDirectory, + StringBuffer? stdout, // if not null, the stdout will be written here StringBuffer? stderr, // if not null, the stderr will be written here bool printStdout = true, bool printStderr = true, }) async { - final StringBuffer output = StringBuffer(); + final StringBuffer output = stdout ?? StringBuffer(); await _execute( executable, arguments,