为什么我的cocoapods post_install挂钩不更新我的预处理器宏?

时间:2014-11-25 18:25:33

标签: ruby macros preprocessor cocoapods xcode-project

我一直在四处走动,现在试图找出为什么我的post_install挂钩没有产生我期待的输出。这是我的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

在上面运行pod update之后,我得到以下输出:

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

我的问题是:为什么不使用新的宏定义更新Debug配置?您可以在输出中看到正确设置了Release配置,但没有调试。

有什么想法吗?

2 个答案:

答案 0 :(得分:4)

以我添加宏的方式找到了我的具体问题的答案。我不得不将config.build_settings ...行分成两行,如下所示:

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

作为旁注,我还在错误的目标上设置定义。既然这两个问题都解决了,我正式解散了!耶!

答案 1 :(得分:0)

我使用了代码,它奏效了。

config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)','MEMORY_LEAKS_FINDER_ENABLED=1','EVERY']

输出:

find MLeaksFinder Release
$(inherited)
MEMORY_LEAKS_FINDER_ENABLED=1
EVERY
find MLeaksFinder Debug
$(inherited)
MEMORY_LEAKS_FINDER_ENABLED=1
EVERY