Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't my cocoapods post_install hook updating my preprocessor macros?

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?

like image 361
Lee Fastenau Avatar asked Nov 25 '14 18:11

Lee Fastenau


People also ask

What command updates a single library in CocoaPods?

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 ).

What does ~> mean in CocoaPods?

~> (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)

How do I add dependencies to CocoaPods?

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.


1 Answers

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!

like image 55
Lee Fastenau Avatar answered Oct 03 '22 02:10

Lee Fastenau