@@ -338,32 +338,43 @@ 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
+ const buildFileUuid = this . addToPbxFrameworksBuildPhase ( file ) ;
352
+ if ( buildFileUuid === file . uuid ) { // PBXFrameworksBuildPhase)
353
+ this . addToPbxBuildFileSection ( file ) ; // PBXBuildFile
354
+ } else {
355
+ file . uuid = buildFileUuid ;
356
+ }
349
357
}
350
358
351
359
if ( customFramework ) {
352
360
this . addToFrameworkSearchPaths ( file ) ;
353
361
354
362
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
+ }
365
376
366
- return embeddedFile ;
377
+ return embeddedFile ;
367
378
}
368
379
}
369
380
@@ -856,10 +867,26 @@ pbxProject.prototype.removeFromFrameworksPbxGroup = function(file) {
856
867
}
857
868
}
858
869
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
+
859
879
pbxProject . prototype . addToPbxEmbedFrameworksBuildPhase = function ( file ) {
860
880
var sources = this . pbxEmbedFrameworksBuildPhaseObj ( file . target ) ;
881
+
861
882
if ( sources ) {
883
+ var referenceUuid = getReferenceInPbxBuildFile . call ( this , sources . files , file )
884
+ if ( referenceUuid ) {
885
+ return referenceUuid ;
886
+ }
887
+
862
888
sources . files . push ( pbxBuildPhaseObj ( file ) ) ;
889
+ return file . uuid ;
863
890
}
864
891
}
865
892
@@ -933,7 +960,16 @@ pbxProject.prototype.removeFromPbxResourcesBuildPhase = function(file) {
933
960
934
961
pbxProject . prototype . addToPbxFrameworksBuildPhase = function ( file ) {
935
962
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
+ }
937
973
}
938
974
939
975
pbxProject . prototype . removeFromPbxFrameworksBuildPhase = function ( file ) {
@@ -1353,8 +1389,10 @@ pbxProject.prototype.addToFrameworkSearchPaths = function(file) {
1353
1389
|| buildSettings [ 'FRAMEWORK_SEARCH_PATHS' ] === INHERITED ) {
1354
1390
buildSettings [ 'FRAMEWORK_SEARCH_PATHS' ] = [ INHERITED ] ;
1355
1391
}
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
+ }
1358
1396
}
1359
1397
}
1360
1398
@@ -1565,6 +1603,19 @@ pbxProject.prototype.hasFile = function(filePath) {
1565
1603
return false ;
1566
1604
}
1567
1605
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
+
1568
1619
pbxProject . prototype . addTarget = function ( name , type , subfolder ) {
1569
1620
1570
1621
// Setup uuid and name of new target
0 commit comments