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

allow aggregate targets to have project external targets #1260

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion Sources/ProjectSpec/SpecValidation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ extension Project {

for target in aggregateTargets {
for dependency in target.targets {
if getProjectTarget(dependency) == nil {
if getProjectTarget(dependency) == nil, let projectName = dependency.components(separatedBy: "/").first,
(getPackage(projectName) == nil && getProjectReference(projectName) == nil) {
errors.append(.invalidTargetDependency(target: target.name, dependency: dependency))
}
}
Expand Down
28 changes: 27 additions & 1 deletion Sources/XcodeGenKit/PBXProjGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,33 @@ public class PBXProjGenerator {
return addObject(buildConfig)
}

let dependencies = target.targets.map { generateTargetDependency(from: target.name, to: $0, platform: nil) }
let dependencies: [PBXTargetDependency] = target.targets.map {
let dependency = $0
if dependency.contains("/") && dependency.components(separatedBy: "/").count == 2 {
let tokens: [String] = dependency.components(separatedBy: "/")
let projectName: String = tokens[0]
let targetName: String = tokens[1]

if nil != project.packages[projectName] {
let productName = targetName
let packageDependency = addObject(
XCSwiftPackageProductDependency(productName: productName)
)

let targetDependency = addObject(
PBXTargetDependency( product: packageDependency)
)
return targetDependency
}

do {
return try generateExternalTargetDependency(from: target.name, to: targetName, in: projectName, platform: .iOS).0
} catch {
print("Error: \(error)")
}
}
return generateTargetDependency(from: target.name, to: $0, platform: nil)
}

let defaultConfigurationName = project.options.defaultConfig ?? project.configs.first?.name ?? ""
let buildConfigList = addObject(XCConfigurationList(
Expand Down
1 change: 1 addition & 0 deletions Tests/Fixtures/paths_test/included_paths_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ aggregateTargets:
IncludedAggregateTarget:
targets:
- IncludedTarget
- AnotherProject/ExternalTarget
configFiles:
Config: config
buildScripts:
Expand Down
2 changes: 1 addition & 1 deletion Tests/ProjectSpecTests/SpecLoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class SpecLoadingTests: XCTestCase {
try expect(project.aggregateTargets) == [
AggregateTarget(
name: "IncludedAggregateTarget",
targets: ["IncludedTarget"],
targets: ["IncludedTarget", "AnotherProject/ExternalTarget"],
configFiles: ["Config": "paths_test/config"],
buildScripts: [BuildScript(script: .path("paths_test/buildScript"))]
),
Expand Down
19 changes: 14 additions & 5 deletions Tests/XcodeGenKitTests/ProjectGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,21 @@ class ProjectGeneratorTests: XCTestCase {

func testAggregateTargets() {
describe {

let externalProjectPath = fixturePath + "TestProject/AnotherProject/AnotherProject.xcodeproj"
let projectReference1 = ProjectReference(name: "AnotherProject", path: externalProjectPath.string)

var target = app
target.dependencies = [
Dependency(type: .target, reference: "AnotherProject/ExternalTarget")
]

let otherTarget = Target(name: "Other", type: .framework, platform: .iOS, dependencies: [Dependency(type: .target, reference: "AggregateTarget")])
let otherTarget2 = Target(name: "Other2", type: .framework, platform: .iOS, dependencies: [Dependency(type: .target, reference: "Other")], transitivelyLinkDependencies: true)
let aggregateTarget = AggregateTarget(name: "AggregateTarget", targets: ["MyApp", "MyFramework"])
let aggregateTarget = AggregateTarget(name: "AggregateTarget", targets: ["MyApp", "MyFramework", "AnotherProject/ExternalTarget"])
let aggregateTarget2 = AggregateTarget(name: "AggregateTarget2", targets: ["AggregateTarget"])
let project = Project(name: "test", targets: [app, framework, otherTarget, otherTarget2], aggregateTargets: [aggregateTarget, aggregateTarget2])

let project = Project(name: "test", targets: [target, framework, otherTarget, otherTarget2], aggregateTargets: [aggregateTarget, aggregateTarget2], projectReferences: [projectReference1])


$0.it("generates aggregate targets") {
let pbxProject = try project.generatePbxProj()
Expand All @@ -259,7 +268,7 @@ class ProjectGeneratorTests: XCTestCase {
try expect(aggregateTargets.count) == 2

let aggregateTarget1 = aggregateTargets.first { $0.name == "AggregateTarget" }
try expect(aggregateTarget1?.dependencies.count) == 2
try expect(aggregateTarget1?.dependencies.count) == 3

let aggregateTarget2 = aggregateTargets.first { $0.name == "AggregateTarget2" }
try expect(aggregateTarget2?.dependencies.count) == 1
Expand All @@ -270,7 +279,7 @@ class ProjectGeneratorTests: XCTestCase {
let target2 = nativeTargets.first { $0.name == "Other2" }
try expect(target2?.dependencies.count) == 2

try expect(pbxProject.targetDependencies.count) == 7
try expect(pbxProject.targetDependencies.count) == 8
}
}
}
Expand Down