Skip to content

Commit d8339a3

Browse files
author
Mitko-Kerezov
committed
Add a target to the Podfile
Trying to run `pod install` with CocoaPods 1.0.0 issues an error in case the Podfile doesn't reference a target. Add the project target to the Podfile. Upon specifying target to the Podfile, however, the path to the Pods' .xcconfig file changes - reflect that change in code. In addition, truncate and write the Podfile upon each prepare in order to avoid duplication and errors.
1 parent cc619e3 commit d8339a3

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

lib/services/ios-project-service.ts

+7-10
Original file line numberDiff line numberDiff line change
@@ -689,13 +689,9 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
689689
let pluginPodFilePath = path.join(pluginPlatformsFolderPath, "Podfile");
690690

691691
if(this.$fs.exists(pluginPodFilePath).wait()) {
692-
if(!this.$fs.exists(this.projectPodFilePath).wait()) {
693-
this.$fs.writeFile(this.projectPodFilePath, "use_frameworks!\n").wait();
694-
}
695-
696692
let pluginPodFileContent = this.$fs.readText(pluginPodFilePath).wait();
697-
let contentToWrite = this.buildPodfileContent(pluginPodFilePath, pluginPodFileContent);
698-
this.$fs.appendFile(this.projectPodFilePath, contentToWrite).wait();
693+
let contentToWrite = `use_frameworks!${os.EOL}${os.EOL}target "${this.$projectData.projectName}" do${os.EOL}${this.buildPodfileContent(pluginPodFilePath, pluginPodFileContent)}${os.EOL}end`;
694+
this.$fs.writeFile(this.projectPodFilePath, contentToWrite).wait();
699695

700696
let project = this.createPbxProj();
701697
project.updateBuildProperty("IPHONEOS_DEPLOYMENT_TARGET", "8.0");
@@ -747,7 +743,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
747743
let projectPodFileContent = this.$fs.readText(this.projectPodFilePath).wait();
748744
let contentToRemove= this.buildPodfileContent(pluginPodFilePath, pluginPodFileContent);
749745
projectPodFileContent = helpers.stringReplaceAll(projectPodFileContent, contentToRemove, "");
750-
if(projectPodFileContent.trim() === "use_frameworks!") {
746+
if(projectPodFileContent.trim() === `use_frameworks!${os.EOL}${os.EOL}target "${this.$projectData.projectName}" do${os.EOL}${os.EOL}end`) {
751747
this.$fs.deleteFile(this.projectPodFilePath).wait();
752748
} else {
753749
this.$fs.writeFile(this.projectPodFilePath, projectPodFileContent).wait();
@@ -811,10 +807,11 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
811807
this.mergeXcconfigFiles(appResourcesXcconfigPath, this.pluginsReleaseXcconfigFilePath).wait();
812808
}
813809

814-
let podFolder = path.join(this.platformData.projectRoot, "Pods/Target Support Files/Pods/");
810+
let podFilesRootDirName = path.join("Pods", "Target Support Files", `Pods-${this.$projectData.projectName}`);
811+
let podFolder = path.join(this.platformData.projectRoot, podFilesRootDirName);
815812
if (this.$fs.exists(podFolder).wait()) {
816-
this.mergeXcconfigFiles(path.join(this.platformData.projectRoot, "Pods/Target Support Files/Pods/Pods.debug.xcconfig"), this.pluginsDebugXcconfigFilePath).wait();
817-
this.mergeXcconfigFiles(path.join(this.platformData.projectRoot, "Pods/Target Support Files/Pods/Pods.release.xcconfig"), this.pluginsReleaseXcconfigFilePath).wait();
813+
this.mergeXcconfigFiles(path.join(this.platformData.projectRoot, podFilesRootDirName, `Pods-${this.$projectData.projectName}.debug.xcconfig`), this.pluginsDebugXcconfigFilePath).wait();
814+
this.mergeXcconfigFiles(path.join(this.platformData.projectRoot, podFilesRootDirName, `Pods-${this.$projectData.projectName}.release.xcconfig`), this.pluginsReleaseXcconfigFilePath).wait();
818815
}
819816
}).future<void>()();
820817
}

test/ios-project-service.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,12 @@ describe("Cocoapods support", () => {
154154
assert.isTrue(fs.exists(projectPodfilePath).wait());
155155

156156
let actualProjectPodfileContent = fs.readText(projectPodfilePath).wait();
157-
let expectedProjectPodfileContent = ["use_frameworks!",
157+
let expectedProjectPodfileContent = ["use_frameworks!\n",
158+
`target "${projectName}" do`,
158159
`# Begin Podfile - ${pluginPodfilePath} `,
159160
` ${pluginPodfileContent} `,
160-
" # End Podfile \n"]
161+
" # End Podfile \n",
162+
"end"]
161163
.join("\n");
162164
assert.equal(actualProjectPodfileContent, expectedProjectPodfileContent);
163165
});
@@ -221,10 +223,12 @@ describe("Cocoapods support", () => {
221223
assert.isTrue(fs.exists(projectPodfilePath).wait());
222224

223225
let actualProjectPodfileContent = fs.readText(projectPodfilePath).wait();
224-
let expectedProjectPodfileContent = ["use_frameworks!",
226+
let expectedProjectPodfileContent = ["use_frameworks!\n",
227+
`target "${projectName}" do`,
225228
`# Begin Podfile - ${pluginPodfilePath} `,
226229
` ${pluginPodfileContent} `,
227-
" # End Podfile \n"]
230+
" # End Podfile \n",
231+
"end"]
228232
.join("\n");
229233
assert.equal(actualProjectPodfileContent, expectedProjectPodfileContent);
230234

0 commit comments

Comments
 (0)