Skip to content

Commit 3a6ba18

Browse files
authored
Merge pull request #2195 from NativeScript/jasssonpet/ios-framework-add
Remove use of lib/iOS folder for native plugins
2 parents e7aeca9 + 78193f2 commit 3a6ba18

File tree

2 files changed

+12
-52
lines changed

2 files changed

+12
-52
lines changed

lib/services/ios-project-service.ts

+9-49
Original file line numberDiff line numberDiff line change
@@ -357,43 +357,10 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
357357
return Future.fromResult();
358358
}
359359

360-
private getDeploymentTarget(project: xcode.project): string {
361-
let configurations = project.pbxXCBuildConfigurationSection();
362-
363-
for (let configName in configurations) {
364-
if (!Object.prototype.hasOwnProperty.call(configurations, configName)) {
365-
continue;
366-
}
367-
368-
let configuration = configurations[configName];
369-
if (typeof configuration !== "object") {
370-
continue;
371-
}
372-
373-
let buildSettings = configuration.buildSettings;
374-
if (buildSettings["IPHONEOS_DEPLOYMENT_TARGET"]) {
375-
return buildSettings["IPHONEOS_DEPLOYMENT_TARGET"];
376-
}
377-
}
378-
}
379-
380-
private ensureIos8DeploymentTarget(project: xcode.project) {
381-
// [email protected]+ has a default deployment target of 8.0 so this is not needed there
382-
if (this.getDeploymentTarget(project) === "7.0") {
383-
project.updateBuildProperty("IPHONEOS_DEPLOYMENT_TARGET", "8.0");
384-
this.$logger.info("The iOS Deployment Target is now 8.0 in order to support Cocoa Touch Frameworks.");
385-
}
386-
}
387-
388-
private addDynamicFramework(frameworkPath: string): IFuture<void> {
360+
private addFramework(frameworkPath: string): IFuture<void> {
389361
return (() => {
390362
this.validateFramework(frameworkPath).wait();
391363

392-
let targetPath = path.join("lib", this.platformData.normalizedPlatformName);
393-
let fullTargetPath = path.join(this.$projectData.projectDir, targetPath);
394-
this.$fs.ensureDirectoryExists(fullTargetPath).wait();
395-
shell.cp("-R", frameworkPath, fullTargetPath);
396-
397364
let project = this.createPbxProj();
398365
let frameworkName = path.basename(frameworkPath, path.extname(frameworkPath));
399366
let frameworkBinaryPath = path.join(frameworkPath, frameworkName);
@@ -403,10 +370,9 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
403370

404371
if (isDynamic) {
405372
frameworkAddOptions["embed"] = true;
406-
this.ensureIos8DeploymentTarget(project);
407373
}
408374

409-
let frameworkRelativePath = this.getLibSubpathRelativeToProjectPath(path.basename(frameworkPath));
375+
let frameworkRelativePath = '$(SRCROOT)/' + this.getLibSubpathRelativeToProjectPath(frameworkPath);
410376
project.addFramework(frameworkRelativePath, frameworkAddOptions);
411377
this.savePbxProj(project).wait();
412378
}).future<void>()();
@@ -417,21 +383,17 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
417383
this.validateStaticLibrary(staticLibPath).wait();
418384
// Copy files to lib folder.
419385
let libraryName = path.basename(staticLibPath, ".a");
420-
let libDestinationPath = path.join(this.$projectData.projectDir, path.join("lib", this.platformData.normalizedPlatformName));
421-
let headersSubpath = path.join("include", libraryName);
422-
this.$fs.ensureDirectoryExists(path.join(libDestinationPath, headersSubpath)).wait();
423-
shell.cp("-Rf", staticLibPath, libDestinationPath);
424-
shell.cp("-Rf", path.join(path.dirname(staticLibPath), headersSubpath), path.join(libDestinationPath, "include"));
386+
let headersSubpath = path.join(path.dirname(staticLibPath), "include", libraryName);
425387

426388
// Add static library to project file and setup header search paths
427389
let project = this.createPbxProj();
428-
let relativeStaticLibPath = this.getLibSubpathRelativeToProjectPath(path.basename(staticLibPath));
390+
let relativeStaticLibPath = this.getLibSubpathRelativeToProjectPath(staticLibPath);
429391
project.addFramework(relativeStaticLibPath);
430392

431393
let relativeHeaderSearchPath = path.join(this.getLibSubpathRelativeToProjectPath(headersSubpath));
432394
project.addToHeaderSearchPaths({ relativePath: relativeHeaderSearchPath });
433395

434-
this.generateMobulemap(path.join(libDestinationPath, headersSubpath), libraryName);
396+
this.generateModulemap(headersSubpath, libraryName);
435397
this.savePbxProj(project).wait();
436398
}).future<void>()();
437399
}
@@ -711,9 +673,8 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
711673
return name.replace(/\\\"/g, "\"");
712674
}
713675

714-
private getLibSubpathRelativeToProjectPath(subPath: string): string {
715-
let targetPath = path.join("lib", this.platformData.normalizedPlatformName);
716-
let frameworkPath = path.relative("platforms/ios", path.join(targetPath, subPath));
676+
private getLibSubpathRelativeToProjectPath(targetPath: string): string {
677+
let frameworkPath = path.relative("platforms/ios", targetPath);
717678
return frameworkPath;
718679
}
719680

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

884845
private prepareFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData): IFuture<void> {
885846
return (() => {
886-
_.each(this.getAllLibsForPluginWithFileExtension(pluginData, ".framework").wait(), fileName => this.addDynamicFramework(path.join(pluginPlatformsFolderPath, fileName)).wait());
847+
_.each(this.getAllLibsForPluginWithFileExtension(pluginData, ".framework").wait(), fileName => this.addFramework(path.join(pluginPlatformsFolderPath, fileName)).wait());
887848
}).future<void>()();
888849
}
889850

@@ -917,7 +878,6 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
917878
this.$fs.writeFile(this.projectPodFilePath, contentToWrite).wait();
918879

919880
let project = this.createPbxProj();
920-
this.ensureIos8DeploymentTarget(project);
921881
this.savePbxProj(project).wait();
922882
}
923883
}
@@ -980,7 +940,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
980940
return `# Begin Podfile - ${pluginPodFilePath} ${os.EOL} ${pluginPodFileContent} ${os.EOL} # End Podfile ${os.EOL}`;
981941
}
982942

983-
private generateMobulemap(headersFolderPath: string, libraryName: string): void {
943+
private generateModulemap(headersFolderPath: string, libraryName: string): void {
984944
let headersFilter = (fileName: string, containingFolderPath: string) => (path.extname(fileName) === ".h" && this.$fs.getFsStats(path.join(containingFolderPath, fileName)).wait().isFile());
985945
let headersFolderContents = this.$fs.readDirectory(headersFolderPath).wait();
986946
let headers = _(headersFolderContents).filter(item => headersFilter(item, headersFolderPath)).value();

test/ios-project-service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ describe("Static libraries support", () => {
442442
fs.ensureDirectoryExists(staticLibraryHeadersPath).wait();
443443
_.each(headers, header => { fs.writeFile(path.join(staticLibraryHeadersPath, header), "").wait(); });
444444

445-
iOSProjectService.generateMobulemap(staticLibraryHeadersPath, libraryName);
445+
iOSProjectService.generateModulemap(staticLibraryHeadersPath, libraryName);
446446
// Read the generated modulemap and verify it.
447447
let modulemap = fs.readFile(path.join(staticLibraryHeadersPath, "module.modulemap")).wait();
448448
let headerCommands = _.map(headers, value => `header "${value}"`);
@@ -452,7 +452,7 @@ describe("Static libraries support", () => {
452452

453453
// Delete all header files. And try to regenerate modulemap.
454454
_.each(headers, header => { fs.deleteFile(path.join(staticLibraryHeadersPath, header)).wait(); });
455-
iOSProjectService.generateMobulemap(staticLibraryHeadersPath, libraryName);
455+
iOSProjectService.generateModulemap(staticLibraryHeadersPath, libraryName);
456456

457457
let error: any;
458458
try {
@@ -476,6 +476,6 @@ describe("Relative paths", () => {
476476
let iOSProjectService = testInjector.resolve("iOSProjectService");
477477

478478
let result = iOSProjectService.getLibSubpathRelativeToProjectPath(subpath);
479-
assert.equal(result, path.join("../../lib/iOS/", subpath));
479+
assert.equal(result, path.join("../../", subpath));
480480
});
481481
});

0 commit comments

Comments
 (0)