Skip to content

Commit 0b7414a

Browse files
authored
Merge pull request #507 from Ruenzuo/parse_xcconfig_include_statements
[Config] Make #to_hash include import statements
2 parents 0760750 + 73fd5b6 commit 0b7414a

File tree

6 files changed

+39
-2
lines changed

6 files changed

+39
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
##### Bug Fixes
1010

11-
* None.
11+
* [Config] Make #to_bash include import statements
12+
[Ruenzuo](https://github.com/Ruenzuo)
13+
[#505](https://github.com/CocoaPods/Xcodeproj/issues/505)
1214

1315

1416
## 1.5.2 (2017-09-24)
@@ -17,7 +19,7 @@
1719

1820
* Resolve variable substitution for xcconfig declared build settings
1921
[Ruenzuo](https://github.com/Ruenzuo)
20-
[#501](https://github.com/CocoaPods/CocoaPods/issues/501)
22+
[#501](https://github.com/CocoaPods/Xcodeproj/issues/501)
2123

2224
##### Bug Fixes
2325

lib/xcodeproj/config.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ def to_hash(prefix = nil)
134134
inherited = %w($(inherited) ${inherited}).freeze
135135
result.reject! { |_, v| inherited.any? { |i| i == v.to_s.strip } }
136136

137+
result = @includes.map do |incl|
138+
path = File.expand_path(incl, @filepath.dirname)
139+
if File.readable? path
140+
Xcodeproj::Config.new(path).to_hash
141+
else
142+
{}
143+
end
144+
end.inject(&:merge).merge(result) unless @filepath.nil? || @includes.empty?
145+
137146
if prefix
138147
Hash[result.map { |k, v| [prefix + k, v] }]
139148
else
@@ -237,8 +246,10 @@ def dup
237246
#
238247
def extract_hash(argument)
239248
if argument.respond_to? :read
249+
@filepath = Pathname.new(argument.to_path)
240250
hash_from_file_content(argument.read)
241251
elsif File.readable?(argument.to_s)
252+
@filepath = Pathname.new(argument.to_s)
242253
hash_from_file_content(File.read(argument))
243254
else
244255
argument

spec/config_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@hash = { 'OTHER_LDFLAGS' => '-framework "Foundation"' }
99
@config = Xcodeproj::Config.new(@hash)
1010
@config_fixture = fixture_path('oneline-key-value.xcconfig')
11+
@config_with_include_fixture = fixture_path('config-with-include.xcconfig')
1112
end
1213

1314
it 'can be created with hash' do
@@ -286,6 +287,18 @@ def filename.open(mode)
286287
config.merge!('OTHER_LDFLAGS' => '-l"Pods-Intercom"')
287288
config.to_hash['OTHER_LDFLAGS'].should == '-ObjC -l"Pods-GoogleAnalytics-iOS-SDK" -l"Pods-Intercom" -force_load $(PODS_ROOT)/Intercom/Intercom/libIntercom.a'
288289
end
290+
291+
it 'processes include statements if initialized with filepath' do
292+
xcconfig_file = File.new(@config_with_include_fixture)
293+
xcconfig = Xcodeproj::Config.new(xcconfig_file)
294+
xcconfig.to_hash.should == {
295+
'FIRST_BUILD_SETTING' => 'YES',
296+
'SECOND_BUILD_SETTING' => 'YES',
297+
'THIRD_BUILD_SETTING' => 'YES',
298+
'A_BUILD_SETTING' => 'OVERRIDE',
299+
'ANOTHER_BUILD_SETTING' => 'SHOULD_PRECEDE',
300+
}
301+
end
289302
end
290303

291304
#---------------------------------------------------------------------------#
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "config-without-include.xcconfig"
2+
3+
SECOND_BUILD_SETTING = YES
4+
A_BUILD_SETTING = THIS_VALUE_SHOULD_BE_OVERRIDEN
5+
ANOTHER_BUILD_SETTING = SHOULD_PRECEDE
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include "another-config-with-include.xcconfig"
2+
3+
FIRST_BUILD_SETTING = YES
4+
A_BUILD_SETTING = OVERRIDE
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
THIRD_BUILD_SETTING = YES
2+
ANOTHER_BUILD_SETTING = SHOULD_NOT_TAKE_PRECEDENCE

0 commit comments

Comments
 (0)