CocoaPods / CocoaPods

The Cocoa Dependency Manager.
https://cocoapods.org/
Other
14.56k stars 2.63k forks source link

post_install hooks only get called once per pod (not per target) #985

Closed berg closed 11 years ago

berg commented 11 years ago

This originally started as a pod spec update to work around the problem, but @alloy asked me to open a bug here. Instead, for reference: https://github.com/CocoaPods/Specs/pull/1815

In CocoaPods 0.18.1, when defining multiple nonexclusive targets, like this:

platform :ios, '5.1'
link_with ['ProdTarget', 'BetaTarget']
pod 'HockeySDK', '~>3.0.0'
pod 'AFNetworking', '~>1.2.0'
pod 'CocoaLumberjack', '~>1.6'
# ... and some other dependendencies

target 'DevTarget' do
    link_with 'DevTarget'
    pod 'NSLogger', '~>1.1'
    pod 'NSLogger-CocoaLumberjack-connector', '~>1.3'
    pod 'CBIntrospect', '~>0.3.3'
    pod 'PonyDebugger', '~>0.2.1beta1'
end

post_install do |installer_representation|
    installer_representation.project.targets.each do |target|
        if target.name == 'Pods-DevTarget'
            target.build_configurations.each do |config|
                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << '_AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_=1'
            end
        end
    end
end

The post_install hook for each pod only gets called once per build, not per target, and the LibraryRepresentation passed into the hook only has a reference to a single target (which seems to be chosen nondeterministically.)

For pods like HockeySDK and QuickDialog which do things like modify the resource script and prefix header from the post install hook, this breaks badly.

berg commented 11 years ago

Here's the issue. It's trivial, but I'm not submitting a pull request because I assume you'd probably like to have tests written for this, and that's probably outside the scope of my Ruby skillz.

https://github.com/CocoaPods/CocoaPods/blob/master/lib/cocoapods/installer.rb#L451

||= short-circuits if executed is true. What I assume you wanted is |=, which just does a logical OR on the values, for the purpose of determining whether to print or skip the UI.message call below. The bug exists in the pre_install hooks as well.

alloy commented 11 years ago

@irrationalfab Can you look into this one?

fabiopelosin commented 11 years ago

@berg Thanks for the precise report :+1:

berg commented 11 years ago

@irrationalfab sorry that I didn't take it all the way and write test cases!

BTW, thanks to both of you for CocoaPods. It's done amazingly great stuff for the ecosystem, IMO, and it's saved me a ton of time. I'm trying to contribute where I can! :heart:

fabiopelosin commented 11 years ago

Np, the tests in that part are not very clean at the moment. Thanks for actually finding the solution though!

alloy commented 11 years ago

:heart:

@irrationalfab I think you can tell Mocha to expect different arguments for the same method call expectation. (I.e. expect it to pass the right library representation objects.)

fabiopelosin commented 11 years ago

:+1: