9

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

私が持っている質問は: デバッグ構成が新しいマクロ定義で更新されないのはなぜですか? リリース構成は正しく設定されているが、デバッグは設定されていないことが出力でわかります。

何か案は?

4

2 に答える 2

5

マクロを追加する方法で、特定の問題に対する答えが見つかりました。次のように、config.build_settings ...行を 2 行に分割する必要がありました。

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

補足として、間違ったターゲットに定義を設定していました。これらの問題の両方が解決されたので、私は正式に立ち往生しています! わーい!

于 2014-11-25T22:35:52.307 に答える