Skip to content

Commit

Permalink
[Config] Make #to_hash include import statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Renzo Crisóstomo committed Sep 27, 2017
1 parent 0760750 commit 73fd5b6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 2 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Expand Up @@ -8,7 +8,9 @@

##### Bug Fixes

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


## 1.5.2 (2017-09-24)
Expand All @@ -17,7 +19,7 @@

* Resolve variable substitution for xcconfig declared build settings
[Ruenzuo](https://github.com/Ruenzuo)
[#501](https://github.com/CocoaPods/CocoaPods/issues/501)
[#501](https://github.com/CocoaPods/Xcodeproj/issues/501)

##### Bug Fixes

Expand Down
11 changes: 11 additions & 0 deletions lib/xcodeproj/config.rb
Expand Up @@ -134,6 +134,15 @@ def to_hash(prefix = nil)
inherited = %w($(inherited) ${inherited}).freeze
result.reject! { |_, v| inherited.any? { |i| i == v.to_s.strip } }

result = @includes.map do |incl|
path = File.expand_path(incl, @filepath.dirname)
if File.readable? path
Xcodeproj::Config.new(path).to_hash
else
{}
end
end.inject(&:merge).merge(result) unless @filepath.nil? || @includes.empty?

if prefix
Hash[result.map { |k, v| [prefix + k, v] }]
else
Expand Down Expand Up @@ -237,8 +246,10 @@ def dup
#
def extract_hash(argument)
if argument.respond_to? :read
@filepath = Pathname.new(argument.to_path)
hash_from_file_content(argument.read)
elsif File.readable?(argument.to_s)
@filepath = Pathname.new(argument.to_s)
hash_from_file_content(File.read(argument))
else
argument
Expand Down
13 changes: 13 additions & 0 deletions spec/config_spec.rb
Expand Up @@ -8,6 +8,7 @@
@hash = { 'OTHER_LDFLAGS' => '-framework "Foundation"' }
@config = Xcodeproj::Config.new(@hash)
@config_fixture = fixture_path('oneline-key-value.xcconfig')
@config_with_include_fixture = fixture_path('config-with-include.xcconfig')
end

it 'can be created with hash' do
Expand Down Expand Up @@ -286,6 +287,18 @@ def filename.open(mode)
config.merge!('OTHER_LDFLAGS' => '-l"Pods-Intercom"')
config.to_hash['OTHER_LDFLAGS'].should == '-ObjC -l"Pods-GoogleAnalytics-iOS-SDK" -l"Pods-Intercom" -force_load $(PODS_ROOT)/Intercom/Intercom/libIntercom.a'
end

it 'processes include statements if initialized with filepath' do
xcconfig_file = File.new(@config_with_include_fixture)
xcconfig = Xcodeproj::Config.new(xcconfig_file)
xcconfig.to_hash.should == {
'FIRST_BUILD_SETTING' => 'YES',
'SECOND_BUILD_SETTING' => 'YES',
'THIRD_BUILD_SETTING' => 'YES',
'A_BUILD_SETTING' => 'OVERRIDE',
'ANOTHER_BUILD_SETTING' => 'SHOULD_PRECEDE',
}
end
end

#---------------------------------------------------------------------------#
Expand Down
5 changes: 5 additions & 0 deletions spec/fixtures/another-config-with-include.xcconfig
@@ -0,0 +1,5 @@
#include "config-without-include.xcconfig"

SECOND_BUILD_SETTING = YES
A_BUILD_SETTING = THIS_VALUE_SHOULD_BE_OVERRIDEN
ANOTHER_BUILD_SETTING = SHOULD_PRECEDE
4 changes: 4 additions & 0 deletions spec/fixtures/config-with-include.xcconfig
@@ -0,0 +1,4 @@
#include "another-config-with-include.xcconfig"

FIRST_BUILD_SETTING = YES
A_BUILD_SETTING = OVERRIDE
2 changes: 2 additions & 0 deletions spec/fixtures/config-without-include.xcconfig
@@ -0,0 +1,2 @@
THIRD_BUILD_SETTING = YES
ANOTHER_BUILD_SETTING = SHOULD_NOT_TAKE_PRECEDENCE

0 comments on commit 73fd5b6

Please sign in to comment.