@@ -883,10 +883,10 @@ end`;
883883 options ?: any ,
884884 execOptions ?: IExecOptions ,
885885 ) : Promise < any > => {
886- if ( command === "arch -x86_64 pod --version") {
887- // This is the command that is used to check if cocoapods is installed under Rosetta 2
886+ if ( command . endsWith ( " pod --version") ) {
887+ // Native CocoaPods is available.
888888 return {
889- stdout : "Bad CPU type in executable " ,
889+ stdout : "1.17.0 " ,
890890 stderr : "" ,
891891 exitCode : 0 ,
892892 } ;
@@ -935,6 +935,69 @@ end`;
935935 } ) ;
936936 } ) ;
937937
938+ describe ( "on Apple Silicon" , ( ) => {
939+ let platform : PropertyDescriptor ;
940+ let arch : PropertyDescriptor ;
941+ beforeEach ( ( ) => {
942+ platform = Object . getOwnPropertyDescriptor ( process , "platform" ) ;
943+ arch = Object . getOwnPropertyDescriptor ( process , "arch" ) ;
944+ Object . defineProperty ( process , "platform" , { value : "darwin" } ) ;
945+ Object . defineProperty ( process , "arch" , { value : "arm64" } ) ;
946+ } ) ;
947+ afterEach ( ( ) => {
948+ Object . defineProperty ( process , "platform" , platform ) ;
949+ Object . defineProperty ( process , "arch" , arch ) ;
950+ } ) ;
951+ [ "pod" , "sandbox-pod" ] . forEach ( ( podTool ) => {
952+ [ false , true ] . forEach ( ( needsRosetta ) => {
953+ it ( `uses ${ podTool } ${ needsRosetta ? "through Rosetta after a native CPU failure" : "natively even when Rosetta is installed" } ` , async ( ) => {
954+ testInjector . resolve < IConfiguration > ( "config" ) . USE_POD_SANDBOX =
955+ podTool === "sandbox-pod" ;
956+ const childProcess =
957+ testInjector . resolve < IChildProcess > ( "childProcess" ) ;
958+ const probes : string [ ] = [ ] ;
959+ childProcess . exec = async ( command : string ) : Promise < any > => {
960+ probes . push ( command ) ;
961+ if ( needsRosetta ) {
962+ throw new Error ( "Bad CPU type in executable" ) ;
963+ }
964+ return { stdout : "1.17.0" , stderr : "" , exitCode : 0 } ;
965+ } ;
966+ childProcess . spawnFromEvent = async (
967+ command : string ,
968+ args : string [ ] ,
969+ ) : Promise < ISpawnResult > => {
970+ assert . equal ( command , needsRosetta ? "arch" : podTool ) ;
971+ assert . deepStrictEqual (
972+ args ,
973+ needsRosetta ? [ "-x86_64" , podTool , "install" ] : [ "install" ] ,
974+ ) ;
975+ return { stdout : "" , stderr : "" , exitCode : 0 } ;
976+ } ;
977+ await cocoapodsService . executePodInstall (
978+ projectRoot ,
979+ xcodeProjPath ,
980+ ) ;
981+ assert . deepStrictEqual ( probes , [ `${ podTool } --version` ] ) ;
982+ } ) ;
983+ } ) ;
984+ } ) ;
985+ it ( "preserves unrelated native probe failures" , async ( ) => {
986+ const childProcess =
987+ testInjector . resolve < IChildProcess > ( "childProcess" ) ;
988+ childProcess . exec = async ( ) : Promise < any > => {
989+ throw new Error ( "pod: command not found" ) ;
990+ } ;
991+ childProcess . spawnFromEvent = async ( ) : Promise < ISpawnResult > => {
992+ throw new Error ( "unexpected Rosetta fallback" ) ;
993+ } ;
994+ await assert . isRejected (
995+ cocoapodsService . executePodInstall ( projectRoot , xcodeProjPath ) ,
996+ "pod: command not found" ,
997+ ) ;
998+ } ) ;
999+ } ) ;
1000+
9381001 it ( "calls pod install spawnFromEvent with correct arguments" , async ( ) => {
9391002 const childProcess = testInjector . resolve < IChildProcess > ( "childProcess" ) ;
9401003 let commandCalled = "" ;
0 commit comments