2014-11-25 23 views
7

Ho girato per un paio di giorni cercando di capire perché il mio hook post_install non sta producendo l'output che mi aspetto. Ecco il mio Podfile:Perché l'hook post_install di cocoapods non sta aggiornando i miei macro del preprocessore?

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 

Dopo aver eseguito pod update a quanto sopra, ottengo il seguente 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 

La domanda che ho è: perché non è l'aggiornamento configurazione di debug con le nuove definizioni di macro ? È possibile vedere nell'output che la configurazione di Release è impostata correttamente, ma non Debug.

Qualche idea?

risposta

4

trovato la risposta al mio problema specifico nel modo stavo aggiungendo macro. Ho dovuto rompere la linea config.build_settings ... in due righe in questo modo:

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 

Come nota a margine, mi è stato anche l'impostazione della definizione sul bersaglio sbagliato. Ora che entrambi questi problemi sono stati risolti, sono ufficialmente scollato! Sìì!

+1

Non è necessaria la seconda riga config.build_settings ['GCC_PREPROCESSOR_DEFINITIONS'] << 'SC_DEBUG_SCCOMMON' Questo aggiungerebbe il testo senza valore, almeno è ciò che ho ottenuto ora durante il test. Per coloro che hanno lo stesso problema, controllare prima se il nome del target è corretto. – David