@@ -35,31 +35,38 @@ export async function ensureXcodeBuildPhase(fromPath: string) {
3535 `Expected a project.pbxproj file at '${ pbxprojPath } '` ,
3636 ) ;
3737 const xcodeProject = xcode . XcodeProject . open ( pbxprojPath ) ;
38- // Create a build phase on the main target to stage and rename the addon Xcframeworks
39- const mainTarget = xcodeProject . rootObject . getMainAppTarget ( ) ;
40- assert ( mainTarget , "Unable to find a main target" ) ;
41-
42- const existingBuildPhases = mainTarget . props . buildPhases . filter ( ( phase ) =>
43- phase . getDisplayName ( ) . startsWith ( BUILD_PHASE_PREFIX ) ,
38+ // Create a build phase in all application targets to stage and rename the addon frameworks
39+ const applicationTargets = xcodeProject . rootObject . props . targets . filter (
40+ ( target ) =>
41+ xcode . PBXNativeTarget . is ( target ) &&
42+ target . props . productType === "com.apple.product-type.application" ,
4443 ) ;
4544
46- for ( const existingBuildPhase of existingBuildPhases ) {
47- console . log (
48- "Removing existing build phase:" ,
49- chalk . dim ( existingBuildPhase . getDisplayName ( ) ) ,
45+ for ( const target of applicationTargets ) {
46+ console . log ( `Patching '${ target . getDisplayName ( ) } ' target` ) ;
47+
48+ const existingBuildPhases = target . props . buildPhases . filter ( ( phase ) =>
49+ phase . getDisplayName ( ) . startsWith ( BUILD_PHASE_PREFIX ) ,
5050 ) ;
51- existingBuildPhase . removeFromProject ( ) ;
52- }
5351
54- // TODO: Declare input and output files to prevent unnecessary runs
52+ for ( const existingBuildPhase of existingBuildPhases ) {
53+ console . log (
54+ "Removing existing build phase:" ,
55+ chalk . dim ( existingBuildPhase . getDisplayName ( ) ) ,
56+ ) ;
57+ existingBuildPhase . removeFromProject ( ) ;
58+ }
5559
56- mainTarget . createBuildPhase ( xcode . PBXShellScriptBuildPhase , {
57- name : BUILD_PHASE_NAME ,
58- shellScript : [
59- "set -e" ,
60- `'${ process . execPath } ' '${ CLI_PATH } ' link --apple '${ fromPath } '` ,
61- ] . join ( "\n" ) ,
62- } ) ;
60+ // TODO: Declare input and output files to prevent unnecessary runs
61+
62+ target . createBuildPhase ( xcode . PBXShellScriptBuildPhase , {
63+ name : BUILD_PHASE_NAME ,
64+ shellScript : [
65+ "set -e" ,
66+ `'${ process . execPath } ' '${ CLI_PATH } ' link --apple '${ fromPath } '` ,
67+ ] . join ( "\n" ) ,
68+ } ) ;
69+ }
6370
6471 await fs . promises . writeFile (
6572 pbxprojPath ,
0 commit comments