为什么我的cocoapods post_install钩子不更新我的预处理器宏? [英] Why isn't my cocoapods post_install hook updating my preprocessor macros?

查看:910
本文介绍了为什么我的cocoapods post_install钩子不更新我的预处理器宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经绕了几天,试图弄清楚为什么我的post_install钩子没有产生我期望的输出.这是我的Podfile:

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

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

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

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

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.

有什么想法吗?

推荐答案

通过添加宏的方式找到了针对特定问题的答案.我必须将config.build_settings ...行分成两行,如下所示:

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!

这篇关于为什么我的cocoapods post_install钩子不更新我的预处理器宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆