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

Generate UI Test Target Attributes #221

Merged
merged 7 commits into from
Jan 10, 2018
Merged
Changes from 2 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
41 changes: 40 additions & 1 deletion Sources/XcodeGenKit/PBXProjGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ public class PBXProjGenerator {

sortGroups(group: mainGroup)

let projectAttributes: [String: Any] = ["LastUpgradeCheck": spec.xcodeVersion].merged(spec.attributes)
let projectAttributes: [String: Any] = ["LastUpgradeCheck": spec.xcodeVersion]
.merged(spec.attributes)
.merged(self.generateTargetAttributes() ?? [:])

let root = PBXProject(
name: spec.name,
reference: proj.rootObject,
Expand All @@ -173,6 +176,42 @@ public class PBXProjGenerator {

return proj
}

func generateTargetAttributes() -> [String: Any]? {


var targetAttributes: [String: Any] = [:]

// look up TEST_TARGET_NAME build setting
func testTargetName(_ target: PBXTarget) -> String? {
guard let configurationList = target.buildConfigurationList else { return nil }
guard let buildConfigurationReferences = self.proj.objects.configurationLists[configurationList]?.buildConfigurations else { return nil }

let configs = buildConfigurationReferences
.flatMap { ref in self.proj.objects.buildConfigurations[ref] }

return configs
.flatMap { $0.buildSettings["TEST_TARGET_NAME"] as? String }
Copy link
Owner

Choose a reason for hiding this comment

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

It's interesting that this could change across configs. I wonder how Xcode deals with this. This is probably fine though

Copy link
Author

Choose a reason for hiding this comment

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

I was wondering about that too.
Xcode doesnt let you specify this on a per configuration basis.
Meaning it adds the TEST_TARGET_NAME setting to all configurations.
and then (i assume) generates the target-attributes.

.first
}

let uiTestTargets = self.proj.objects.nativeTargets.values
.filter { $0.productType == .uiTestBundle }

for uiTestTarget in uiTestTargets {
guard let name = testTargetName(uiTestTarget) else { continue }
guard let target = self.proj.objects.targets(named: name).first else { continue }

targetAttributes[uiTestTarget.reference] = [ "TestTargetID": target.reference]
}

guard !targetAttributes.isEmpty else { return nil }

return [
"TargetAttributes": targetAttributes
]

}

func sortGroups(group: PBXGroup) {
// sort children
Expand Down