-
-
Notifications
You must be signed in to change notification settings - Fork 197
Add support for Custom entitlements files #2753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
32e7de8
Extract entitlements and xcconfig services.
e14ec25
Fix tests setup with the new services in ios-project-service tests
a161117
Adding newline in xcconfig-service to fix lint error
ee7b20c
Add Tests for XCConfig-Service
dd374a0
First test for the merging of the Build XCConfig files
f02841b
trying to add gems to the Travis CI machine setup
b44a5b8
Adding patching the xcconfig file with a default entitlements file lo…
c2e7561
Fix default empty entitlements file - was needless and caused errors.
08f48ac
Extract entitlements and xcconfig services.
13f3b6a
Fix tests setup with the new services in ios-project-service tests
9cf033b
Adding newline in xcconfig-service to fix lint error
5cd3f7a
Add Tests for XCConfig-Service
de96b76
First test for the merging of the Build XCConfig files
7222e98
trying to add gems to the Travis CI machine setup
835133a
Adding patching the xcconfig file with a default entitlements file lo…
6e37aa8
Fix default empty entitlements file - was needless and caused errors.
001179e
Merge branch 'yosifov/entitlements' of github.com:NativeScript/native…
dc508e6
Adding merge entitlements tests
6b74cbe
Add merge from App_Resources and Plugin integration test
ac8eb91
Fix PR comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as path from "path"; | ||
import * as constants from "../constants"; | ||
import { PlistSession } from "plist-merge-patch"; | ||
|
||
export class IOSEntitlementsService { | ||
constructor(private $fs: IFileSystem, | ||
private $logger: ILogger, | ||
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants, | ||
private $mobileHelper: Mobile.IMobileHelper, | ||
private $pluginsService: IPluginsService) { | ||
} | ||
|
||
public static readonly DefaultEntitlementsName: string = "app.entitlements"; | ||
|
||
private getDefaultAppEntitlementsPath(projectData: IProjectData) : string { | ||
const entitlementsName = IOSEntitlementsService.DefaultEntitlementsName; | ||
const entitlementsPath = path.join(projectData.projectDir, | ||
constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME, | ||
this.$mobileHelper.normalizePlatformName(this.$devicePlatformsConstants.iOS), | ||
entitlementsName); | ||
return entitlementsPath; | ||
} | ||
|
||
public getPlatformsEntitlementsPath(projectData: IProjectData) : string { | ||
return path.join(projectData.platformsDir, this.$devicePlatformsConstants.iOS, | ||
projectData.projectName, projectData.projectName + ".entitlements"); | ||
} | ||
public getPlatformsEntitlementsRelativePath(projectData: IProjectData): string { | ||
return path.join(projectData.projectName, projectData.projectName + ".entitlements"); | ||
} | ||
|
||
public async merge(projectData: IProjectData): Promise<void> { | ||
let session = new PlistSession({ log: (txt: string) => this.$logger.trace("App.entitlements: " + txt) }); | ||
|
||
let projectDir = projectData.projectDir; | ||
let makePatch = (plistPath: string) => { | ||
if (!this.$fs.exists(plistPath)) { | ||
this.$logger.trace("No plist found at: " + plistPath); | ||
return; | ||
} | ||
|
||
this.$logger.trace("Schedule merge plist at: " + plistPath); | ||
session.patch({ | ||
name: path.relative(projectDir, plistPath), | ||
read: () => this.$fs.readText(plistPath) | ||
}); | ||
}; | ||
|
||
let allPlugins = await this.getAllInstalledPlugins(projectData); | ||
for (let plugin of allPlugins) { | ||
let pluginInfoPlistPath = path.join(plugin.pluginPlatformsFolderPath(this.$devicePlatformsConstants.iOS), | ||
IOSEntitlementsService.DefaultEntitlementsName); | ||
makePatch(pluginInfoPlistPath); | ||
} | ||
|
||
let appEntitlementsPath = this.getDefaultAppEntitlementsPath(projectData); | ||
if (this.$fs.exists(appEntitlementsPath)) { | ||
makePatch(appEntitlementsPath); | ||
} | ||
|
||
let plistContent = session.build(); | ||
this.$logger.trace("App.entitlements: Write to: " + this.getPlatformsEntitlementsPath(projectData)); | ||
this.$fs.writeFile(this.getPlatformsEntitlementsPath(projectData), plistContent); | ||
return; | ||
} | ||
|
||
private getAllInstalledPlugins(projectData: IProjectData): Promise<IPluginData[]> { | ||
return this.$pluginsService.getAllInstalledPlugins(projectData); | ||
} | ||
} | ||
|
||
$injector.register("iOSEntitlementsService", IOSEntitlementsService); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ import { EOL } from "os"; | |
import * as temp from "temp"; | ||
import * as plist from "plist"; | ||
import { IOSProvisionService } from "./ios-provision-service"; | ||
import { IOSEntitlementsService } from "./ios-entitlements-service"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the practice is to ad interface for the service and use the interface in the constructor instead of importing the Type from another file. However I do not insist on using this approach strictly. |
||
import { XCConfigService } from "./xcconfig-service"; | ||
|
||
export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService { | ||
private static XCODE_PROJECT_EXT_NAME = ".xcodeproj"; | ||
|
@@ -40,9 +42,11 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ | |
private $pluginVariablesService: IPluginVariablesService, | ||
private $xcprojService: IXcprojService, | ||
private $iOSProvisionService: IOSProvisionService, | ||
private $sysInfo: ISysInfo, | ||
private $pbxprojDomXcode: IPbxprojDomXcode, | ||
private $xcode: IXcode) { | ||
private $xcode: IXcode, | ||
private $iOSEntitlementsService: IOSEntitlementsService, | ||
private $sysInfo: ISysInfo, | ||
private $xCConfigService: XCConfigService) { | ||
super($fs, $projectDataService); | ||
} | ||
|
||
|
@@ -668,6 +672,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f | |
|
||
public async processConfigurationFilesFromAppResources(release: boolean, projectData: IProjectData): Promise<void> { | ||
await this.mergeInfoPlists(projectData); | ||
await this.$iOSEntitlementsService.merge(projectData); | ||
await this.mergeProjectXcconfigFiles(release, projectData); | ||
for (let pluginData of await this.getAllInstalledPlugins(projectData)) { | ||
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 | |
} | ||
|
||
private async mergeProjectXcconfigFiles(release: boolean, projectData: IProjectData): Promise<void> { | ||
this.$fs.deleteFile(release ? this.getPluginsReleaseXcconfigFilePath(projectData) : this.getPluginsDebugXcconfigFilePath(projectData)); | ||
let pluginsXcconfigFilePath = release ? this.getPluginsReleaseXcconfigFilePath(projectData) : this.getPluginsDebugXcconfigFilePath(projectData); | ||
this.$fs.deleteFile(pluginsXcconfigFilePath); | ||
|
||
let allPlugins: IPluginData[] = await (<IPluginsService>this.$injector.resolve("pluginsService")).getAllInstalledPlugins(projectData); | ||
for (let plugin of allPlugins) { | ||
let pluginPlatformsFolderPath = plugin.pluginPlatformsFolderPath(IOSProjectService.IOS_PLATFORM_NAME); | ||
let pluginXcconfigFilePath = path.join(pluginPlatformsFolderPath, "build.xcconfig"); | ||
if (this.$fs.exists(pluginXcconfigFilePath)) { | ||
await this.mergeXcconfigFiles(pluginXcconfigFilePath, release ? this.getPluginsReleaseXcconfigFilePath(projectData) : this.getPluginsDebugXcconfigFilePath(projectData)); | ||
await this.mergeXcconfigFiles(pluginXcconfigFilePath, pluginsXcconfigFilePath); | ||
} | ||
} | ||
|
||
let appResourcesXcconfigPath = path.join(projectData.projectDir, constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME, this.getPlatformData(projectData).normalizedPlatformName, "build.xcconfig"); | ||
if (this.$fs.exists(appResourcesXcconfigPath)) { | ||
await this.mergeXcconfigFiles(appResourcesXcconfigPath, release ? this.getPluginsReleaseXcconfigFilePath(projectData) : this.getPluginsDebugXcconfigFilePath(projectData)); | ||
await this.mergeXcconfigFiles(appResourcesXcconfigPath, pluginsXcconfigFilePath); | ||
} | ||
|
||
// Set Entitlements Property to point to default file if not set explicitly by the user. | ||
let entitlementsPropertyValue = this.$xCConfigService.readPropertyValue(pluginsXcconfigFilePath, constants.CODE_SIGN_ENTITLEMENTS); | ||
if (entitlementsPropertyValue === null) { | ||
temp.track(); | ||
const tempEntitlementsDir = temp.mkdirSync("entitlements"); | ||
const tempEntitlementsFilePath = path.join(tempEntitlementsDir, "set-entitlements.xcconfig"); | ||
const entitlementsRelativePath = this.$iOSEntitlementsService.getPlatformsEntitlementsRelativePath(projectData); | ||
this.$fs.writeFile(tempEntitlementsFilePath, `CODE_SIGN_ENTITLEMENTS = ${entitlementsRelativePath}${EOL}`); | ||
|
||
await this.mergeXcconfigFiles(tempEntitlementsFilePath, pluginsXcconfigFilePath); | ||
} | ||
|
||
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 | |
return null; | ||
} | ||
|
||
private readXCConfig(flag: string, projectData: IProjectData): string { | ||
let xcconfigFile = path.join(projectData.appResourcesDirectoryPath, this.getPlatformData(projectData).normalizedPlatformName, "build.xcconfig"); | ||
if (this.$fs.exists(xcconfigFile)) { | ||
let text = this.$fs.readText(xcconfigFile); | ||
let teamId: string; | ||
text.split(/\r?\n/).forEach((line) => { | ||
line = line.replace(/\/(\/)[^\n]*$/, ""); | ||
if (line.indexOf(flag) >= 0) { | ||
teamId = line.split("=")[1].trim(); | ||
if (teamId[teamId.length - 1] === ';') { | ||
teamId = teamId.slice(0, -1); | ||
} | ||
} | ||
}); | ||
if (teamId) { | ||
return teamId; | ||
} | ||
} | ||
private getBuildXCConfigFilePath(projectData: IProjectData): string { | ||
let buildXCConfig = path.join(projectData.appResourcesDirectoryPath, | ||
this.getPlatformData(projectData).normalizedPlatformName, "build.xcconfig"); | ||
return buildXCConfig; | ||
} | ||
|
||
private readTeamId(projectData: IProjectData): string { | ||
let teamId = this.$xCConfigService.readPropertyValue(this.getBuildXCConfigFilePath(projectData), "DEVELOPMENT_TEAM"); | ||
|
||
let fileName = path.join(this.getPlatformData(projectData).projectRoot, "teamid"); | ||
if (this.$fs.exists(fileName)) { | ||
return this.$fs.readText(fileName); | ||
teamId = this.$fs.readText(fileName); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private readTeamId(projectData: IProjectData): string { | ||
return this.readXCConfig("DEVELOPMENT_TEAM", projectData); | ||
return teamId; | ||
} | ||
|
||
private readXCConfigProvisioningProfile(projectData: IProjectData): string { | ||
return this.readXCConfig("PROVISIONING_PROFILE", projectData); | ||
return this.$xCConfigService.readPropertyValue(this.getBuildXCConfigFilePath(projectData), "PROVISIONING_PROFILE"); | ||
} | ||
|
||
private readXCConfigProvisioningProfileForIPhoneOs(projectData: IProjectData): string { | ||
return this.readXCConfig("PROVISIONING_PROFILE[sdk=iphoneos*]", projectData); | ||
return this.$xCConfigService.readPropertyValue(this.getBuildXCConfigFilePath(projectData), "PROVISIONING_PROFILE[sdk=iphoneos*]"); | ||
} | ||
|
||
private readXCConfigProvisioningProfileSpecifier(projectData: IProjectData): string { | ||
return this.readXCConfig("PROVISIONING_PROFILE_SPECIFIER", projectData); | ||
return this.$xCConfigService.readPropertyValue(this.getBuildXCConfigFilePath(projectData), "PROVISIONING_PROFILE_SPECIFIER"); | ||
} | ||
|
||
private readXCConfigProvisioningProfileSpecifierForIPhoneOs(projectData: IProjectData): string { | ||
return this.readXCConfig("PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]", projectData); | ||
return this.$xCConfigService.readPropertyValue(this.getBuildXCConfigFilePath(projectData), "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]"); | ||
} | ||
|
||
private async getDevelopmentTeam(projectData: IProjectData, teamId?: string): Promise<string> { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export class XCConfigService { | ||
constructor(private $fs: IFileSystem) { | ||
} | ||
|
||
/** | ||
* Returns the Value of a Property from a XC Config file. | ||
* @param xcconfigFilePath | ||
* @param propertyName | ||
*/ | ||
public readPropertyValue(xcconfigFilePath: string, propertyName: string): string { | ||
if (this.$fs.exists(xcconfigFilePath)) { | ||
let text = this.$fs.readText(xcconfigFilePath); | ||
|
||
let property: string; | ||
let isPropertyParsed: boolean = false; | ||
text.split(/\r?\n/).forEach((line) => { | ||
line = line.replace(/\/(\/)[^\n]*$/, ""); | ||
if (line.indexOf(propertyName) >= 0) { | ||
let parts = line.split("="); | ||
if (parts.length > 1 && parts[1]) { | ||
property = parts[1].trim(); | ||
isPropertyParsed = true; | ||
if (property[property.length - 1] === ';') { | ||
property = property.slice(0, -1); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
if (isPropertyParsed) { | ||
// property can be an empty string, so we don't check for that. | ||
return property; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
||
$injector.register("xCConfigService", XCConfigService); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you do not need this return