@@ -109,11 +109,13 @@ pbxProject.prototype.removePluginFile = function (path, opt) {
109109 return file ;
110110}
111111
112+
112113pbxProject . prototype . addSourceFile = function ( path , opt ) {
114+
113115 var file = this . addPluginFile ( path , opt ) ;
114-
115116 if ( ! file ) return false ;
116117
118+ file . target = opt ? opt . target : undefined ;
117119 file . uuid = this . generateUuid ( ) ;
118120
119121 this . addToPbxBuildFileSection ( file ) ; // PBXBuildFile
@@ -122,8 +124,10 @@ pbxProject.prototype.addSourceFile = function (path, opt) {
122124 return file ;
123125}
124126
127+
125128pbxProject . prototype . removeSourceFile = function ( path , opt ) {
126129 var file = this . removePluginFile ( path , opt )
130+ file . target = opt ? opt . target : undefined ;
127131 this . removeFromPbxBuildFileSection ( file ) ; // PBXBuildFile
128132 this . removeFromPbxSourcesBuildPhase ( file ) ; // PBXSourcesBuildPhase
129133
@@ -152,6 +156,7 @@ pbxProject.prototype.addResourceFile = function (path, opt) {
152156 }
153157
154158 file . uuid = this . generateUuid ( ) ;
159+ file . target = opt ? opt . target : undefined ;
155160
156161 if ( ! opt . plugin ) {
157162 correctForResourcesPath ( file , this ) ;
@@ -171,6 +176,7 @@ pbxProject.prototype.addResourceFile = function (path, opt) {
171176
172177pbxProject . prototype . removeResourceFile = function ( path , opt ) {
173178 var file = new pbxFile ( path , opt ) ;
179+ file . target = opt ? opt . target : undefined ;
174180
175181 correctForResourcesPath ( file , this ) ;
176182
@@ -188,7 +194,9 @@ pbxProject.prototype.addFramework = function (fpath, opt) {
188194 if ( this . hasFile ( file . path ) ) return false ;
189195
190196 file . uuid = this . generateUuid ( ) ;
191- file . fileRef = this . generateUuid ( ) ;
197+ file . fileRef = this . generateUuid ( ) ;
198+ file . target = opt ? opt . target : undefined ;
199+
192200
193201 this . addToPbxBuildFileSection ( file ) ; // PBXBuildFile
194202 this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
@@ -209,6 +217,7 @@ pbxProject.prototype.addFramework = function (fpath, opt) {
209217
210218pbxProject . prototype . removeFramework = function ( fpath , opt ) {
211219 var file = new pbxFile ( fpath , opt ) ;
220+ file . target = opt ? opt . target : undefined ;
212221
213222 this . removeFromPbxBuildFileSection ( file ) ; // PBXBuildFile
214223 this . removeFromPbxFileReferenceSection ( file ) ; // PBXFileReference
@@ -241,6 +250,7 @@ pbxProject.prototype.addStaticLibrary = function (path, opt) {
241250 }
242251
243252 file . uuid = this . generateUuid ( ) ;
253+ file . target = opt ? opt . target : undefined ;
244254
245255 if ( ! opt . plugin ) {
246256 file . fileRef = this . generateUuid ( ) ;
@@ -353,14 +363,14 @@ pbxProject.prototype.removeFromFrameworksPbxGroup = function (file) {
353363 }
354364 }
355365}
356-
357366pbxProject . prototype . addToPbxSourcesBuildPhase = function ( file ) {
358- var sources = this . pbxSourcesBuildPhaseObj ( ) ;
367+ var sources = this . pbxSourcesBuildPhaseObj ( file . target ) ;
359368 sources . files . push ( pbxBuildPhaseObj ( file ) ) ;
360369}
361370
362371pbxProject . prototype . removeFromPbxSourcesBuildPhase = function ( file ) {
363- var sources = this . pbxSourcesBuildPhaseObj ( ) , i ;
372+
373+ var sources = this . pbxSourcesBuildPhaseObj ( file . target ) , i ;
364374 for ( i in sources . files ) {
365375 if ( sources . files [ i ] . comment == longComment ( file ) ) {
366376 sources . files . splice ( i , 1 ) ;
@@ -370,12 +380,12 @@ pbxProject.prototype.removeFromPbxSourcesBuildPhase = function (file) {
370380}
371381
372382pbxProject . prototype . addToPbxResourcesBuildPhase = function ( file ) {
373- var sources = this . pbxResourcesBuildPhaseObj ( ) ;
383+ var sources = this . pbxResourcesBuildPhaseObj ( file . target ) ;
374384 sources . files . push ( pbxBuildPhaseObj ( file ) ) ;
375385}
376386
377387pbxProject . prototype . removeFromPbxResourcesBuildPhase = function ( file ) {
378- var sources = this . pbxResourcesBuildPhaseObj ( ) , i ;
388+ var sources = this . pbxResourcesBuildPhaseObj ( file . target ) , i ;
379389
380390 for ( i in sources . files ) {
381391 if ( sources . files [ i ] . comment == longComment ( file ) ) {
@@ -386,12 +396,12 @@ pbxProject.prototype.removeFromPbxResourcesBuildPhase = function (file) {
386396}
387397
388398pbxProject . prototype . addToPbxFrameworksBuildPhase = function ( file ) {
389- var sources = this . pbxFrameworksBuildPhaseObj ( ) ;
399+ var sources = this . pbxFrameworksBuildPhaseObj ( file . target ) ;
390400 sources . files . push ( pbxBuildPhaseObj ( file ) ) ;
391401}
392402
393403pbxProject . prototype . removeFromPbxFrameworksBuildPhase = function ( file ) {
394- var sources = this . pbxFrameworksBuildPhaseObj ( ) ;
404+ var sources = this . pbxFrameworksBuildPhaseObj ( file . target ) ;
395405 for ( i in sources . files ) {
396406 if ( sources . files [ i ] . comment == longComment ( file ) ) {
397407 sources . files . splice ( i , 1 ) ;
@@ -441,6 +451,14 @@ pbxProject.prototype.pbxFileReferenceSection = function () {
441451 return this . hash . project . objects [ 'PBXFileReference' ] ;
442452}
443453
454+ pbxProject . prototype . pbxNativeTarget = function ( ) {
455+ return this . hash . project . objects [ 'PBXNativeTarget' ] ;
456+ }
457+
458+ pbxProject . prototype . pbxXCConfigurationList = function ( ) {
459+ return this . hash . project . objects [ 'XCConfigurationList' ] ;
460+ }
461+
444462pbxProject . prototype . pbxGroupByName = function ( name ) {
445463 var groups = this . hash . project . objects [ 'PBXGroup' ] ,
446464 key , groupKey ;
@@ -458,39 +476,66 @@ pbxProject.prototype.pbxGroupByName = function (name) {
458476 return null ;
459477}
460478
461- pbxProject . prototype . pbxSourcesBuildPhaseObj = function ( ) {
462- return this . buildPhaseObject ( 'PBXSourcesBuildPhase' , 'Sources' ) ;
479+ pbxProject . prototype . pbxSourcesBuildPhaseObj = function ( target ) {
480+ return this . buildPhaseObject ( 'PBXSourcesBuildPhase' , 'Sources' , target ) ;
463481}
464482
465- pbxProject . prototype . pbxResourcesBuildPhaseObj = function ( ) {
466- return this . buildPhaseObject ( 'PBXResourcesBuildPhase' , 'Resources' ) ;
483+ pbxProject . prototype . pbxResourcesBuildPhaseObj = function ( target ) {
484+ return this . buildPhaseObject ( 'PBXResourcesBuildPhase' , 'Resources' , target ) ;
467485}
468486
469- pbxProject . prototype . pbxFrameworksBuildPhaseObj = function ( ) {
470- return this . buildPhaseObject ( 'PBXFrameworksBuildPhase' , 'Frameworks' ) ;
487+ pbxProject . prototype . pbxFrameworksBuildPhaseObj = function ( target ) {
488+ return this . buildPhaseObject ( 'PBXFrameworksBuildPhase' , 'Frameworks' , target ) ;
471489}
472490
473491pbxProject . prototype . pbxEmbedFrameworksBuildPhaseObj = function ( ) {
474492 return this . buildPhaseObject ( 'PBXCopyFilesBuildPhase' , 'Embed Frameworks' ) ;
475493}
476494
477- pbxProject . prototype . buildPhaseObject = function ( name , group ) {
495+ // Find Build Phase from group/target
496+ pbxProject . prototype . buildPhase = function ( group , target ) {
497+
498+ if ( ! target )
499+ return undefined ;
500+
501+ var nativeTargets = this . pbxNativeTarget ( ) ;
502+ if ( typeof nativeTargets [ target ] == "undefined" )
503+ throw new Error ( "Invalid target: " + target ) ;
504+
505+ var nativeTarget = nativeTargets [ target ] ;
506+ var buildPhases = nativeTarget . buildPhases ;
507+ for ( var i in buildPhases )
508+ {
509+ var buildPhase = buildPhases [ i ] ;
510+ if ( buildPhase . comment == group )
511+ return buildPhase . value + "_comment" ;
512+ }
513+ }
514+
515+ pbxProject . prototype . buildPhaseObject = function ( name , group , target ) {
478516 var section = this . hash . project . objects [ name ] ,
479517 obj , sectionKey , key ;
480518
519+ var buildPhase = this . buildPhase ( group , target ) ;
520+
481521 for ( key in section ) {
522+
482523 // only look for comments
483524 if ( ! COMMENT_KEY . test ( key ) ) continue ;
484-
525+
526+ // select the proper buildPhase
527+ if ( buildPhase && buildPhase != key )
528+ continue ;
529+
485530 if ( section [ key ] == group ) {
486- sectionKey = key . split ( COMMENT_KEY ) [ 0 ] ;
531+ sectionKey = key . split ( COMMENT_KEY ) [ 0 ] ;
487532 return section [ sectionKey ] ;
488533 }
489- }
490-
534+ }
491535 return null ;
492536}
493537
538+
494539pbxProject . prototype . updateBuildProperty = function ( prop , value ) {
495540 var config = this . pbxXCBuildConfigurationSection ( ) ;
496541 propReplace ( config , prop , value ) ;
@@ -625,6 +670,7 @@ pbxProject.prototype.removeFromHeaderSearchPaths = function (file) {
625670
626671 }
627672}
673+
628674pbxProject . prototype . addToHeaderSearchPaths = function ( file ) {
629675 var configurations = nonComments ( this . pbxXCBuildConfigurationSection ( ) ) ,
630676 INHERITED = '"$(inherited)"' ,
@@ -647,6 +693,7 @@ pbxProject.prototype.addToHeaderSearchPaths = function (file) {
647693 }
648694 }
649695}
696+
650697// a JS getter. hmmm
651698pbxProject . prototype . __defineGetter__ ( "productName" , function ( ) {
652699 var configurations = nonComments ( this . pbxXCBuildConfigurationSection ( ) ) ,
0 commit comments