CocoaPods / CocoaPods/Xcodeproj

Xcodeproj::Config merge does not de-duplicate all values

Open
#509 3 comments 3 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
2.4k
Forks
488
PR merge metrics
No merged PRs in 30d

Description

While working on https://github.com/CocoaPods/CocoaPods/pull/6401 I stumbled on a case where I believe the `merge!` method of Xcodeproj::Config is not returning what is expected.

If the two merged xcconfig files include a variable with both mutual "sub-values" but also different ones, the output of the merge will contain some duplicated values.

Let me explain more clearly with an example:

left.xcconfig:

```
HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/JSONKit"
```

right.xcconfig:

```
HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/Reachability
```

The expected result is (in my opinion):

```
HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/JSONKit" "${PODS_ROOT}/Headers/Public/Reachability"
```

But currently `merge!` will output:

```
HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/JSONKit" $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/Reachability"
```

duplicating the `$(inherited)` and `"${PODS_ROOT}/Headers/Public"` values.

-----------------------

Here's a test case for this behavior (currently failing):

```
it 'de-duplicates multiple values when merging' do
@config << { 'FOO' => 'bar spam' }
@config.merge!('FOO' => 'bar $(baz)')
@config.to_hash.should == {
'FOO' => 'bar spam $(baz)',
'OTHER_LDFLAGS' => '-framework "Foundation"',
}
end
```

output (notice how `bar` is duplicated):

```
Bacon::Error: {"FOO"=>"bar spam bar $(baz)", "OTHER_LDFLAGS"=>"-framework \"Foundation\""}.==({"FOO"=>"bar spam $(baz)", "OTHER_LDFLAGS"=>"-framework \"Foundation\""}) failed
```

---------------------

Is the current behavior expected or is this a bug? If it's the latter, I'd be happy to propose a patch :)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at Xcodeproj::Config#merge! and reproduce the supplied failing test for merging FOO values. Compare the result of @config.to_hash with the expected hash, including retaining each value only once; the issue is done when the test passes without duplicating shared sub-values.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.