I've been going round and round for a couple days now trying to figure out why my post_install hook isn't producing the output I'm expecting. Here's my Podfile:
source 'https://github.com/CocoaPods/Specs.git'
target "SCCommon" do
platform :ios, "6.0"
pod 'AFNetworking', '~> 1.2.1'
pod 'Mantle', '~> 1.3'
pod 'PubNub', '3.5.5'
end
target "SCCommon-TestHarness" do
platform :ios, "6.0"
# inhibit_all_warnings!
pod 'SCCommon', :path => '../SCCommon.podspec'
end
target "SCCommon-UnitTests" do
platform :ios, "6.0"
# inhibit_all_warnings!
pod 'OCMock', '2.2.3'
pod 'SCCommon', :path => '../SCCommon.podspec'
end
post_install do |installer_representation|
installer_representation.project.targets.each do |target|
if target.name == 'Pods-SCCommon-UnitTests'
puts "Setting preprocessor macro for #{target.name}..."
target.build_configurations.each do |config|
puts "#{config} configuration..."
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)','SC_DEBUG_SCCOMMON=1','FOOBAR']
puts config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']
puts '---'
end
end
end
end
After running pod update
on the above, I get the following output:
Update all pods
Analyzing dependencies
CocoaPods 0.35.0 is available.
To update use: `sudo gem install cocoapods`
For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.
Fetching podspec for `SCCommon` from `../SCCommon.podspec`
Downloading dependencies
Using AFNetworking (1.2.1)
Using Mantle (1.5.1)
Using OCMock (2.2.3)
Using PubNub (3.5.5)
Using SCCommon (0.3)
Generating Pods project
Setting preprocessor macro for Pods-SCCommon-UnitTests...
Release configuration...
$(inherited)
SC_DEBUG_SCCOMMON=1
FOOBAR
---
Debug configuration...
DEBUG=1
$(inherited)
---
Integrating client project
The question I have is: Why isn't the Debug configuration updating with the new macro definitions? You can see in the output that the Release configuration is setup correctly, but not Debug.
Any ideas?
When you run pod update PODNAME , CocoaPods will try to find an updated version of the pod PODNAME , without taking into account the version listed in Podfile. lock . It will update the pod to the latest version possible (as long as it matches the version restrictions in your Podfile ).
~> (the optimistic operator) is used when you want to specify a version 'up to next major | minor | patch'. For example: ~> 0.1.2 will get you a version up to 0.2 (but not including 0.2 and higher)
After you have initially installed CocoaPods into your project, you can add new dependencies (or remove unused ones) by editing the Podfile. Then simply run pod install again.
Found the answer to my specific issue in the way I was adding macros. I had to break the config.build_settings ...
line into two lines like so:
post_install do |installer_representation|
installer_representation.project.targets.each do |target|
if target.name == 'Pods-SCCommon-UnitTests-SCCommon'
puts "Setting preprocessor macro for #{target.name}..."
target.build_configurations.each do |config|
puts "#{config} configuration..."
puts "before: #{config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].inspect}"
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'SC_DEBUG_SCCOMMON'
puts "after: #{config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].inspect}"
puts '---'
end
end
end
end
As a side note, I was also setting the definition on the wrong target. Now that both of those issues are resolved, I am officially unstuck! Yay!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With