@@ -338,32 +338,43 @@ pbxProject.prototype.addFramework = function(fpath, opt) {
338338 file . fileRef = this . generateUuid ( ) ;
339339 file . target = opt ? opt . target : undefined ;
340340
341- if ( this . hasFile ( file . path ) ) return false ;
342-
343- this . addToPbxBuildFileSection ( file ) ; // PBXBuildFile
344- this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
345- this . addToFrameworksPbxGroup ( file ) ; // PBXGroup
341+ var fileReference = this . hasFile ( file . path ) ;
342+ if ( fileReference ) {
343+ var key = this . getFileKey ( file . path ) ;
344+ file . fileRef = key ;
345+ } else {
346+ this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
347+ this . addToFrameworksPbxGroup ( file ) ; // PBXGroup
348+ }
346349
347350 if ( link ) {
348- this . addToPbxFrameworksBuildPhase ( file ) ; // PBXFrameworksBuildPhase
351+ const buildFileUuid = this . addToPbxFrameworksBuildPhase ( file ) ;
352+ if ( buildFileUuid === file . uuid ) { // PBXFrameworksBuildPhase)
353+ this . addToPbxBuildFileSection ( file ) ; // PBXBuildFile
354+ } else {
355+ file . uuid = buildFileUuid ;
356+ }
349357 }
350358
351359 if ( customFramework ) {
352360 this . addToFrameworkSearchPaths ( file ) ;
353361
354362 if ( embed ) {
355- opt . embed = embed ;
356- var embeddedFile = new pbxFile ( fpath , opt ) ;
357-
358- embeddedFile . uuid = this . generateUuid ( ) ;
359- embeddedFile . fileRef = file . fileRef ;
360-
361- //keeping a separate PBXBuildFile entry for Embed Frameworks
362- this . addToPbxBuildFileSection ( embeddedFile ) ; // PBXBuildFile
363-
364- this . addToPbxEmbedFrameworksBuildPhase ( embeddedFile ) ; // PBXCopyFilesBuildPhase
363+ opt . embed = embed ;
364+ var embeddedFile = new pbxFile ( fpath , opt ) ;
365+
366+ embeddedFile . uuid = this . generateUuid ( ) ;
367+ embeddedFile . fileRef = file . fileRef ;
368+ embeddedFile . target = file . target ;
369+ const embedBuildFileUuid = this . addToPbxEmbedFrameworksBuildPhase ( embeddedFile ) ;
370+ if ( embedBuildFileUuid === embeddedFile . uuid ) { // PBXCopyFilesBuildPhase
371+ //keeping a separate PBXBuildFile entry for Embed Frameworks
372+ this . addToPbxBuildFileSection ( embeddedFile ) ; // PBXBuildFile
373+ } else {
374+ embeddedFile . uuid = embedBuildFileUuid ;
375+ }
365376
366- return embeddedFile ;
377+ return embeddedFile ;
367378 }
368379 }
369380
@@ -856,10 +867,26 @@ pbxProject.prototype.removeFromFrameworksPbxGroup = function(file) {
856867 }
857868}
858869
870+ function getReferenceInPbxBuildFile ( buildFileReferences , fileReference ) {
871+ var buildFileSection = this . pbxBuildFileSection ( ) ;
872+ for ( let buildFileReference of buildFileReferences ) {
873+ if ( buildFileSection [ buildFileReference . value ] && buildFileSection [ buildFileReference . value ] . fileRef === fileReference . fileRef ) {
874+ return buildFileReference . value ;
875+ }
876+ }
877+ }
878+
859879pbxProject . prototype . addToPbxEmbedFrameworksBuildPhase = function ( file ) {
860880 var sources = this . pbxEmbedFrameworksBuildPhaseObj ( file . target ) ;
881+
861882 if ( sources ) {
883+ var referenceUuid = getReferenceInPbxBuildFile . call ( this , sources . files , file )
884+ if ( referenceUuid ) {
885+ return referenceUuid ;
886+ }
887+
862888 sources . files . push ( pbxBuildPhaseObj ( file ) ) ;
889+ return file . uuid ;
863890 }
864891}
865892
@@ -933,7 +960,16 @@ pbxProject.prototype.removeFromPbxResourcesBuildPhase = function(file) {
933960
934961pbxProject . prototype . addToPbxFrameworksBuildPhase = function ( file ) {
935962 var sources = this . pbxFrameworksBuildPhaseObj ( file . target ) ;
936- sources . files . push ( pbxBuildPhaseObj ( file ) ) ;
963+
964+ if ( sources ) {
965+ var frameworkBuildUuid = getReferenceInPbxBuildFile . call ( this , sources . files , file ) ;
966+ if ( frameworkBuildUuid ) {
967+ return frameworkBuildUuid ;
968+ }
969+
970+ sources . files . push ( pbxBuildPhaseObj ( file ) ) ;
971+ return file . uuid ;
972+ }
937973}
938974
939975pbxProject . prototype . removeFromPbxFrameworksBuildPhase = function ( file ) {
@@ -1353,8 +1389,10 @@ pbxProject.prototype.addToFrameworkSearchPaths = function(file) {
13531389 || buildSettings [ 'FRAMEWORK_SEARCH_PATHS' ] === INHERITED ) {
13541390 buildSettings [ 'FRAMEWORK_SEARCH_PATHS' ] = [ INHERITED ] ;
13551391 }
1356-
1357- buildSettings [ 'FRAMEWORK_SEARCH_PATHS' ] . push ( searchPathForFile ( file , this ) ) ;
1392+ var searchPath = searchPathForFile ( file , this ) ;
1393+ if ( buildSettings [ 'FRAMEWORK_SEARCH_PATHS' ] . indexOf ( searchPath ) < 0 ) {
1394+ buildSettings [ 'FRAMEWORK_SEARCH_PATHS' ] . push ( searchPath ) ;
1395+ }
13581396 }
13591397}
13601398
@@ -1565,6 +1603,19 @@ pbxProject.prototype.hasFile = function(filePath) {
15651603 return false ;
15661604}
15671605
1606+ pbxProject . prototype . getFileKey = function ( filePath ) {
1607+ var files = nonComments ( this . pbxFileReferenceSection ( ) ) ,
1608+ file , id ;
1609+ for ( id in files ) {
1610+ file = files [ id ] ;
1611+ if ( file . path == filePath || file . path == ( '"' + filePath + '"' ) ) {
1612+ return id ;
1613+ }
1614+ }
1615+
1616+ return false ;
1617+ }
1618+
15681619pbxProject . prototype . addTarget = function ( name , type , subfolder ) {
15691620
15701621 // Setup uuid and name of new target
0 commit comments