Skip to content

Merge xcconfig files #1042

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
Oct 12, 2015
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
2 changes: 1 addition & 1 deletion lib/commands/create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class ProjectCommandParameter implements ICommandParameter {
}

if (value.toUpperCase() === "APP") {
this.$logger.warn("You cannot build aplications named 'app' in Xcode. Consider creating a project with different name.");
this.$logger.warn("You cannot build applications named 'app' in Xcode. Consider creating a project with different name.");
}

return this.$projectNameValidator.validate(value);
Expand Down
68 changes: 40 additions & 28 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,12 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
return path.join(this.platformData.projectRoot, "Podfile");
}

private get projectXcconfigFilePath(): string {
return path.join(this.platformData.appDestinationDirectoryPath, "build.xcconfig");
private get pluginsDebugXcconfigFilePath(): string {
return path.join(this.platformData.projectRoot, "plugins-debug.xcconfig");
}

private get pluginsReleaseXcconfigFilePath(): string {
return path.join(this.platformData.projectRoot, "plugins-release.xcconfig");
}

private replace(name: string): string {
Expand Down Expand Up @@ -389,7 +393,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
this.prepareFrameworks(pluginPlatformsFolderPath, pluginData).wait();
this.prepareStaticLibs(pluginPlatformsFolderPath, pluginData).wait();
this.prepareCocoapods(pluginPlatformsFolderPath).wait();
this.prepareXcconfigFile(pluginPlatformsFolderPath).wait();
}).future<void>()();
}

Expand All @@ -400,7 +403,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
this.removeFrameworks(pluginPlatformsFolderPath, pluginData).wait();
this.removeStaticLibs(pluginPlatformsFolderPath, pluginData).wait();
this.removeCocoapods(pluginPlatformsFolderPath).wait();
this.removeXcconfigFile(pluginPlatformsFolderPath).wait();
}).future<void>()();
}

Expand Down Expand Up @@ -433,6 +435,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ

this.executePodInstall().wait();
}

this.regeneratePluginsXcconfigFile().wait();
}).future<void>()();
}

Expand Down Expand Up @@ -535,16 +539,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
}).future<void>()();
}

private prepareXcconfigFile(pluginPlatformsFolderPath: string): IFuture<void> {
return (() => {
let pluginXcconfigFilePath = path.join(pluginPlatformsFolderPath, "build.xcconfig");
if(this.$fs.exists(pluginXcconfigFilePath).wait()) {
let contentToWrite = this.buildXcconfigContent(pluginXcconfigFilePath);
this.$fs.appendFile(this.projectXcconfigFilePath, contentToWrite).wait();
}
}).future<void>()();
}

private removeFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData): IFuture<void> {
return (() => {
let project = this.createPbxProj();
Expand Down Expand Up @@ -588,18 +582,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
} else {
this.$fs.writeFile(this.projectPodFilePath, projectPodFileContent).wait();
}
}
}).future<void>()();
}

private removeXcconfigFile(pluginPlatformsFolderPath: string): IFuture<void> {
return (() => {
let pluginXcconfigFilePath = path.join(pluginPlatformsFolderPath, "build.xcconfig");
if(this.$fs.exists(pluginXcconfigFilePath).wait()) {
let projectXcconfigFileContent = this.$fs.readText(this.projectXcconfigFilePath).wait();
let contentToRemove = this.buildXcconfigContent(pluginXcconfigFilePath);
projectXcconfigFileContent = helpers.stringReplaceAll(projectXcconfigFileContent, contentToRemove, "");
this.$fs.writeFile(this.projectXcconfigFilePath, projectXcconfigFileContent).wait();
}
}).future<void>()();
}
Expand All @@ -624,9 +607,38 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
this.$fs.writeFile(path.join(headersFolderPath, "module.modulemap"), modulemap).wait();
}

private buildXcconfigContent(xcconfigFilePath: string): string {
let relativePluginXcconfigFilePath = path.relative(path.dirname(this.projectXcconfigFilePath), xcconfigFilePath);
return `${os.EOL}#include "${relativePluginXcconfigFilePath}"${os.EOL}`;
private mergeXcconfigFiles(pluginFile: string, projectFile: string): IFuture<void> {
return (() => {
if (!this.$fs.exists(projectFile).wait()) {
this.$fs.writeFile(projectFile, "").wait();
}

let mergeScript = `require 'xcodeproj'; Xcodeproj::Config.new('${projectFile}').merge(Xcodeproj::Config.new('${pluginFile}')).save_as(Pathname.new('${projectFile}'))`;
this.$childProcess.exec(`ruby -e "${mergeScript}"`).wait();
}).future<void>()();
}

private regeneratePluginsXcconfigFile(): IFuture<void> {
return (() => {
this.$fs.deleteFile(this.pluginsDebugXcconfigFilePath).wait();
this.$fs.deleteFile(this.pluginsReleaseXcconfigFilePath).wait();

let allPlugins: IPluginData[] = (<IPluginsService>this.$injector.resolve("pluginsService")).getAllInstalledPlugins().wait();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use constructor injection?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were some circular dependencies.

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).wait()) {
this.mergeXcconfigFiles(pluginXcconfigFilePath, this.pluginsDebugXcconfigFilePath).wait();
this.mergeXcconfigFiles(pluginXcconfigFilePath, this.pluginsReleaseXcconfigFilePath).wait();
}
}

let podFolder = path.join(this.platformData.projectRoot, "Pods/Target Support Files/Pods/");
if (this.$fs.exists(podFolder).wait()) {
this.mergeXcconfigFiles(path.join(this.platformData.projectRoot, "Pods/Target Support Files/Pods/Pods.debug.xcconfig"), this.pluginsDebugXcconfigFilePath).wait();
this.mergeXcconfigFiles(path.join(this.platformData.projectRoot, "Pods/Target Support Files/Pods/Pods.release.xcconfig"), this.pluginsReleaseXcconfigFilePath).wait();
}
}).future<void>()();
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/services/plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export class PluginsService implements IPluginsService {

public getAllInstalledPlugins(): IFuture<IPluginData[]> {
return (() => {
let nodeModules = this.getAllInstalledModules().wait();
let nodeModules = this.getAllInstalledModules().wait().map(nodeModuleData => this.convertToPluginData(nodeModuleData));
return _.filter(nodeModules, nodeModuleData => nodeModuleData && nodeModuleData.isPlugin);
}).future<IPluginData[]>()();
}
Expand Down