@@ -23,9 +23,10 @@ var util = require('util'),
2323 fork = require ( 'child_process' ) . fork ,
2424 pbxWriter = require ( './pbxWriter' ) ,
2525 pbxFile = require ( './pbxFile' ) . pbxFile ,
26- isSourceOrHeaderFileType = require ( './pbxFile' ) . isSourceOrHeaderFileType ,
26+ isSourceFileType = require ( './pbxFile' ) . isSourceFileType ,
2727 isHeaderFileType = require ( './pbxFile' ) . isHeaderFileType ,
2828 isResource = require ( './pbxFile' ) . isResource ,
29+ isEntitlement = require ( './pbxFile' ) . isEntitlement
2930 fs = require ( 'fs' ) ,
3031 parser = require ( './parser/pbxproj' ) ,
3132 plist = require ( 'simple-plist' ) ,
@@ -560,13 +561,12 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
560561 var srcRootPath = $path . dirname ( $path . dirname ( this . filepath ) ) ;
561562 var relativePath = $path . relative ( srcRootPath , filePath ) ;
562563 var file = new pbxFile ( opt . filesRelativeToProject ? relativePath : filePath ) ;
563-
564+ file . uuid = this . generateUuid ( ) ;
565+ file . fileRef = this . generateUuid ( ) ;
564566 if ( opt . target ) {
565567 file . target = opt . target ;
566568 }
567-
568569 if ( fs . existsSync ( filePath ) && fs . lstatSync ( filePath ) . isDirectory ( ) ) {
569- file . uuid = this . generateUuid ( ) ;
570570 file . fileRef = file . uuid ;
571571 var files = fs . readdirSync ( filePath ) . map ( p => $path . join ( filePath , p ) ) ;
572572 if ( $path . extname ( filePath ) === ".lproj" ) {
@@ -584,27 +584,21 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
584584 pbxGroup . children . push ( pbxGroupChild ( file ) ) ;
585585 this . addPbxGroup ( files , $path . basename ( filePath ) , filePath , null , { uuid : file . uuid , filesRelativeToProject : opt . filesRelativeToProject , target : opt . target } ) ;
586586 }
587- } else if ( isSourceOrHeaderFileType ( file . lastKnownFileType ) ) {
588- file . uuid = this . generateUuid ( ) ;
589- file . fileRef = this . generateUuid ( ) ;
590- this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
591- this . addToPbxBuildFileSection ( file ) ; // PBXBuildFile
592- if ( ! isHeaderFileType ( file . lastKnownFileType ) ) {
593- this . addToPbxSourcesBuildPhase ( file ) ;
594- }
595- pbxGroup . children . push ( pbxGroupChild ( file ) ) ;
596- } else if ( isResource ( file . group ) ) {
597- file . uuid = this . generateUuid ( ) ;
598- file . fileRef = this . generateUuid ( ) ;
599- this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
600- this . addToPbxResourcesBuildPhase ( file )
601- pbxGroup . children . push ( pbxGroupChild ( file ) ) ;
602587 } else {
603- file . uuid = this . generateUuid ( ) ;
604- file . fileRef = this . generateUuid ( ) ;
605588 this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
606- this . addToPbxBuildFileSection ( file ) ;
607589 pbxGroup . children . push ( pbxGroupChild ( file ) ) ;
590+ if ( isHeaderFileType ( file . lastKnownFileType ) ) {
591+ continue ;
592+ } else if ( isSourceFileType ( file . lastKnownFileType ) ) {
593+ this . addToPbxBuildFileSection ( file ) ; // PBXBuildFile
594+ this . addToPbxSourcesBuildPhase ( file ) ;
595+ } else if ( isEntitlement ( file . lastKnownFileType ) ) {
596+ this . addToBuildSettings ( 'CODE_SIGN_ENTITLEMENTS' , file . path , opt . target ) ;
597+ } else if ( isResource ( file . group ) ) {
598+ this . addToPbxResourcesBuildPhase ( file )
599+ } else {
600+ this . addToPbxBuildFileSection ( file ) ;
601+ }
608602 }
609603 }
610604
@@ -1445,14 +1439,30 @@ pbxProject.prototype.removeFromOtherLinkerFlags = function (flag) {
14451439 }
14461440}
14471441
1448- pbxProject . prototype . addToBuildSettings = function ( buildSetting , value ) {
1442+ pbxProject . prototype . addToBuildSettings = function ( buildSetting , value , targetUuid ) {
14491443 var configurations = nonComments ( this . pbxXCBuildConfigurationSection ( ) ) ,
1444+ buildConfigurationsUuids = [ ] ,
14501445 config , buildSettings ;
14511446
1447+ if ( targetUuid ) {
1448+ var targets = this . hash . project . objects [ 'PBXNativeTarget' ] || [ ] ;
1449+ var target = targets [ targetUuid ] || { } ;
1450+ var buildConfigurationList = target [ "buildConfigurationList" ] ;
1451+ var pbxXCConfigurationListSection = this . pbxXCConfigurationList ( ) || { } ;
1452+ var xcConfigurationList = pbxXCConfigurationListSection [ buildConfigurationList ] || { } ;
1453+ var buildConfigurations = xcConfigurationList . buildConfigurations || [ ] ;
1454+ for ( var configurationUuid in buildConfigurations ) {
1455+ buildConfigurationsUuids . push ( buildConfigurations [ configurationUuid ] . value ) ;
1456+ }
1457+
1458+ }
1459+
14521460 for ( config in configurations ) {
1453- buildSettings = configurations [ config ] . buildSettings ;
1461+ if ( ! target || buildConfigurationsUuids . indexOf ( config ) >= 0 ) {
1462+ buildSettings = configurations [ config ] . buildSettings ;
14541463
1455- buildSettings [ buildSetting ] = value ;
1464+ buildSettings [ buildSetting ] = value ;
1465+ }
14561466 }
14571467}
14581468
@@ -1762,9 +1772,15 @@ pbxProject.prototype.removeTarget = function(target, targetKey) {
17621772 }
17631773 }
17641774
1775+ //remove targetAttributes for target
1776+ var attributes = this . getFirstProject ( ) [ 'firstProject' ] [ 'attributes' ] ;
1777+ if ( attributes [ 'TargetAttributes' ] ) {
1778+ delete attributes [ 'TargetAttributes' ] [ targetKey ] ;
1779+ }
1780+
17651781 //remove the target from PBXNativeTarget section
17661782 var nativeTargets = this . pbxNativeTargetSection ( ) ;
1767- removeItemAndCommentFromSectionByUuid ( nativeTargets , nativeTargetUuid ) ;
1783+ removeItemAndCommentFromSectionByUuid ( nativeTargets , targetKey ) ;
17681784
17691785 this . removePbxGroup ( unquote ( target . name ) ) ;
17701786} ;
0 commit comments