Commit 8a443085 authored by Marius Rackwitz's avatar Marius Rackwitz

[XCConfig] Implement the split of podspec xcconfig

parent a210a7e7
......@@ -103,6 +103,8 @@ module Pod
end
end
@xcconfig.merge!(merged_user_target_xcconfigs)
# TODO: Need to decide how we are going to ensure settings like these
# are always excluded from the user's project.
#
......@@ -148,6 +150,55 @@ module Pod
target.pod_targets_for_build_configuration(@configuration_name)
end
# Returns the +user_target_xcconfig+ for all pod targets grouped by keys
#
# @return [Hash{String,Hash{Target,String}]
#
def user_target_xcconfig_values_by_target_by_key
pod_targets.each_with_object({}) do |target, hash|
target.spec_consumers.each do |spec_consumer|
spec_consumer.user_target_xcconfig.each do |k, v|
(hash[k] ||= {})[target] = v
end
end
end
end
# Merges the +user_target_xcconfig+ for all pod targets into the
# #xcconfig and warns on conflicting definitions.
#
# @return [Hash{String, String}]
#
def merged_user_target_xcconfigs
settings = user_target_xcconfig_values_by_target_by_key
settings.each_with_object({}) do |(key, values_by_target), xcconfig|
uniq_values = values_by_target.values.uniq
values_are_bools = values_by_target.values.all? { |v| v =~ /(yes|no)/i }
if values_are_bools
# Boolean build settings
if uniq_values.count > 1
UI.warn 'Can\'t merge user_target_xcconfig for pod targets: ' \
"#{values_by_target.keys.map(&:label)}. Boolean build "\
"setting #{key} has different values."
else
xcconfig[key] = uniq_values.first
end
elsif key =~ /S$/
# Plural build settings
xcconfig[key] = uniq_values.join(' ')
else
# Singular build settings
if uniq_values.count > 1
UI.warn 'Can\'t merge user_target_xcconfig for pod targets: ' \
"#{values_by_target.keys.map(&:label)}. Singular build "\
"setting #{key} has different values."
else
xcconfig[key] = uniq_values.first
end
end
end
end
#---------------------------------------------------------------------#
end
end
......
......@@ -170,6 +170,70 @@ module Pod
generated.class.should == Xcodeproj::Config
end
end
#-----------------------------------------------------------------------#
describe 'with multiple pod targets with user_target_xcconfigs' do
before do
spec_b = fixture_spec('orange-framework/OrangeFramework.podspec')
@pod_target_b = fixture_pod_target(spec_b)
@consumer_a = @consumer
@consumer_b = @pod_target_b.spec_consumers.last
@target.pod_targets << @pod_target_b
end
describe 'with boolean build settings' do
it 'does not warn if the values are equal' do
@consumer_a.stubs(:user_target_xcconfig).returns('ENABLE_HEADER_DEPENDENCIES' => 'YES')
@consumer_b.stubs(:user_target_xcconfig).returns('ENABLE_HEADER_DEPENDENCIES' => 'YES')
@xcconfig = @generator.generate
@xcconfig.to_hash['ENABLE_HEADER_DEPENDENCIES'].should == 'YES'
end
it 'warns if the values differ' do
@consumer_a.stubs(:user_target_xcconfig).returns('ENABLE_HEADER_DEPENDENCIES' => 'YES')
@consumer_b.stubs(:user_target_xcconfig).returns('ENABLE_HEADER_DEPENDENCIES' => 'NO')
@xcconfig = @generator.generate
UI.warnings.should.include 'Can\'t merge user_target_xcconfig for pod targets: ' \
'["Pods-BananaLib", "Pods-OrangeFramework"]. Boolean build setting '\
'ENABLE_HEADER_DEPENDENCIES has different values.'
end
end
describe 'with list build settings' do
it 'only adds the value once if the values are equal' do
@consumer_a.stubs(:user_target_xcconfig).returns('OTHER_CPLUSPLUSFLAGS' => '-std=c++1y')
@consumer_b.stubs(:user_target_xcconfig).returns('OTHER_CPLUSPLUSFLAGS' => '-std=c++1y')
@xcconfig = @generator.generate
@xcconfig.to_hash['OTHER_CPLUSPLUSFLAGS'].should == '-std=c++1y'
end
it 'adds both values if the values differ' do
@consumer_a.stubs(:user_target_xcconfig).returns('OTHER_CPLUSPLUSFLAGS' => '-std=c++1y')
@consumer_b.stubs(:user_target_xcconfig).returns('OTHER_CPLUSPLUSFLAGS' => '-stdlib=libc++')
@xcconfig = @generator.generate
@xcconfig.to_hash['OTHER_CPLUSPLUSFLAGS'].should == '-std=c++1y -stdlib=libc++'
end
end
describe 'with singular build settings' do
it 'does not warn if the values are equal' do
@consumer_a.stubs(:user_target_xcconfig).returns('STRIP_STYLE' => 'non-global')
@consumer_b.stubs(:user_target_xcconfig).returns('STRIP_STYLE' => 'non-global')
@xcconfig = @generator.generate
@xcconfig.to_hash['STRIP_STYLE'].should == 'non-global'
end
it 'does warn if the values differ' do
@consumer_a.stubs(:user_target_xcconfig).returns('STRIP_STYLE' => 'non-global')
@consumer_b.stubs(:user_target_xcconfig).returns('STRIP_STYLE' => 'all')
@xcconfig = @generator.generate
UI.warnings.should.include 'Can\'t merge user_target_xcconfig for pod targets: ' \
'["Pods-BananaLib", "Pods-OrangeFramework"]. Singular build setting '\
'STRIP_STYLE has different values.'
end
end
end
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment