@@ -11,6 +11,8 @@ import { EOL } from "os";
11
11
import * as temp from "temp" ;
12
12
import * as plist from "plist" ;
13
13
import { IOSProvisionService } from "./ios-provision-service" ;
14
+ import { IOSEntitlementsService } from "./ios-entitlements-service" ;
15
+ import { XCConfigService } from "./xcconfig-service" ;
14
16
15
17
export class IOSProjectService extends projectServiceBaseLib . PlatformProjectServiceBase implements IPlatformProjectService {
16
18
private static XCODE_PROJECT_EXT_NAME = ".xcodeproj" ;
@@ -40,9 +42,11 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
40
42
private $pluginVariablesService : IPluginVariablesService ,
41
43
private $xcprojService : IXcprojService ,
42
44
private $iOSProvisionService : IOSProvisionService ,
43
- private $sysInfo : ISysInfo ,
44
45
private $pbxprojDomXcode : IPbxprojDomXcode ,
45
- private $xcode : IXcode ) {
46
+ private $xcode : IXcode ,
47
+ private $iOSEntitlementsService : IOSEntitlementsService ,
48
+ private $sysInfo : ISysInfo ,
49
+ private $xCConfigService : XCConfigService ) {
46
50
super ( $fs , $projectDataService ) ;
47
51
}
48
52
@@ -668,6 +672,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
668
672
669
673
public async processConfigurationFilesFromAppResources ( release : boolean , projectData : IProjectData ) : Promise < void > {
670
674
await this . mergeInfoPlists ( projectData ) ;
675
+ await this . $iOSEntitlementsService . merge ( projectData ) ;
671
676
await this . mergeProjectXcconfigFiles ( release , projectData ) ;
672
677
for ( let pluginData of await this . getAllInstalledPlugins ( projectData ) ) {
673
678
await this . $pluginVariablesService . interpolatePluginVariables ( pluginData , this . getPlatformData ( projectData ) . configurationFilePath , projectData ) ;
@@ -1085,20 +1090,33 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
1085
1090
}
1086
1091
1087
1092
private async mergeProjectXcconfigFiles ( release : boolean , projectData : IProjectData ) : Promise < void > {
1088
- this . $fs . deleteFile ( release ? this . getPluginsReleaseXcconfigFilePath ( projectData ) : this . getPluginsDebugXcconfigFilePath ( projectData ) ) ;
1093
+ let pluginsXcconfigFilePath = release ? this . getPluginsReleaseXcconfigFilePath ( projectData ) : this . getPluginsDebugXcconfigFilePath ( projectData ) ;
1094
+ this . $fs . deleteFile ( pluginsXcconfigFilePath ) ;
1089
1095
1090
1096
let allPlugins : IPluginData [ ] = await ( < IPluginsService > this . $injector . resolve ( "pluginsService" ) ) . getAllInstalledPlugins ( projectData ) ;
1091
1097
for ( let plugin of allPlugins ) {
1092
1098
let pluginPlatformsFolderPath = plugin . pluginPlatformsFolderPath ( IOSProjectService . IOS_PLATFORM_NAME ) ;
1093
1099
let pluginXcconfigFilePath = path . join ( pluginPlatformsFolderPath , "build.xcconfig" ) ;
1094
1100
if ( this . $fs . exists ( pluginXcconfigFilePath ) ) {
1095
- await this . mergeXcconfigFiles ( pluginXcconfigFilePath , release ? this . getPluginsReleaseXcconfigFilePath ( projectData ) : this . getPluginsDebugXcconfigFilePath ( projectData ) ) ;
1101
+ await this . mergeXcconfigFiles ( pluginXcconfigFilePath , pluginsXcconfigFilePath ) ;
1096
1102
}
1097
1103
}
1098
1104
1099
1105
let appResourcesXcconfigPath = path . join ( projectData . projectDir , constants . APP_FOLDER_NAME , constants . APP_RESOURCES_FOLDER_NAME , this . getPlatformData ( projectData ) . normalizedPlatformName , "build.xcconfig" ) ;
1100
1106
if ( this . $fs . exists ( appResourcesXcconfigPath ) ) {
1101
- await this . mergeXcconfigFiles ( appResourcesXcconfigPath , release ? this . getPluginsReleaseXcconfigFilePath ( projectData ) : this . getPluginsDebugXcconfigFilePath ( projectData ) ) ;
1107
+ await this . mergeXcconfigFiles ( appResourcesXcconfigPath , pluginsXcconfigFilePath ) ;
1108
+ }
1109
+
1110
+ // Set Entitlements Property to point to default file if not set explicitly by the user.
1111
+ let entitlementsPropertyValue = this . $xCConfigService . readPropertyValue ( pluginsXcconfigFilePath , constants . CODE_SIGN_ENTITLEMENTS ) ;
1112
+ if ( entitlementsPropertyValue === null ) {
1113
+ temp . track ( ) ;
1114
+ const tempEntitlementsDir = temp . mkdirSync ( "entitlements" ) ;
1115
+ const tempEntitlementsFilePath = path . join ( tempEntitlementsDir , "set-entitlements.xcconfig" ) ;
1116
+ const entitlementsRelativePath = this . $iOSEntitlementsService . getPlatformsEntitlementsRelativePath ( projectData ) ;
1117
+ this . $fs . writeFile ( tempEntitlementsFilePath , `CODE_SIGN_ENTITLEMENTS = ${ entitlementsRelativePath } ${ EOL } ` ) ;
1118
+
1119
+ await this . mergeXcconfigFiles ( tempEntitlementsFilePath , pluginsXcconfigFilePath ) ;
1102
1120
}
1103
1121
1104
1122
let podFilesRootDirName = path . join ( "Pods" , "Target Support Files" , `Pods-${ projectData . projectName } ` ) ;
@@ -1178,51 +1196,37 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
1178
1196
return null ;
1179
1197
}
1180
1198
1181
- private readXCConfig ( flag : string , projectData : IProjectData ) : string {
1182
- let xcconfigFile = path . join ( projectData . appResourcesDirectoryPath , this . getPlatformData ( projectData ) . normalizedPlatformName , "build.xcconfig" ) ;
1183
- if ( this . $fs . exists ( xcconfigFile ) ) {
1184
- let text = this . $fs . readText ( xcconfigFile ) ;
1185
- let teamId : string ;
1186
- text . split ( / \r ? \n / ) . forEach ( ( line ) => {
1187
- line = line . replace ( / \/ ( \/ ) [ ^ \n ] * $ / , "" ) ;
1188
- if ( line . indexOf ( flag ) >= 0 ) {
1189
- teamId = line . split ( "=" ) [ 1 ] . trim ( ) ;
1190
- if ( teamId [ teamId . length - 1 ] === ';' ) {
1191
- teamId = teamId . slice ( 0 , - 1 ) ;
1192
- }
1193
- }
1194
- } ) ;
1195
- if ( teamId ) {
1196
- return teamId ;
1197
- }
1198
- }
1199
+ private getBuildXCConfigFilePath ( projectData : IProjectData ) : string {
1200
+ let buildXCConfig = path . join ( projectData . appResourcesDirectoryPath ,
1201
+ this . getPlatformData ( projectData ) . normalizedPlatformName , "build.xcconfig" ) ;
1202
+ return buildXCConfig ;
1203
+ }
1204
+
1205
+ private readTeamId ( projectData : IProjectData ) : string {
1206
+ let teamId = this . $xCConfigService . readPropertyValue ( this . getBuildXCConfigFilePath ( projectData ) , "DEVELOPMENT_TEAM" ) ;
1199
1207
1200
1208
let fileName = path . join ( this . getPlatformData ( projectData ) . projectRoot , "teamid" ) ;
1201
1209
if ( this . $fs . exists ( fileName ) ) {
1202
- return this . $fs . readText ( fileName ) ;
1210
+ teamId = this . $fs . readText ( fileName ) ;
1203
1211
}
1204
1212
1205
- return null ;
1206
- }
1207
-
1208
- private readTeamId ( projectData : IProjectData ) : string {
1209
- return this . readXCConfig ( "DEVELOPMENT_TEAM" , projectData ) ;
1213
+ return teamId ;
1210
1214
}
1211
1215
1212
1216
private readXCConfigProvisioningProfile ( projectData : IProjectData ) : string {
1213
- return this . readXCConfig ( "PROVISIONING_PROFILE" , projectData ) ;
1217
+ return this . $xCConfigService . readPropertyValue ( this . getBuildXCConfigFilePath ( projectData ) , "PROVISIONING_PROFILE" ) ;
1214
1218
}
1215
1219
1216
1220
private readXCConfigProvisioningProfileForIPhoneOs ( projectData : IProjectData ) : string {
1217
- return this . readXCConfig ( "PROVISIONING_PROFILE[sdk=iphoneos*]" , projectData ) ;
1221
+ return this . $xCConfigService . readPropertyValue ( this . getBuildXCConfigFilePath ( projectData ) , "PROVISIONING_PROFILE[sdk=iphoneos*]" ) ;
1218
1222
}
1219
1223
1220
1224
private readXCConfigProvisioningProfileSpecifier ( projectData : IProjectData ) : string {
1221
- return this . readXCConfig ( "PROVISIONING_PROFILE_SPECIFIER" , projectData ) ;
1225
+ return this . $xCConfigService . readPropertyValue ( this . getBuildXCConfigFilePath ( projectData ) , "PROVISIONING_PROFILE_SPECIFIER" ) ;
1222
1226
}
1223
1227
1224
1228
private readXCConfigProvisioningProfileSpecifierForIPhoneOs ( projectData : IProjectData ) : string {
1225
- return this . readXCConfig ( "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" , projectData ) ;
1229
+ return this . $xCConfigService . readPropertyValue ( this . getBuildXCConfigFilePath ( projectData ) , "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" ) ;
1226
1230
}
1227
1231
1228
1232
private async getDevelopmentTeam ( projectData : IProjectData , teamId ?: string ) : Promise < string > {
0 commit comments