@@ -108,11 +108,13 @@ pbxProject.prototype.removePluginFile = function (path, opt) {
108108 return file ;
109109}
110110
111+
111112pbxProject . prototype . addSourceFile = function ( path , opt ) {
113+
112114 var file = this . addPluginFile ( path , opt ) ;
113-
114115 if ( ! file ) return false ;
115116
117+ file . target = opt ? opt . target : undefined ;
116118 file . uuid = this . generateUuid ( ) ;
117119
118120 this . addToPbxBuildFileSection ( file ) ; // PBXBuildFile
@@ -121,8 +123,10 @@ pbxProject.prototype.addSourceFile = function (path, opt) {
121123 return file ;
122124}
123125
126+
124127pbxProject . prototype . removeSourceFile = function ( path , opt ) {
125128 var file = this . removePluginFile ( path , opt )
129+ file . target = opt ? opt . target : undefined ;
126130 this . removeFromPbxBuildFileSection ( file ) ; // PBXBuildFile
127131 this . removeFromPbxSourcesBuildPhase ( file ) ; // PBXSourcesBuildPhase
128132
@@ -151,6 +155,7 @@ pbxProject.prototype.addResourceFile = function (path, opt) {
151155 }
152156
153157 file . uuid = this . generateUuid ( ) ;
158+ file . target = opt ? opt . target : undefined ;
154159
155160 if ( ! opt . plugin ) {
156161 correctForResourcesPath ( file , this ) ;
@@ -170,6 +175,7 @@ pbxProject.prototype.addResourceFile = function (path, opt) {
170175
171176pbxProject . prototype . removeResourceFile = function ( path , opt ) {
172177 var file = new pbxFile ( path , opt ) ;
178+ file . target = opt ? opt . target : undefined ;
173179
174180 correctForResourcesPath ( file , this ) ;
175181
@@ -187,7 +193,9 @@ pbxProject.prototype.addFramework = function (fpath, opt) {
187193 if ( this . hasFile ( file . path ) ) return false ;
188194
189195 file . uuid = this . generateUuid ( ) ;
190- file . fileRef = this . generateUuid ( ) ;
196+ file . fileRef = this . generateUuid ( ) ;
197+ file . target = opt ? opt . target : undefined ;
198+
191199
192200 this . addToPbxBuildFileSection ( file ) ; // PBXBuildFile
193201 this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
@@ -203,6 +211,7 @@ pbxProject.prototype.addFramework = function (fpath, opt) {
203211
204212pbxProject . prototype . removeFramework = function ( fpath , opt ) {
205213 var file = new pbxFile ( fpath , opt ) ;
214+ file . target = opt ? opt . target : undefined ;
206215
207216 this . removeFromPbxBuildFileSection ( file ) ; // PBXBuildFile
208217 this . removeFromPbxFileReferenceSection ( file ) ; // PBXFileReference
@@ -230,6 +239,7 @@ pbxProject.prototype.addStaticLibrary = function (path, opt) {
230239 }
231240
232241 file . uuid = this . generateUuid ( ) ;
242+ file . target = opt ? opt . target : undefined ;
233243
234244 if ( ! opt . plugin ) {
235245 file . fileRef = this . generateUuid ( ) ;
@@ -341,14 +351,14 @@ pbxProject.prototype.removeFromFrameworksPbxGroup = function (file) {
341351 }
342352 }
343353}
344-
345354pbxProject . prototype . addToPbxSourcesBuildPhase = function ( file ) {
346- var sources = this . pbxSourcesBuildPhaseObj ( ) ;
355+ var sources = this . pbxSourcesBuildPhaseObj ( file . target ) ;
347356 sources . files . push ( pbxBuildPhaseObj ( file ) ) ;
348357}
349358
350359pbxProject . prototype . removeFromPbxSourcesBuildPhase = function ( file ) {
351- var sources = this . pbxSourcesBuildPhaseObj ( ) , i ;
360+
361+ var sources = this . pbxSourcesBuildPhaseObj ( file . target ) , i ;
352362 for ( i in sources . files ) {
353363 if ( sources . files [ i ] . comment == longComment ( file ) ) {
354364 sources . files . splice ( i , 1 ) ;
@@ -358,12 +368,12 @@ pbxProject.prototype.removeFromPbxSourcesBuildPhase = function (file) {
358368}
359369
360370pbxProject . prototype . addToPbxResourcesBuildPhase = function ( file ) {
361- var sources = this . pbxResourcesBuildPhaseObj ( ) ;
371+ var sources = this . pbxResourcesBuildPhaseObj ( file . target ) ;
362372 sources . files . push ( pbxBuildPhaseObj ( file ) ) ;
363373}
364374
365375pbxProject . prototype . removeFromPbxResourcesBuildPhase = function ( file ) {
366- var sources = this . pbxResourcesBuildPhaseObj ( ) , i ;
376+ var sources = this . pbxResourcesBuildPhaseObj ( file . target ) , i ;
367377
368378 for ( i in sources . files ) {
369379 if ( sources . files [ i ] . comment == longComment ( file ) ) {
@@ -374,12 +384,12 @@ pbxProject.prototype.removeFromPbxResourcesBuildPhase = function (file) {
374384}
375385
376386pbxProject . prototype . addToPbxFrameworksBuildPhase = function ( file ) {
377- var sources = this . pbxFrameworksBuildPhaseObj ( ) ;
387+ var sources = this . pbxFrameworksBuildPhaseObj ( file . target ) ;
378388 sources . files . push ( pbxBuildPhaseObj ( file ) ) ;
379389}
380390
381391pbxProject . prototype . removeFromPbxFrameworksBuildPhase = function ( file ) {
382- var sources = this . pbxFrameworksBuildPhaseObj ( ) ;
392+ var sources = this . pbxFrameworksBuildPhaseObj ( file . target ) ;
383393 for ( i in sources . files ) {
384394 if ( sources . files [ i ] . comment == longComment ( file ) ) {
385395 sources . files . splice ( i , 1 ) ;
@@ -401,6 +411,14 @@ pbxProject.prototype.pbxFileReferenceSection = function () {
401411 return this . hash . project . objects [ 'PBXFileReference' ] ;
402412}
403413
414+ pbxProject . prototype . pbxNativeTarget = function ( ) {
415+ return this . hash . project . objects [ 'PBXNativeTarget' ] ;
416+ }
417+
418+ pbxProject . prototype . pbxXCConfigurationList = function ( ) {
419+ return this . hash . project . objects [ 'XCConfigurationList' ] ;
420+ }
421+
404422pbxProject . prototype . pbxGroupByName = function ( name ) {
405423 var groups = this . hash . project . objects [ 'PBXGroup' ] ,
406424 key , groupKey ;
@@ -418,35 +436,62 @@ pbxProject.prototype.pbxGroupByName = function (name) {
418436 return null ;
419437}
420438
421- pbxProject . prototype . pbxSourcesBuildPhaseObj = function ( ) {
422- return this . buildPhaseObject ( 'PBXSourcesBuildPhase' , 'Sources' ) ;
439+ pbxProject . prototype . pbxSourcesBuildPhaseObj = function ( target ) {
440+ return this . buildPhaseObject ( 'PBXSourcesBuildPhase' , 'Sources' , target ) ;
423441}
424442
425- pbxProject . prototype . pbxResourcesBuildPhaseObj = function ( ) {
426- return this . buildPhaseObject ( 'PBXResourcesBuildPhase' , 'Resources' ) ;
443+ pbxProject . prototype . pbxResourcesBuildPhaseObj = function ( target ) {
444+ return this . buildPhaseObject ( 'PBXResourcesBuildPhase' , 'Resources' , target ) ;
427445}
428446
429- pbxProject . prototype . pbxFrameworksBuildPhaseObj = function ( ) {
430- return this . buildPhaseObject ( 'PBXFrameworksBuildPhase' , 'Frameworks' ) ;
447+ pbxProject . prototype . pbxFrameworksBuildPhaseObj = function ( target ) {
448+ return this . buildPhaseObject ( 'PBXFrameworksBuildPhase' , 'Frameworks' , target ) ;
431449}
432450
433- pbxProject . prototype . buildPhaseObject = function ( name , group ) {
451+ // Find Build Phase from group/target
452+ pbxProject . prototype . buildPhase = function ( group , target ) {
453+
454+ if ( ! target )
455+ return undefined ;
456+
457+ var nativeTargets = this . pbxNativeTarget ( ) ;
458+ if ( typeof nativeTargets [ target ] == "undefined" )
459+ throw new Error ( "Invalid target: " + target ) ;
460+
461+ var nativeTarget = nativeTargets [ target ] ;
462+ var buildPhases = nativeTarget . buildPhases ;
463+ for ( var i in buildPhases )
464+ {
465+ var buildPhase = buildPhases [ i ] ;
466+ if ( buildPhase . comment == group )
467+ return buildPhase . value + "_comment" ;
468+ }
469+ }
470+
471+ pbxProject . prototype . buildPhaseObject = function ( name , group , target ) {
434472 var section = this . hash . project . objects [ name ] ,
435473 obj , sectionKey , key ;
436474
475+ var buildPhase = this . buildPhase ( group , target ) ;
476+
437477 for ( key in section ) {
478+
438479 // only look for comments
439480 if ( ! COMMENT_KEY . test ( key ) ) continue ;
440-
481+
482+ // select the proper buildPhase
483+ if ( buildPhase && buildPhase != key )
484+ continue ;
485+
441486 if ( section [ key ] == group ) {
442- sectionKey = key . split ( COMMENT_KEY ) [ 0 ] ;
487+ sectionKey = key . split ( COMMENT_KEY ) [ 0 ] ;
443488 return section [ sectionKey ] ;
444489 }
445- }
446-
490+ }
447491 return null ;
448492}
449493
494+
450495pbxProject . prototype . updateBuildProperty = function ( prop , value ) {
451496 var config = this . pbxXCBuildConfigurationSection ( ) ;
452497 propReplace ( config , prop , value ) ;
0 commit comments