Merge pull request #277 from yonaskolb/set_signing_attributes

Automatically set DevelopmentTeam and ProvisioningStyle TargetAttributes
This commit is contained in:
Yonas Kolb
2018-03-27 16:37:41 +11:00
committed by GitHub
4 changed files with 36 additions and 7 deletions
+4 -1
View File
@@ -165,7 +165,10 @@ Settings are merged in the following order: groups, base, configs.
- [ ] **dependencies**: **[[Dependency](#dependency)]** - Dependencies for the target
- [ ] **scheme**: **[Target Scheme](#target-scheme)** - Generated scheme with tests or config variants
- [ ] **legacy**: **[Legacy Target](#legacy-target)** - When present, opt-in to make an Xcode "External Build System" legacy target instead.
- [ ] **attributes**: **[String: Any]** - This sets values in the project `TargetAttributes`. It is merged with `attributes` from the project and anything automatically added by XcodeGen, with any duplicate values being override by values specified here. This is for advanced use only.
- [ ] **attributes**: **[String: Any]** - This sets values in the project `TargetAttributes`. It is merged with `attributes` from the project and anything automatically added by XcodeGen, with any duplicate values being override by values specified here. This is for advanced use only. Properties that are already set include:
- `DevelopmentTeam`: if all configurations have the same `DEVELOPMENT_TEAM` setting
- `ProvisioningStyle`: if all configurations have the same `CODE_SIGN_STYLE` setting
- `TestTargetID`: if all configurations have the same `TEST_TARGET_NAME` setting
### Product Type
+3 -3
View File
@@ -5,9 +5,9 @@ import xcproj
public struct Settings: Equatable, JSONObjectConvertible, CustomStringConvertible {
public let buildSettings: BuildSettings
public let configSettings: [String: Settings]
public let groups: [String]
public var buildSettings: BuildSettings
public var configSettings: [String: Settings]
public var groups: [String]
public init(buildSettings: BuildSettings = [:], configSettings: [String: Settings] = [:], groups: [String] = []) {
self.buildSettings = buildSettings
+26 -2
View File
@@ -243,9 +243,33 @@ public class PBXProjGenerator {
}
for target in spec.targets {
if !target.attributes.isEmpty, let targetObject = targetObjects[target.name] {
targetAttributes[targetObject.reference, default: [:]].merge(target.attributes)
guard let targetReference = targetObjects[target.name]?.reference else {
continue
}
if !target.attributes.isEmpty {
targetAttributes[targetReference, default: [:]].merge(target.attributes)
}
func getSingleBuildSetting(_ setting: String) -> String? {
let settings = spec.configs.flatMap {
spec.getCombinedBuildSettings(basePath: spec.basePath, target: target, config: $0)[setting] as? String
}
guard settings.count == spec.configs.count,
let firstSetting = settings.first,
settings.filter({ $0 == firstSetting}).count == settings.count else {
return nil
}
return firstSetting
}
func setTargetAttribute(attribute: String, buildSetting: String) {
if let setting = getSingleBuildSetting(buildSetting) {
targetAttributes[targetReference, default: [:]].merge([attribute: setting])
}
}
setTargetAttribute(attribute: "ProvisioningStyle", buildSetting: "CODE_SIGN_STYLE")
setTargetAttribute(attribute: "DevelopmentTeam", buildSetting: "DEVELOPMENT_TEAM")
}
return targetAttributes.isEmpty ? nil : ["TargetAttributes": targetAttributes]
@@ -209,10 +209,11 @@ func projectGeneratorTests() {
$0.it("generates target attributes") {
var appTargetWithAttributes = application
appTargetWithAttributes.settings.buildSettings["DEVELOPMENT_TEAM"] = "123"
appTargetWithAttributes.attributes = ["ProvisioningStyle": "Automatic"]
var testTargetWithAttributes = uiTest
testTargetWithAttributes.attributes = ["ProvisioningStyle": "Manual"]
testTargetWithAttributes.settings.buildSettings["CODE_SIGN_STYLE"] = "Manual"
var spec = ProjectSpec(basePath: "", name: "test", targets: [appTargetWithAttributes, framework, testTargetWithAttributes])
let pbxProject = try getPbxProj(spec)
@@ -231,6 +232,7 @@ func projectGeneratorTests() {
try expect(targetAttributes[uiTestTarget.reference]?["TestTargetID"] as? String) == appTarget.reference
try expect(targetAttributes[uiTestTarget.reference]?["ProvisioningStyle"] as? String) == "Manual"
try expect(targetAttributes[appTarget.reference]?["ProvisioningStyle"] as? String) == "Automatic"
try expect(targetAttributes[appTarget.reference]?["DevelopmentTeam"] as? String) == "123"
}
$0.it("generates platform version") {