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

Add XCBuildConfiguration.append public method #450

Merged
merged 4 commits into from Jun 25, 2019
Merged

Conversation

pepicrft
Copy link
Contributor

Resolves #395

Short description πŸ“

Add public method to conveniently append settings as suggested here

Implementation πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

  • Implement method.
  • Add unit tests.

@pepicrft pepicrft requested a review from a team June 23, 2019 07:48
@pepicrft pepicrft self-assigned this Jun 23, 2019
@pepicrft
Copy link
Contributor Author

Note that some of the changes of the diff were generated after running the code formatters.

@codecov
Copy link

codecov bot commented Jun 23, 2019

Codecov Report

Merging #450 into master will increase coverage by 0.11%.
The diff coverage is 96.55%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #450      +/-   ##
==========================================
+ Coverage   80.43%   80.55%   +0.11%     
==========================================
  Files         149      149              
  Lines        7652     7697      +45     
==========================================
+ Hits         6155     6200      +45     
  Misses       1497     1497
Impacted Files Coverage Ξ”
...ts/xcodeprojTests/Utils/PBXBatchUpdaterTests.swift 100% <ΓΈ> (ΓΈ) ⬆️
...s/SwiftPackage/XCRemoteSwiftPackageReference.swift 89.28% <100%> (ΓΈ) ⬆️
...SwiftPackage/XCSwiftPackageProductDependency.swift 93.75% <100%> (ΓΈ) ⬆️
...j/Objects/Configuration/XCBuildConfiguration.swift 82.5% <100%> (+5.83%) ⬆️
...ects/Configuration/XCBuildConfigurationTests.swift 100% <100%> (ΓΈ) ⬆️
Sources/xcodeproj/Objects/Targets/PBXTarget.swift 72.22% <100%> (ΓΈ) ⬆️
...codeproj/Objects/Files/PBXContainerItemProxy.swift 84.88% <80%> (ΓΈ) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data
Powered by Codecov. Last update aa14558...ba0ac58. Read the comment docs.

@codecov
Copy link

codecov bot commented Jun 23, 2019

Codecov Report

Merging #450 into master will increase coverage by 0.18%.
The diff coverage is 97.8%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #450      +/-   ##
==========================================
+ Coverage   80.94%   81.12%   +0.18%     
==========================================
  Files         147      148       +1     
  Lines        7592     7667      +75     
==========================================
+ Hits         6145     6220      +75     
  Misses       1447     1447
Impacted Files Coverage Ξ”
...ts/xcodeprojTests/Utils/PBXBatchUpdaterTests.swift 100% <ΓΈ> (ΓΈ) ⬆️
...ects/Configuration/XCBuildConfigurationTests.swift 100% <100%> (ΓΈ) ⬆️
Sources/xcodeproj/Project/XcodeProj.swift 45.74% <100%> (ΓΈ) ⬆️
...urces/xcodeproj/Scheme/XCScheme+LaunchAction.swift 58.54% <100%> (ΓΈ) ⬆️
...SwiftPackage/XCSwiftPackageProductDependency.swift 93.75% <100%> (ΓΈ) ⬆️
...s/SwiftPackage/XCRemoteSwiftPackageReference.swift 89.28% <100%> (ΓΈ) ⬆️
Sources/xcodeproj/Objects/Targets/PBXTarget.swift 72.22% <100%> (ΓΈ) ⬆️
Sources/xcodeproj/Extensions/Array+Extras.swift 100% <100%> (ΓΈ)
...j/Objects/Configuration/XCBuildConfiguration.swift 84.44% <100%> (+7.77%) ⬆️
...codeproj/Objects/Files/PBXContainerItemProxy.swift 84.88% <80%> (ΓΈ) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data
Powered by Codecov. Last update 8c77525...43295ee. Read the comment docs.

Copy link
Collaborator

@kwridan kwridan left a comment

Choose a reason for hiding this comment

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

this will be a nice addition to XcodeProj - will allow re-using some of the helpers from Tuist! πŸ‘

A few suggestions on some more cases that can be present with settings - especially as we have no control on what will be read from an existing project.

Array Settings

Xcode prefers array settings sometimes - it even goes as far as re-formatting the string with spaces to an array after opening the project.

e.g.

HEADER_SEARCH_PATHS = "$(inherited) \"My Libraries/MyLibraryA/include\" \"My Libraries/MyLibraryB/include\""

gets modified to:

HEADER_SEARCH_PATHS = (
		"$(inherited)",
		"\"My Libraries/MyLibraryA/include\"",
		"\"My Libraries/MyLibraryB/include\"",
        );

Other Settings

If I'm not mistaken, settings can be of type boolean too? Testing it out, settings with a boolean value e.g. "YES" are treated as strings within the library so not a 100% sure on this one.

let newValue = [existingValue, value].joined(separator: " ")

// Remove duplicates
let newValueComponents = Set(newValue.split(separator: " "))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some settings may have a space e.g. "My Libraries/MyLibraryA/include" - using a Set will shuffle the order of the reconstructed setting.

subject.append(setting: "OTHER_LDFLAGS", value: "flag2")

// Then
XCTAssertEqual(subject.buildSettings["OTHER_LDFLAGS"] as? String, "flag1 flag2")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I noticed this failed locally for me

XCTAssertEqual failed: ("Optional("flag2 flag1")") is not equal to ("Optional("flag1 flag2")")

It's due to using a Set to reconstruct the setting. I think this test itself is correct as it is, appending settings should append the new setting to the end.

@pepicrft
Copy link
Contributor Author

@kwridan I've added logic to handle the settings that are arrays of strings. I added the test that you proposed to test that it's properly handled.

Regarding booleans, I think it should be fine because they are stored as strings.

Notice in the changes that in the case of arrays, I'm removing the duplicates. That's not straightforward in the case of strings. I was thinking though about removing duplicated $(inherited)'s . What do you think?

@kwridan
Copy link
Collaborator

kwridan commented Jun 25, 2019

Thanks @pepibumur

Notice in the changes that in the case of arrays, I'm removing the duplicates. That's not straightforward in the case of strings. I was thinking though about removing duplicated $(inherited)'s . What do you think?

That's fair - perhaps we can just remove duplicates as a whole e.g.

case let string as String where string != value:

This will protect against the case where you append the same item twice.

func test_append_when_duplicateSettingExists() {
        // Given
        let subject = XCBuildConfiguration(name: "Debug",
                                           baseConfiguration: nil,
                                           buildSettings: ["OTHER_LDFLAGS": "flag1"])
        
        // When
        subject.append(setting: "OTHER_LDFLAGS", value: "flag1")
        
        // Then
        XCTAssertEqual(subject.buildSettings["OTHER_LDFLAGS"] as? String, "flag1")
    }

@pepicrft pepicrft merged commit 9833865 into master Jun 25, 2019
@pepicrft pepicrft deleted the append-setting branch June 25, 2019 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

XCBuildConfiguration helper method to append settings
2 participants