@@ -338,14 +338,19 @@ pbxProject.prototype.addFramework = function(fpath, opt) {
338
338
file . fileRef = this . generateUuid ( ) ;
339
339
file . target = opt ? opt . target : undefined ;
340
340
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
+ }
346
349
347
350
if ( link ) {
348
- this . addToPbxFrameworksBuildPhase ( file ) ; // PBXFrameworksBuildPhase
351
+ if ( this . addToPbxFrameworksBuildPhase ( file ) ) { // PBXFrameworksBuildPhase)
352
+ this . addToPbxBuildFileSection ( file ) ; // PBXBuildFile
353
+ }
349
354
}
350
355
351
356
if ( customFramework ) {
@@ -357,13 +362,13 @@ pbxProject.prototype.addFramework = function(fpath, opt) {
357
362
358
363
embeddedFile . uuid = this . generateUuid ( ) ;
359
364
embeddedFile . fileRef = file . fileRef ;
365
+ embeddedFile . target = file . target ;
360
366
361
- //keeping a separate PBXBuildFile entry for Embed Frameworks
362
- this . addToPbxBuildFileSection ( embeddedFile ) ; // PBXBuildFile
363
-
364
- this . addToPbxEmbedFrameworksBuildPhase ( embeddedFile ) ; // PBXCopyFilesBuildPhase
365
-
366
- return embeddedFile ;
367
+ if ( this . addToPbxEmbedFrameworksBuildPhase ( embeddedFile ) ) { // PBXCopyFilesBuildPhase
368
+ //keeping a separate PBXBuildFile entry for Embed Frameworks
369
+ this . addToPbxBuildFileSection ( embeddedFile ) ; // PBXBuildFile
370
+ return embeddedFile ;
371
+ }
367
372
}
368
373
}
369
374
@@ -856,10 +861,25 @@ pbxProject.prototype.removeFromFrameworksPbxGroup = function(file) {
856
861
}
857
862
}
858
863
864
+ function hasReferenceInPbxBuildFile ( buildFileReferences , fileReference ) {
865
+ var buildFileSection = this . pbxBuildFileSection ( ) ;
866
+ for ( let buildFileReference of buildFileReferences ) {
867
+ if ( buildFileSection [ buildFileReference . value ] && buildFileSection [ buildFileReference . value ] . fileRef === fileReference . fileRef ) {
868
+ return true ;
869
+ }
870
+ }
871
+ }
872
+
859
873
pbxProject . prototype . addToPbxEmbedFrameworksBuildPhase = function ( file ) {
860
874
var sources = this . pbxEmbedFrameworksBuildPhaseObj ( file . target ) ;
875
+
861
876
if ( sources ) {
877
+ if ( hasReferenceInPbxBuildFile . call ( this , sources . files , file ) ) {
878
+ return false ;
879
+ }
880
+
862
881
sources . files . push ( pbxBuildPhaseObj ( file ) ) ;
882
+ return true ;
863
883
}
864
884
}
865
885
@@ -933,7 +953,15 @@ pbxProject.prototype.removeFromPbxResourcesBuildPhase = function(file) {
933
953
934
954
pbxProject . prototype . addToPbxFrameworksBuildPhase = function ( file ) {
935
955
var sources = this . pbxFrameworksBuildPhaseObj ( file . target ) ;
936
- sources . files . push ( pbxBuildPhaseObj ( file ) ) ;
956
+
957
+ if ( sources ) {
958
+ if ( hasReferenceInPbxBuildFile . call ( this , sources . files , file ) ) {
959
+ return false ;
960
+ }
961
+
962
+ sources . files . push ( pbxBuildPhaseObj ( file ) ) ;
963
+ return true ;
964
+ }
937
965
}
938
966
939
967
pbxProject . prototype . removeFromPbxFrameworksBuildPhase = function ( file ) {
@@ -1353,8 +1381,10 @@ pbxProject.prototype.addToFrameworkSearchPaths = function(file) {
1353
1381
|| buildSettings [ 'FRAMEWORK_SEARCH_PATHS' ] === INHERITED ) {
1354
1382
buildSettings [ 'FRAMEWORK_SEARCH_PATHS' ] = [ INHERITED ] ;
1355
1383
}
1356
-
1357
- buildSettings [ 'FRAMEWORK_SEARCH_PATHS' ] . push ( searchPathForFile ( file , this ) ) ;
1384
+ var searchPath = searchPathForFile ( file , this ) ;
1385
+ if ( buildSettings [ 'FRAMEWORK_SEARCH_PATHS' ] . indexOf ( searchPath ) < 0 ) {
1386
+ buildSettings [ 'FRAMEWORK_SEARCH_PATHS' ] . push ( searchPath ) ;
1387
+ }
1358
1388
}
1359
1389
}
1360
1390
@@ -1565,6 +1595,19 @@ pbxProject.prototype.hasFile = function(filePath) {
1565
1595
return false ;
1566
1596
}
1567
1597
1598
+ pbxProject . prototype . getFileKey = function ( filePath ) {
1599
+ var files = nonComments ( this . pbxFileReferenceSection ( ) ) ,
1600
+ file , id ;
1601
+ for ( id in files ) {
1602
+ file = files [ id ] ;
1603
+ if ( file . path == filePath || file . path == ( '"' + filePath + '"' ) ) {
1604
+ return id ;
1605
+ }
1606
+ }
1607
+
1608
+ return false ;
1609
+ }
1610
+
1568
1611
pbxProject . prototype . addTarget = function ( name , type , subfolder ) {
1569
1612
1570
1613
// Setup uuid and name of new target
0 commit comments