Skip to content
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

Fix dependency framework/library linking #93

Merged
merged 4 commits into from
Oct 18, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
BF3862341101 /* MyFramework.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = FR2993497801 /* MyFramework.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
BF5986511201 = {isa = PBXBuildFile; fileRef = FR6523263101 /* TestProject.app */; };
BF6182896901 /* Result.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FR9215298301 /* Result.framework */; };
BF7015992001 /* MyFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FR2993497801 /* MyFramework.framework */; };
BF9001417701 /* TestProjectTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR6877173101 /* TestProjectTests.swift */; };
BF9155249601 /* FrameworkFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR7078510801 /* FrameworkFile.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -80,6 +81,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
BF7015992001 /* MyFramework.framework in Frameworks */,
BF6182896901 /* Result.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
8 changes: 8 additions & 0 deletions Sources/ProjectSpec/ProjectExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ extension PBXProductType {
}
}

public var isFramework: Bool {

Choose a reason for hiding this comment

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

I'd add some tests here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

return self == .framework
}

public var isLibrary: Bool {
return self == .staticLibrary || self == .dynamicLibrary
}

public var isExtension: Bool {
return fileExtension == "appex"
}
Expand Down
16 changes: 10 additions & 6 deletions Sources/XcodeGenKit/PBXProjGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class PBXProjGenerator {
var variantGroupsByPath: [Path: PBXVariantGroup] = [:]

var targetNativeReferences: [String: String] = [:]
var targetBuildFileReferences: [String: String] = [:]
var targetBuildFiles: [String: PBXBuildFile] = [:]
var targetFileReferences: [String: String] = [:]
var topLevelGroups: [PBXGroup] = []
var carthageFrameworksByPlatform: [String: [String]] = [:]
Expand Down Expand Up @@ -93,7 +93,7 @@ public class PBXProjGenerator {

let buildFile = PBXBuildFile(reference: generateUUID(PBXBuildFile.self, fileReference.reference), fileRef: fileReference.reference)
addObject(buildFile)
targetBuildFileReferences[target.name] = buildFile.reference
targetBuildFiles[target.name] = buildFile
}

let targets = try spec.targets.map(generateTarget)
Expand Down Expand Up @@ -249,11 +249,15 @@ public class PBXProjGenerator {
addObject(targetDependency)
dependencies.append(targetDependency.reference)

// don't bother linking a target dependency
// let dependencyBuildFile = targetBuildFileReferences[dependencyTargetName]!
// targetFrameworkBuildFiles.append(dependencyBuildFile)
if dependencyTarget.type.isLibrary || dependencyTarget.type.isFramework {
let dependencyBuildFile = targetBuildFiles[dependencyTargetName]!
let buildFile = PBXBuildFile(reference: generateUUID(PBXBuildFile.self, dependencyBuildFile.reference + target.name), fileRef: dependencyBuildFile.fileRef)
addObject(buildFile)
targetFrameworkBuildFiles.append(buildFile.reference)
}

if embed && !dependencyTarget.type.isLibrary {

if embed {
let embedSettings = dependency.buildSettings
let embedFile = PBXBuildFile(reference: generateUUID(PBXBuildFile.self, dependencyFileReference + target.name), fileRef: dependencyFileReference, settings: embedSettings)
addObject(embedFile)
Expand Down
1 change: 1 addition & 0 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ XCTMain([
testCase(GeneratorTests.allTests),
testCase(SpecLoadingTests.allTests),
testCase(FixtureTests.allTests),
testCase(ProjectSpecTests.allTests),
])
28 changes: 28 additions & 0 deletions Tests/XcodeGenKitTests/ProjectSpecTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Spectre
import XcodeGenKit
import xcproj
import ProjectSpec

func projectSpecTests() {

describe("ProjectSpec") {

let framework = Target(name: "MyFramework", type: .framework, platform: .iOS,
settings: Settings(buildSettings: ["SETTING_2": "VALUE"]))
let staticLibrary = Target(name: "MyStaticLibrary", type: .staticLibrary, platform: .iOS,
settings: Settings(buildSettings: ["SETTING_2": "VALUE"]))
let dynamicLibrary = Target(name: "MyDynamicLibrary", type: .dynamicLibrary, platform: .iOS,
settings: Settings(buildSettings: ["SETTING_2": "VALUE"]))

$0.describe("Types") {
$0.it("is a framework when it has the right extension") {
try expect(framework.type.isFramework).to.beTrue()
}

$0.it("is a library when it has the right type") {
try expect(staticLibrary.type.isLibrary).to.beTrue()
try expect(dynamicLibrary.type.isLibrary).to.beTrue()
}
}
}
}
1 change: 1 addition & 0 deletions Tests/XcodeGenKitTests/XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ class XCodeGenKitTests: XCTestCase {
projectGeneratorTests()
specLoadingTests()
fixtureTests()
projectSpecTests()
}
}