Skip to content

Remove use of lib/iOS folder for native plugins #2195

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 1 commit into from
Nov 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 9 additions & 49 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
// [email protected]+ 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<void> {
private addFramework(frameworkPath: string): IFuture<void> {
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);
Expand All @@ -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<void>()();
Expand All @@ -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<void>()();
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -883,7 +844,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f

private prepareFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData): IFuture<void> {
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<void>()();
}

Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions test/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}"`);
Expand All @@ -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 {
Expand All @@ -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));
});
});