@@ -820,10 +820,10 @@ end`,
820820 options ?: any ,
821821 execOptions ?: IExecOptions
822822 ) : Promise < any > => {
823- if ( command === "arch -x86_64 pod --version") {
824- // This is the command that is used to check if cocoapods is installed under Rosetta 2
823+ if ( command . endsWith ( " pod --version") ) {
824+ // Native CocoaPods is available.
825825 return {
826- stdout : "Bad CPU type in executable " ,
826+ stdout : "1.17.0 " ,
827827 stderr : "" ,
828828 exitCode : 0 ,
829829 } ;
@@ -872,6 +872,69 @@ end`,
872872 } ) ;
873873 } ) ;
874874
875+ describe ( "on Apple Silicon" , ( ) => {
876+ let platform : PropertyDescriptor ;
877+ let arch : PropertyDescriptor ;
878+ beforeEach ( ( ) => {
879+ platform = Object . getOwnPropertyDescriptor ( process , "platform" ) ;
880+ arch = Object . getOwnPropertyDescriptor ( process , "arch" ) ;
881+ Object . defineProperty ( process , "platform" , { value : "darwin" } ) ;
882+ Object . defineProperty ( process , "arch" , { value : "arm64" } ) ;
883+ } ) ;
884+ afterEach ( ( ) => {
885+ Object . defineProperty ( process , "platform" , platform ) ;
886+ Object . defineProperty ( process , "arch" , arch ) ;
887+ } ) ;
888+ [ "pod" , "sandbox-pod" ] . forEach ( ( podTool ) => {
889+ [ false , true ] . forEach ( ( needsRosetta ) => {
890+ it ( `uses ${ podTool } ${ needsRosetta ? "through Rosetta after a native CPU failure" : "natively even when Rosetta is installed" } ` , async ( ) => {
891+ testInjector . resolve < IConfiguration > ( "config" ) . USE_POD_SANDBOX =
892+ podTool === "sandbox-pod" ;
893+ const childProcess =
894+ testInjector . resolve < IChildProcess > ( "childProcess" ) ;
895+ const probes : string [ ] = [ ] ;
896+ childProcess . exec = async ( command : string ) : Promise < any > => {
897+ probes . push ( command ) ;
898+ if ( needsRosetta ) {
899+ throw new Error ( "Bad CPU type in executable" ) ;
900+ }
901+ return { stdout : "1.17.0" , stderr : "" , exitCode : 0 } ;
902+ } ;
903+ childProcess . spawnFromEvent = async (
904+ command : string ,
905+ args : string [ ] ,
906+ ) : Promise < ISpawnResult > => {
907+ assert . equal ( command , needsRosetta ? "arch" : podTool ) ;
908+ assert . deepStrictEqual (
909+ args ,
910+ needsRosetta ? [ "-x86_64" , podTool , "install" ] : [ "install" ] ,
911+ ) ;
912+ return { stdout : "" , stderr : "" , exitCode : 0 } ;
913+ } ;
914+ await cocoapodsService . executePodInstall (
915+ projectRoot ,
916+ xcodeProjPath ,
917+ ) ;
918+ assert . deepStrictEqual ( probes , [ `${ podTool } --version` ] ) ;
919+ } ) ;
920+ } ) ;
921+ } ) ;
922+ it ( "preserves unrelated native probe failures" , async ( ) => {
923+ const childProcess =
924+ testInjector . resolve < IChildProcess > ( "childProcess" ) ;
925+ childProcess . exec = async ( ) : Promise < any > => {
926+ throw new Error ( "pod: command not found" ) ;
927+ } ;
928+ childProcess . spawnFromEvent = async ( ) : Promise < ISpawnResult > => {
929+ throw new Error ( "unexpected Rosetta fallback" ) ;
930+ } ;
931+ await assert . isRejected (
932+ cocoapodsService . executePodInstall ( projectRoot , xcodeProjPath ) ,
933+ "pod: command not found" ,
934+ ) ;
935+ } ) ;
936+ } ) ;
937+
875938 it ( "calls pod install spawnFromEvent with correct arguments" , async ( ) => {
876939 const childProcess = testInjector . resolve < IChildProcess > ( "childProcess" ) ;
877940 let commandCalled = "" ;
0 commit comments