Skip to content

Bugfix: settings override on occasion (v. 2.14.0) #812

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

Open
wants to merge 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#### Fixed
- Fixed resolving path to local Swift Packages [#796](https://github.com/yonaskolb/XcodeGen/pull/796) @freddi-kit
- Added ability to stop on every main thread checker issue on Run schemes and TargetSchemes [#799](https://github.com/yonaskolb/XcodeGen/pull/799) @ionutivan
- Fixed occasional build settings override for configs with partially matching names [#812](https://github.com/yonaskolb/XcodeGen/pull/812) @tralf

## 2.14.0

Expand Down
2 changes: 1 addition & 1 deletion Sources/XcodeGenKit/SettingsBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ extension Project {
buildSettings += settings.buildSettings

for (configVariant, settings) in settings.configSettings {
let isPartialMatch = config.name.lowercased().contains(configVariant.lowercased())
let isPartialMatch = config.name.lowercased().split(separator: " ").contains(Substring(configVariant.lowercased()))
Copy link
Owner

Choose a reason for hiding this comment

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

As far as I can see this would be a breaking change, as putting stag for Staging Release would now fail, as this is now matching whole words instead of any substring.
We could change this so it finds a config in the following order:

  • an exact match
  • matching a word (space delimited)
  • any substring

Copy link
Author

Choose a reason for hiding this comment

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

Got your point, thank you! I'll update the fix and add extra tests to cover this scenario as soon as have time.

if isPartialMatch {
let exactConfig = getConfig(configVariant)
let matchesExactlyToOtherConfig = exactConfig != nil && exactConfig?.name != config.name
Expand Down
27 changes: 27 additions & 0 deletions Tests/XcodeGenKitTests/ProjectGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,33 @@ class ProjectGeneratorTests: XCTestCase {
try expect(buildSettings["SETTING3"]).beNil()
}

$0.it("doesn't mix up config settings for partially matching names") {
let project = Project(
name: "test",
configs: [
Config(name: "Rod Release", type: .release),
Config(name: "Prod Release", type: .release),
Config(name: "Preprod Release", type: .release),
],
settings: Settings(configSettings: [
"Prod": ["SETTING1": "VALUE2"],
"Rod": ["SETTING1": "VALUE1"],
"Preprod": ["SETTING1": "VALUE3"],
])
)

var buildSettings = project.getProjectBuildSettings(config: project.configs[0])
try expect(buildSettings["SETTING1"] as? String) == "VALUE1"

// Rod settings shouldn't override Prod
buildSettings = project.getProjectBuildSettings(config: project.configs[1])
try expect(buildSettings["SETTING1"] as? String) == "VALUE2"

// Prod or Rod settings shouldn't override Preprod
buildSettings = project.getProjectBuildSettings(config: project.configs[2])
try expect(buildSettings["SETTING1"] as? String) == "VALUE3"
}

$0.it("sets project SDKROOT if there is only a single platform") {
var project = Project(
name: "test",
Expand Down