Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #13 from unsignedapps/feature/xcconfig
Browse files Browse the repository at this point in the history
XCConfig Support
  • Loading branch information
bok- authored Jul 1, 2020
2 parents 6d4c39c + 43b106e commit 7b7b4aa
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Sources/CreateXCFramework/Command+Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ extension Command {

@Flag(help: "Prints the available products and targets")
var listProducts: Bool

@Option(help: "The path to a .xcconfig file that can be used to override Xcode build settings. Relative to the package path.")
var xcconfig: String?


// MARK: - Output Options
Expand Down
6 changes: 2 additions & 4 deletions Sources/CreateXCFramework/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct Command: ParsableCommand {
let platforms = try package.supportedPlatforms()

// get what we're building
try generator.writeXcconfig()
try generator.writeDistributionXcconfig()
let project = try generator.generate()

// printing packages?
Expand All @@ -65,9 +65,7 @@ struct Command: ParsableCommand {

// we've applied the xcconfig to everything, but some dependencies (*cough* swift-nio)
// have build errors, so we remove it from targets we're not building
for target in project.targets where productNames.contains(target.name) == false {
target.buildSettings.xcconfigFileRef = nil
}
try project.enableDistribution(targets: productNames, xcconfig: AbsolutePath(package.distributionBuildXcconfig.path).relative(to: AbsolutePath(package.rootDirectory.path)))

// save the project
try project.save(to: generator.projectPath)
Expand Down
17 changes: 16 additions & 1 deletion Sources/CreateXCFramework/PackageInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,22 @@ struct PackageInfo {
.appendingPathComponent("Distribution.xcconfig")
.absoluteURL
}


var overridesXcconfig: Foundation.URL? {
guard let path = self.options.xcconfig else { return nil }

// absolute path
if path.hasPrefix("/") {
return Foundation.URL(fileURLWithPath: path)

// strip current directory if thats where we are
} else if path.hasPrefix("./") {
return self.rootDirectory.appendingPathComponent(String(path[path.index(path.startIndex, offsetBy: 2)...]))
}

return self.rootDirectory.appendingPathComponent(path)
}

// TODO: Map diagnostics to swift-log
let diagnostics = DiagnosticsEngine()

Expand Down
51 changes: 45 additions & 6 deletions Sources/CreateXCFramework/ProjectGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ struct ProjectGenerator {
private enum Constants {
static let `extension` = "xcodeproj"
}



// MARK: - Properties

let package: PackageInfo
Expand All @@ -24,19 +25,32 @@ struct ProjectGenerator {
let dir = AbsolutePath(self.package.projectBuildDirectory.path)
return buildXcodeprojPath(outputDir: dir, projectName: self.package.package.name)
}



// MARK: - Initialisation

init (package: PackageInfo) {
self.package = package
}



// MARK: - Generation

/// Writes out the Xcconfig file
func writeXcconfig () throws {
func writeDistributionXcconfig () throws {
try makeDirectories(self.projectPath)
try open(AbsolutePath(self.package.distributionBuildXcconfig.path)) { stream in

let path = AbsolutePath(self.package.distributionBuildXcconfig.path)
try open(path) { stream in
if let absolutePath = self.package.overridesXcconfig?.path {
stream (
"""
#include "\(AbsolutePath(absolutePath).relative(to: AbsolutePath(path.dirname)).pathString)"
"""
)
}

stream (
"""
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
Expand All @@ -59,19 +73,44 @@ struct ProjectGenerator {
graph: self.package.graph,
extraDirs: [],
extraFiles: [],
options: XcodeprojOptions(xcconfigOverrides: AbsolutePath(self.package.distributionBuildXcconfig.path)),
options: XcodeprojOptions(xcconfigOverrides: (self.package.overridesXcconfig?.path).flatMap { AbsolutePath($0) }),
diagnostics: self.package.diagnostics
)

return project
}

}


// MARK: - Saving Xcode Projects

extension Xcode.Project {

/// This is the group that is normally created in Xcodeproj.xcodeProject() when you specify an xcconfigOverride
var configGroup: Xcode.Group {
let name = "Configs"

if let group = self.mainGroup.subitems.lazy.compactMap({ $0 as? Xcode.Group }).first(where: { $0.name == name }) {
return group
}

// doesn't exist - lets creat it
return self.mainGroup.addGroup(path: "", name: name)
}

func enableDistribution (targets: [String], xcconfig: RelativePath) throws {
let group = self.configGroup
let ref = group.addFileReference (
path: xcconfig.pathString,
name: xcconfig.basename
)

for target in self.targets where targets.contains(target.name) {
target.buildSettings.xcconfigFileRef = ref
}
}

func save (to path: AbsolutePath) throws {
try open(path.appending(component: "project.pbxproj")) { stream in
// Serialize the project model we created to a plist, and return
Expand Down
6 changes: 6 additions & 0 deletions action.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ async function run () {
let targets = core.getInput('target', { required: false })
let configuration = core.getInput('configuration', { required: false })
let platforms = core.getInput('platforms', { required: false })
let xcconfig = core.getInput('xcconfig', { required: false })

// install mint if its not installed
await installUsingBrewIfRequired("mint")
Expand All @@ -34,6 +35,11 @@ async function run () {
options.push(configuration)
}

if (!!xcconfig) {
options.push('--xcconfig')
options.push(xcconfig)
}

if (!!platforms) {
platforms
.split(',')
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ inputs:
description: "Build with a specific configuration ('debug' or 'release')"
required: false
default: release
xcconfig:
description: "The path to a .xcconfig file that can be used to override Xcode build settings. Relative to the package path."
required: false

runs:
using: node12
Expand Down

0 comments on commit 7b7b4aa

Please sign in to comment.