Commit d56aac94 authored by Fabio Pelosin's avatar Fabio Pelosin

[UserProjectIntegrator] Warn about xcconfig override after every installation

parent c68ce09a
......@@ -62,6 +62,7 @@ module Pod
create_workspace
integrate_user_targets
warn_about_empty_podfile
warn_about_xcconfig_overrides
end
#-----------------------------------------------------------------------#
......@@ -133,6 +134,28 @@ module Pod
end
end
# Checks whether the settings of the CocoaPods generated xcconfig are
# overridden by the build configuration of a target and prints a
# warning to inform the user if needed.
#
def warn_about_xcconfig_overrides
targets.each do |aggregate_target|
aggregate_target.user_targets.each do |user_target|
user_target.build_configurations.each do |config|
xcconfig = aggregate_target.xcconfigs[config.name]
if xcconfig
xcconfig.attributes.keys.each do |key|
target_value = config.build_settings[key]
if target_value && !target_value.include?('$(inherited)')
print_override_warning(aggregate_target, user_target, config, key)
end
end
end
end
end
end
end
private
# @!group Private Helpers
......@@ -169,11 +192,37 @@ module Pod
end.compact.uniq
end
def targets_to_integrate
targets.reject { |target| target.target_definition.empty? }
end
# Prints a warning informing the user that a build configuration of
# the integrated target is overriding the CocoaPods build settings.
#
# @param [Target::AggregateTarget] aggregate_target
# The umbrella target.
#
# @param [XcodeProj::PBXNativeTarget] user_target
# The native target.
#
# @param [Xcodeproj::XCBuildConfiguration] config
# The build configuration.
#
# @param [String] key
# The key of the overridden build setting.
#
def print_override_warning(aggregate_target, user_target, config, key)
actions = [
"Use the `$(inherited)` flag, or",
"Remove the build settings from the target."
]
message = "The `#{user_target.name} [#{config.name}]` " \
"target overrides the `#{key}` build setting defined in " \
"`#{aggregate_target.xcconfig_relative_path(config.name)}'. " \
"This can lead to problems with the CocoaPods installation"
UI.warn(message, actions)
end
#-----------------------------------------------------------------------#
end
......
......@@ -20,7 +20,6 @@ module Pod
target.build_configurations.each do |config|
update_from_cocoapods_0_33_1(pod_bundle, targets)
set_target_xcconfig(pod_bundle, config)
check_overrides(pod_bundle, target, config)
end
end
end
......@@ -72,28 +71,6 @@ module Pod
config.base_configuration_reference = file_ref
end
# Checks whether the settings of the CocoaPods generated xcconfig are
# overridden by the build configuration of a target and prints a
# warning to inform the user if needed.
#
# @param [Target::AggregateTarget] pod_bundle
# The Pods bundle.
#
# @param [XcodeProj::PBXNativeTarget] target
# The native target.
#
# @param [Xcodeproj::XCBuildConfiguration] config
# The build configuration.
#
def self.check_overrides(pod_bundle, target, config)
xcconfig = pod_bundle.xcconfigs[config.name]
xcconfig.attributes.keys.each do |key|
target_value = config.build_settings[key]
if target_value && !target_value.include?('$(inherited)')
print_override_warning(pod_bundle, target, config, key)
end
end
end
private
......
......@@ -50,22 +50,7 @@ module Pod
config.base_configuration_reference.should.equal existing
end
it 'check that the integrated target does not override the CocoaPods build settings' do
UI.warnings = ''
config = @target.build_configuration_list['Release']
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = 'FLAG=1'
XCConfigIntegrator.integrate(@pod_bundle, [@target])
UI.warnings.should.include 'The `SampleProject [Release]` target ' \
'overrides the `GCC_PREPROCESSOR_DEFINITIONS` build setting'
end
it 'allows build settings which inherit the settings form the CocoaPods xcconfig' do
UI.warnings = ''
config = @target.build_configuration_list['Release']
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = '$(inherited)'
XCConfigIntegrator.integrate(@pod_bundle, [@target])
UI.warnings.should.not.include 'GCC_PREPROCESSOR_DEFINITIONS'
end
end
end
......@@ -29,6 +29,9 @@ module Pod
#-----------------------------------------------------------------------#
describe "In general" do
before do
@integrator.stubs(:warn_about_xcconfig_overrides)
end
it "adds the Pods project to the workspace" do
UserProjectIntegrator::TargetIntegrator.any_instance.stubs(:integrate!)
......@@ -52,6 +55,35 @@ module Pod
UI.warnings.should.include?('The Podfile does not contain any dependencies')
end
it 'check that the integrated target does not override the CocoaPods build settings' do
UI.warnings = ''
target_config = stub(:name => 'Release', :build_settings => { 'GCC_PREPROCESSOR_DEFINITIONS' => 'FLAG=1' })
user_target = stub(:name => 'SampleProject', :build_configurations => [target_config])
@library.stubs(:user_targets).returns([user_target])
@library.xcconfigs['Release'] = stub(:attributes => {'GCC_PREPROCESSOR_DEFINITIONS' => 'COCOAPODS=1'})
@integrator = UserProjectIntegrator.new(@podfile, config.sandbox, temporary_directory, [@library])
@integrator.unstub(:warn_about_xcconfig_overrides)
@integrator.send(:warn_about_xcconfig_overrides)
UI.warnings.should.include 'The `SampleProject [Release]` target ' \
'overrides the `GCC_PREPROCESSOR_DEFINITIONS` build setting'
end
it 'allows build settings which inherit the settings form the CocoaPods xcconfig' do
UI.warnings = ''
target_config = stub(:name => 'Release', :build_settings => { 'GCC_PREPROCESSOR_DEFINITIONS' => 'FLAG=1 $(inherited)' })
user_target = stub(:name => 'SampleProject', :build_configurations => [target_config])
@library.stubs(:user_targets).returns([user_target])
@library.xcconfigs['Release'] = stub(:attributes => {'GCC_PREPROCESSOR_DEFINITIONS' => 'COCOAPODS=1'})
@integrator = UserProjectIntegrator.new(@podfile, config.sandbox, temporary_directory, [@library])
@integrator.unstub(:warn_about_xcconfig_overrides)
@integrator.send(:warn_about_xcconfig_overrides)
UI.warnings.should.not.include 'GCC_PREPROCESSOR_DEFINITIONS'
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