Commit 2ab324a7 authored by Chris Brauchli's avatar Chris Brauchli Committed by Samuel E. Giddins

Add naive check for #included CocoaPods-generated xcconfig

Whenever I run `pod install` I get warnings like:

```
[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `TestClient` to `Pods/Target Support Files/Pods-TestClient/Pods-TestClient.debug.xcconfig` or include the `Pods/Target Support Files/Pods-TestClient/Pods-TestClient.debug.xcconfig` in your build configuration.
```

This is confusing, especially for people not familiar with CocoaPods.

This adds a naive check for the CocoaPods-generated xcconfig being #included into the target's actual xcconfig. It also adds the ability to have a special token (I chose `// @COCOAPODS_SILENCE_WARNINGS@ //`, but am happy to change it) in the target's xcconfig to signal that the warning should be silenced even though CocoaPods's xcconfig does not appear to be included. This is useful for test targets and cases where the naive check is not sufficient.
parent 872407eb
......@@ -33,6 +33,11 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
linting.
[Marius Rackwitz](https://github.com/mrackwitz)
* Naïvely prevent base xcconfig warnings for targets that have custom
config files set.
[Chris Brauchli](https://github.com/cbrauchli)
[#2633](https://github.com/CocoaPods/CocoaPods/issues/2633)
##### Bug Fixes
* Do not pass code-sign arguments to xcodebuild when linting OS X targets.
......
......@@ -91,12 +91,14 @@ module Pod
file_ref = group.files.find { |f| f.path == path }
if config.base_configuration_reference &&
config.base_configuration_reference != file_ref
UI.warn 'CocoaPods did not set the base configuration of your ' \
'project because your project already has a custom ' \
'config set. In order for CocoaPods integration to work at ' \
'all, please either set the base configurations of the target ' \
"`#{target.name}` to `#{path}` or include the `#{path}` in your " \
'build configuration.'
unless xcconfig_includes_target_xcconfig?(config.base_configuration_reference, path)
UI.warn 'CocoaPods did not set the base configuration of your ' \
'project because your project already has a custom ' \
'config set. In order for CocoaPods integration to work at ' \
'all, please either set the base configurations of the target ' \
"`#{target.name}` to `#{path}` or include the `#{path}` in your " \
'build configuration.'
end
elsif config.base_configuration_reference.nil? || file_ref.nil?
file_ref ||= group.new_file(path)
config.base_configuration_reference = file_ref
......@@ -136,6 +138,35 @@ module Pod
'This can lead to problems with the CocoaPods installation'
UI.warn(message, actions)
end
# Naively checks to see if a given PBXFileReference imports a given
# path.
#
# @param [PBXFileReference] base_config_ref
# A file reference to an `.xcconfig` file.
#
# @param [String] target_config_path
# The path to check for.
#
SILENCE_WARNINGS_STRING = '// @COCOAPODS_SILENCE_WARNINGS@ //'
def self.xcconfig_includes_target_xcconfig?(base_config_ref, target_config_path)
return unless base_config_ref && File.exist?(base_config_ref.real_path)
regex = /
^(
(\s* # Possible, but unlikely, space before include statement
\#include\s+ # Include statement
['"] # Open quote
(.*\/)? # Possible prefix to path
#{Regexp.quote(target_config_path)} # The path should end in the target_config_path
['"] # Close quote
)
|
(#{Regexp.quote(SILENCE_WARNINGS_STRING)}) # Token to treat xcconfig as good and silence pod install warnings
)
/x
File.foreach(base_config_ref.real_path) { |line| return true if line =~ regex }
false
end
end
end
end
......
......@@ -47,7 +47,7 @@ module Pod
config.base_configuration_reference.should.equal existing
end
it 'does not set the Pods xcconfig as the base config if the user ' \
it 'logs a warning and does not set the Pods xcconfig as the base config if the user ' \
'has already set a config of their own' do
sample_config = @project.new_file('SampleConfig.xcconfig')
@target.build_configurations.each do |config|
......@@ -70,5 +70,40 @@ module Pod
UI.warnings.should.not.match /not set.*base configuration/
end
it 'does not log a warning if the user has set a xcconfig of their own that includes the Pods config' do
sample_config = @project.new_file('SampleConfig.xcconfig')
File.open(sample_config.real_path, 'w') do |file|
@target.build_configurations.each do |config|
file.write("\#include \"#{@pod_bundle.xcconfig_relative_path(config.name)}\"\n")
end
end
@target.build_configurations.each do |config|
config.base_configuration_reference = sample_config
end
XCConfigIntegrator.integrate(@pod_bundle, [@target])
@target.build_configurations.each do |config|
config.base_configuration_reference.should == sample_config
end
UI.warnings.should.not.match /not set.*base configuration/
end
it 'does not log a warning if the user has set a xcconfig of their own that includes the silence warnings string' do
SILENCE_TOKEN = '// @COCOAPODS_SILENCE_WARNINGS@ //'
sample_config = @project.new_file('SampleConfig.xcconfig')
File.open(sample_config.real_path, 'w') do |file|
file.write("#{SILENCE_TOKEN}\n")
end
@target.build_configurations.each do |config|
config.base_configuration_reference = sample_config
end
XCConfigIntegrator.integrate(@pod_bundle, [@target])
@target.build_configurations.each do |config|
config.base_configuration_reference.should == sample_config
end
UI.warnings.should.not.match /not set.*base configuration/
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