From f7bd20fc090bb1a5983e07e0c7f0d8b79f361fef Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Tue, 7 Dec 2021 15:29:03 -0800 Subject: [PATCH] Detect additional ARM ffi CocoaPods error (#94385) --- .../lib/src/macos/cocoapods.dart | 3 +- .../general.shard/macos/cocoapods_test.dart | 82 ++++++++++--------- 2 files changed, 45 insertions(+), 40 deletions(-) diff --git a/packages/flutter_tools/lib/src/macos/cocoapods.dart b/packages/flutter_tools/lib/src/macos/cocoapods.dart index 3ee17c97e9..8e7a08f62c 100644 --- a/packages/flutter_tools/lib/src/macos/cocoapods.dart +++ b/packages/flutter_tools/lib/src/macos/cocoapods.dart @@ -360,8 +360,7 @@ class CocoaPods { ' pod repo update\n', emphasis: true, ); - } else if (stdout.contains('Init_ffi_c') && - stdout.contains('symbol not found') && + } else if (stdout.contains('ffi_c.bundle') && stdout.contains('LoadError') && _operatingSystemUtils.hostPlatform == HostPlatform.darwin_arm) { // https://github.com/flutter/flutter/issues/70796 UsageEvent( diff --git a/packages/flutter_tools/test/general.shard/macos/cocoapods_test.dart b/packages/flutter_tools/test/general.shard/macos/cocoapods_test.dart index d5e40d8ae1..a27a1cc7a2 100644 --- a/packages/flutter_tools/test/general.shard/macos/cocoapods_test.dart +++ b/packages/flutter_tools/test/general.shard/macos/cocoapods_test.dart @@ -491,46 +491,52 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by ); }); - testUsingContext('ffi failure on ARM macOS prompts gem install', () async { - final FlutterProject projectUnderTest = setupProjectUnderTest(); - pretendPodIsInstalled(); - pretendPodVersionIs('1.10.0'); - fileSystem.file(fileSystem.path.join('project', 'ios', 'Podfile')) - ..createSync() - ..writeAsStringSync('Existing Podfile'); + final Map possibleErrors = { + 'symbol not found': 'LoadError - dlsym(0x7fbbeb6837d0, Init_ffi_c): symbol not found - /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/lib/ffi_c.bundle', + 'incompatible architecture': "LoadError - (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/usr/lib/ffi_c.bundle' (no such file) - /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.4/lib/ffi_c.bundle", + }; + possibleErrors.forEach((String errorName, String cocoaPodsError) { + testUsingContext('ffi $errorName failure on ARM macOS prompts gem install', () async { + final FlutterProject projectUnderTest = setupProjectUnderTest(); + pretendPodIsInstalled(); + pretendPodVersionIs('1.10.0'); + fileSystem.file(fileSystem.path.join('project', 'ios', 'Podfile')) + ..createSync() + ..writeAsStringSync('Existing Podfile'); - fakeProcessManager.addCommands([ - const FakeCommand( - command: ['pod', 'install', '--verbose'], - workingDirectory: 'project/ios', - environment: { - 'COCOAPODS_DISABLE_STATS': 'true', - 'LANG': 'en_US.UTF-8', - }, - exitCode: 1, - stdout: 'LoadError - dlsym(0x7fbbeb6837d0, Init_ffi_c): symbol not found - /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/lib/ffi_c.bundle', - ), - const FakeCommand( - command: ['which', 'sysctl'], - ), - const FakeCommand( - command: ['sysctl', 'hw.optional.arm64'], - stdout: 'hw.optional.arm64: 1', - ), - ]); + fakeProcessManager.addCommands([ + FakeCommand( + command: const ['pod', 'install', '--verbose'], + workingDirectory: 'project/ios', + environment: const { + 'COCOAPODS_DISABLE_STATS': 'true', + 'LANG': 'en_US.UTF-8', + }, + exitCode: 1, + stdout: cocoaPodsError, + ), + const FakeCommand( + command: ['which', 'sysctl'], + ), + const FakeCommand( + command: ['sysctl', 'hw.optional.arm64'], + stdout: 'hw.optional.arm64: 1', + ), + ]); - await expectToolExitLater( - cocoaPodsUnderTest.processPods( - xcodeProject: projectUnderTest.ios, - buildMode: BuildMode.debug, - ), - equals('Error running pod install'), - ); - expect( - logger.errorText, - contains('set up CocoaPods for ARM macOS'), - ); - expect(usage.events, contains(const TestUsageEvent('pod-install-failure', 'arm-ffi'))); + await expectToolExitLater( + cocoaPodsUnderTest.processPods( + xcodeProject: projectUnderTest.ios, + buildMode: BuildMode.debug, + ), + equals('Error running pod install'), + ); + expect( + logger.errorText, + contains('set up CocoaPods for ARM macOS'), + ); + expect(usage.events, contains(const TestUsageEvent('pod-install-failure', 'arm-ffi'))); + }); }); testUsingContext('ffi failure on x86 macOS does not prompt gem install', () async {