diff --git a/CHANGELOG.md b/CHANGELOG.md index e2bc81b32..5a5bda35b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) @@ -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 diff --git a/lib/xcodeproj/config.rb b/lib/xcodeproj/config.rb index dc31afa1a..ac46533d1 100644 --- a/lib/xcodeproj/config.rb +++ b/lib/xcodeproj/config.rb @@ -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 @@ -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 diff --git a/spec/config_spec.rb b/spec/config_spec.rb index bb4318c8c..eee8bb328 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -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 @@ -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 #---------------------------------------------------------------------------# diff --git a/spec/fixtures/another-config-with-include.xcconfig b/spec/fixtures/another-config-with-include.xcconfig new file mode 100644 index 000000000..01fee4d19 --- /dev/null +++ b/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 diff --git a/spec/fixtures/config-with-include.xcconfig b/spec/fixtures/config-with-include.xcconfig new file mode 100644 index 000000000..f2d14beee --- /dev/null +++ b/spec/fixtures/config-with-include.xcconfig @@ -0,0 +1,4 @@ +#include "another-config-with-include.xcconfig" + +FIRST_BUILD_SETTING = YES +A_BUILD_SETTING = OVERRIDE diff --git a/spec/fixtures/config-without-include.xcconfig b/spec/fixtures/config-without-include.xcconfig new file mode 100644 index 000000000..d9106b054 --- /dev/null +++ b/spec/fixtures/config-without-include.xcconfig @@ -0,0 +1,2 @@ +THIRD_BUILD_SETTING = YES +ANOTHER_BUILD_SETTING = SHOULD_NOT_TAKE_PRECEDENCE