Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#### Added
- Allow specifying a `github` name like `JohnSundell/Ink` instead of a full `url` for Swift Packages [#1029](https://github.com/yonaskolb/XcodeGen/pull/1029) @yonaskolb
- Added explicity `LastUpgradeCheck` and `LastUpgradeVersion` override support so it's possible to override these properties without using the `project.xcodeVersion`. [1013](https://github.com/yonaskolb/XcodeGen/pull/1013) @Andre113
- Added `macroExpansion` for `run` in `schemes` [#1036](https://github.com/yonaskolb/XcodeGen/pull/1036) @freddi-kit
- Added `askForAppToLaunch` for `profile` in `schemes` [#1035](https://github.com/yonaskolb/XcodeGen/pull/1035) @freddi-kit

Expand Down
2 changes: 1 addition & 1 deletion Docs/ProjectSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ You can also use environment variables in your configuration file, by using `${S
- [x] **name**: **String** - Name of the generated project
- [ ] **include**: **[Include](#include)** - One or more paths to other specs
- [ ] **options**: **[Options](#options)** - Various options to override default behaviour
- [ ] **attributes**: **[String: Any]** - The PBXProject attributes. This is for advanced use. This defaults to ``{"LastUpgradeCheck": "XcodeVersion"}`` with `xcodeVersion` being set by [Options](#options)`.xcodeVersion`
- [ ] **attributes**: **[String: Any]** - The PBXProject attributes. This is for advanced use. If no value is set for `LastUpgradeCheck`, it will be defaulted to ``{"LastUpgradeCheck": "XcodeVersion"}`` with `xcodeVersion` being set by [Options](#options)`.xcodeVersion`
- [ ] **configs**: **[Configs](#configs)** - Project build configurations. Defaults to `Debug` and `Release` configs
- [ ] **configFiles**: **[Config Files](#config-files)** - `.xcconfig` files per config
- [ ] **settings**: **[Settings](#settings)** - Project specific settings. Default base and config type settings will be applied first before any settings defined here
Expand Down
13 changes: 10 additions & 3 deletions Sources/XcodeGenKit/PBXProjGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,16 @@ public class PBXProjGenerator {
}.flatMap { $0 }
).sorted()

var projectAttributes: [String: Any] = ["LastUpgradeCheck": project.xcodeVersion]
.merged(project.attributes)

var projectAttributes: [String: Any] = project.attributes

// Set default LastUpgradeCheck if user did not specify
let lastUpgradeKey = "LastUpgradeCheck"
if !projectAttributes.contains(where: { (key, value) -> Bool in
key == lastUpgradeKey && value is String
}) {
projectAttributes[lastUpgradeKey] = project.xcodeVersion
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This code is the same as before, but it only replaces the key if it's a string, correct? Were you running into cases where devs were putting numbers in the project attributes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Almost. It will replace the key if the user did not specify a value for LastUpgradeCheck or if this value is not a string. In this case, it will keep the same behavior as today, using the project.xcodeVersion value.
I just felt it would be safer to validade if the value we're inserting is a String to avoid any strange values.

}

if !assetTags.isEmpty {
projectAttributes["knownAssetTags"] = assetTags
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/XcodeGenKit/SchemeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,11 @@ public class SchemeGenerator {
postActions: scheme.archive?.postActions.map(getExecutionAction) ?? []
)

let lastUpgradeVersion = project.attributes["LastUpgradeCheck"] as? String ?? project.xcodeVersion

return XCScheme(
name: scheme.name,
lastUpgradeVersion: project.xcodeVersion,
lastUpgradeVersion: lastUpgradeVersion,
version: project.schemeVersion,
buildAction: buildAction,
testAction: testAction,
Expand Down
2 changes: 1 addition & 1 deletion Sources/XcodeGenKit/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ProjectSpec

extension Project {

var xcodeVersion: String {
public var xcodeVersion: String {
XCodeVersion.parse(options.xcodeVersion ?? "12.0")
}

Expand Down
40 changes: 39 additions & 1 deletion Tests/XcodeGenKitTests/PBXProjGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,43 @@ class PBXProjGeneratorTests: XCTestCase {
}
}
}


func testDefaultLastUpgradeCheckWhenUserDidSpecifyInvalidValue() throws {
let lastUpgradeKey = "LastUpgradeCheck"
let attributes: [String: Any] = [lastUpgradeKey: 1234]
let project = Project(name: "Test", attributes: attributes)
let projGenerator = PBXProjGenerator(project: project)

let pbxProj = try projGenerator.generate()

for pbxProject in pbxProj.projects {
XCTAssertEqual(pbxProject.attributes[lastUpgradeKey] as? String, project.xcodeVersion)
}
}

func testOverrideLastUpgradeCheckWhenUserDidSpecifyValue() throws {
let lastUpgradeKey = "LastUpgradeCheck"
let lastUpgradeValue = "1234"
let attributes: [String: Any] = [lastUpgradeKey: lastUpgradeValue]
let project = Project(name: "Test", attributes: attributes)
let projGenerator = PBXProjGenerator(project: project)

let pbxProj = try projGenerator.generate()

for pbxProject in pbxProj.projects {
XCTAssertEqual(pbxProject.attributes[lastUpgradeKey] as? String, lastUpgradeValue)
}
}

func testDefaultLastUpgradeCheckWhenUserDidNotSpecifyValue() throws {
let lastUpgradeKey = "LastUpgradeCheck"
let project = Project(name: "Test")
let projGenerator = PBXProjGenerator(project: project)

let pbxProj = try projGenerator.generate()

for pbxProject in pbxProj.projects {
XCTAssertEqual(pbxProject.attributes[lastUpgradeKey] as? String, project.xcodeVersion)
}
}
}
26 changes: 26 additions & 0 deletions Tests/XcodeGenKitTests/SchemeGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,32 @@ class SchemeGeneratorTests: XCTestCase {
}
}
}

func testOverrideLastUpgradeVersionWhenUserDidSpecify() throws {
var target = app
target.scheme = TargetScheme()

let lastUpgradeKey = "LastUpgradeCheck"
let lastUpgradeValue = "1234"
let attributes: [String: Any] = [lastUpgradeKey: lastUpgradeValue]
let project = Project(name: "test", targets: [target, framework], attributes: attributes)
let xcodeProject = try project.generateXcodeProject()

let xcscheme = try unwrap(xcodeProject.sharedData?.schemes.first)
XCTAssertEqual(xcscheme.lastUpgradeVersion, lastUpgradeValue)
}


func testDefaultLastUpgradeVersionWhenUserDidNotSpecify() throws {
var target = app
target.scheme = TargetScheme()

let project = Project(name: "test", targets: [target, framework])
let xcodeProject = try project.generateXcodeProject()

let xcscheme = try unwrap(xcodeProject.sharedData?.schemes.first)
XCTAssertEqual(xcscheme.lastUpgradeVersion, project.xcodeVersion)
}

// MARK: - Helpers

Expand Down