From 78193f214e5ed0a976bd232667a13600f15f2efb Mon Sep 17 00:00:00 2001 From: Jason Zhekov Date: Fri, 4 Nov 2016 18:05:26 +0200 Subject: [PATCH] Remove use of lib/iOS folder for native plugins They are added from their original node_modules folder instead. --- lib/services/ios-project-service.ts | 58 +++++------------------------ test/ios-project-service.ts | 6 +-- 2 files changed, 12 insertions(+), 52 deletions(-) diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index 6de0956eee..d098b6debb 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -357,43 +357,10 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ return Future.fromResult(); } - private getDeploymentTarget(project: xcode.project): string { - let configurations = project.pbxXCBuildConfigurationSection(); - - for (let configName in configurations) { - if (!Object.prototype.hasOwnProperty.call(configurations, configName)) { - continue; - } - - let configuration = configurations[configName]; - if (typeof configuration !== "object") { - continue; - } - - let buildSettings = configuration.buildSettings; - if (buildSettings["IPHONEOS_DEPLOYMENT_TARGET"]) { - return buildSettings["IPHONEOS_DEPLOYMENT_TARGET"]; - } - } - } - - private ensureIos8DeploymentTarget(project: xcode.project) { - // tns-ios@2.1.0+ has a default deployment target of 8.0 so this is not needed there - if (this.getDeploymentTarget(project) === "7.0") { - project.updateBuildProperty("IPHONEOS_DEPLOYMENT_TARGET", "8.0"); - this.$logger.info("The iOS Deployment Target is now 8.0 in order to support Cocoa Touch Frameworks."); - } - } - - private addDynamicFramework(frameworkPath: string): IFuture { + private addFramework(frameworkPath: string): IFuture { return (() => { this.validateFramework(frameworkPath).wait(); - let targetPath = path.join("lib", this.platformData.normalizedPlatformName); - let fullTargetPath = path.join(this.$projectData.projectDir, targetPath); - this.$fs.ensureDirectoryExists(fullTargetPath).wait(); - shell.cp("-R", frameworkPath, fullTargetPath); - let project = this.createPbxProj(); let frameworkName = path.basename(frameworkPath, path.extname(frameworkPath)); let frameworkBinaryPath = path.join(frameworkPath, frameworkName); @@ -403,10 +370,9 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ if (isDynamic) { frameworkAddOptions["embed"] = true; - this.ensureIos8DeploymentTarget(project); } - let frameworkRelativePath = this.getLibSubpathRelativeToProjectPath(path.basename(frameworkPath)); + let frameworkRelativePath = '$(SRCROOT)/' + this.getLibSubpathRelativeToProjectPath(frameworkPath); project.addFramework(frameworkRelativePath, frameworkAddOptions); this.savePbxProj(project).wait(); }).future()(); @@ -417,21 +383,17 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ this.validateStaticLibrary(staticLibPath).wait(); // Copy files to lib folder. let libraryName = path.basename(staticLibPath, ".a"); - let libDestinationPath = path.join(this.$projectData.projectDir, path.join("lib", this.platformData.normalizedPlatformName)); - let headersSubpath = path.join("include", libraryName); - this.$fs.ensureDirectoryExists(path.join(libDestinationPath, headersSubpath)).wait(); - shell.cp("-Rf", staticLibPath, libDestinationPath); - shell.cp("-Rf", path.join(path.dirname(staticLibPath), headersSubpath), path.join(libDestinationPath, "include")); + let headersSubpath = path.join(path.dirname(staticLibPath), "include", libraryName); // Add static library to project file and setup header search paths let project = this.createPbxProj(); - let relativeStaticLibPath = this.getLibSubpathRelativeToProjectPath(path.basename(staticLibPath)); + let relativeStaticLibPath = this.getLibSubpathRelativeToProjectPath(staticLibPath); project.addFramework(relativeStaticLibPath); let relativeHeaderSearchPath = path.join(this.getLibSubpathRelativeToProjectPath(headersSubpath)); project.addToHeaderSearchPaths({ relativePath: relativeHeaderSearchPath }); - this.generateMobulemap(path.join(libDestinationPath, headersSubpath), libraryName); + this.generateModulemap(headersSubpath, libraryName); this.savePbxProj(project).wait(); }).future()(); } @@ -711,9 +673,8 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f return name.replace(/\\\"/g, "\""); } - private getLibSubpathRelativeToProjectPath(subPath: string): string { - let targetPath = path.join("lib", this.platformData.normalizedPlatformName); - let frameworkPath = path.relative("platforms/ios", path.join(targetPath, subPath)); + private getLibSubpathRelativeToProjectPath(targetPath: string): string { + let frameworkPath = path.relative("platforms/ios", targetPath); return frameworkPath; } @@ -883,7 +844,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f private prepareFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData): IFuture { return (() => { - _.each(this.getAllLibsForPluginWithFileExtension(pluginData, ".framework").wait(), fileName => this.addDynamicFramework(path.join(pluginPlatformsFolderPath, fileName)).wait()); + _.each(this.getAllLibsForPluginWithFileExtension(pluginData, ".framework").wait(), fileName => this.addFramework(path.join(pluginPlatformsFolderPath, fileName)).wait()); }).future()(); } @@ -917,7 +878,6 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f this.$fs.writeFile(this.projectPodFilePath, contentToWrite).wait(); let project = this.createPbxProj(); - this.ensureIos8DeploymentTarget(project); this.savePbxProj(project).wait(); } } @@ -980,7 +940,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f return `# Begin Podfile - ${pluginPodFilePath} ${os.EOL} ${pluginPodFileContent} ${os.EOL} # End Podfile ${os.EOL}`; } - private generateMobulemap(headersFolderPath: string, libraryName: string): void { + private generateModulemap(headersFolderPath: string, libraryName: string): void { let headersFilter = (fileName: string, containingFolderPath: string) => (path.extname(fileName) === ".h" && this.$fs.getFsStats(path.join(containingFolderPath, fileName)).wait().isFile()); let headersFolderContents = this.$fs.readDirectory(headersFolderPath).wait(); let headers = _(headersFolderContents).filter(item => headersFilter(item, headersFolderPath)).value(); diff --git a/test/ios-project-service.ts b/test/ios-project-service.ts index 1b509d4be4..9e3878aec3 100644 --- a/test/ios-project-service.ts +++ b/test/ios-project-service.ts @@ -442,7 +442,7 @@ describe("Static libraries support", () => { fs.ensureDirectoryExists(staticLibraryHeadersPath).wait(); _.each(headers, header => { fs.writeFile(path.join(staticLibraryHeadersPath, header), "").wait(); }); - iOSProjectService.generateMobulemap(staticLibraryHeadersPath, libraryName); + iOSProjectService.generateModulemap(staticLibraryHeadersPath, libraryName); // Read the generated modulemap and verify it. let modulemap = fs.readFile(path.join(staticLibraryHeadersPath, "module.modulemap")).wait(); let headerCommands = _.map(headers, value => `header "${value}"`); @@ -452,7 +452,7 @@ describe("Static libraries support", () => { // Delete all header files. And try to regenerate modulemap. _.each(headers, header => { fs.deleteFile(path.join(staticLibraryHeadersPath, header)).wait(); }); - iOSProjectService.generateMobulemap(staticLibraryHeadersPath, libraryName); + iOSProjectService.generateModulemap(staticLibraryHeadersPath, libraryName); let error: any; try { @@ -476,6 +476,6 @@ describe("Relative paths", () => { let iOSProjectService = testInjector.resolve("iOSProjectService"); let result = iOSProjectService.getLibSubpathRelativeToProjectPath(subpath); - assert.equal(result, path.join("../../lib/iOS/", subpath)); + assert.equal(result, path.join("../../", subpath)); }); });