CocoaPods / CocoaPods

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

Unable to register `pre_integrate` and `post_integrate` hooks from plugins #11277

Open soumyamahunt opened 2 years ago

soumyamahunt commented 2 years ago

Report

What did you do?

I tried to create CocoaPods plugin with pre_integrate and post_integrate hooks.

What did you expect to happen?

I expected these hooks to be run just like it runs for pre_integrate and post_integrate hooks in Podfile.

What happened instead?

None of the hooks was executed.

CocoaPods Environment

Stack

   CocoaPods : 1.11.3
        Ruby : ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin21]
    RubyGems : 3.0.3.1
        Host : macOS 12.3 (21E230)
       Xcode : 13.3 (13E113)
         Git : git version 2.32.0 (Apple Git-132)
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib
Repositories : cocoapods - git - https://github.com/CocoaPods/Specs.git @ 12ede23c2ffaf6899c92c0063954ff040625ade5

               trunk - CDN - https://cdn.cocoapods.org/

Installation Source

Executable Path: /usr/local/bin/pod

Plugins

cocoapods-archive                  : 0.0.2
cocoapods-deintegrate              : 1.0.5
cocoapods-packager                 : 1.5.0
cocoapods-plugins                  : 1.0.0
cocoapods-rome                     : 1.0.1
cocoapods-search                   : 1.0.1
cocoapods-stats                    : 1.1.0
cocoapods-trunk                    : 1.6.0
cocoapods-try                      : 1.2.0
cocoapods-user-defined-build-types : 0.0.7

Podfile

# Uncomment the next line to define a global platform for your project
platform :ios, '14.0'
plugin 'cocoapods-embed-flutter'

target 'ios_app' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for ios_app
  pub 'flutter_module', :path => '../'
end

pre_integrate do |installer|
  puts "podfile pre integrate"
end

Additional observations

I noticed the following functions are defined to call pre_integrate and post_integrate hooks for plugins respectively. But I couldn't find these functions called from any where. Are these hooks intentionally disabled for plugins? I couldn't find any info in docs regarding this. https://github.com/CocoaPods/CocoaPods/blob/3eb1bd365b97af2677e80531f77310c4bb69d9bd/lib/cocoapods/installer.rb#L703 https://github.com/CocoaPods/CocoaPods/blob/3eb1bd365b97af2677e80531f77310c4bb69d9bd/lib/cocoapods/installer.rb#L726

orta commented 2 years ago

Interesting, they are documented as being available in the podfile: https://guides.cocoapods.org/syntax/podfile.html#pre_integrate - looks like a bug, open to PRs

soumyamahunt commented 2 years ago

Interesting, they are documented as being available in the podfile: https://guides.cocoapods.org/syntax/podfile.html#pre_integrate - looks like a bug, open to PRs

@orta I will be happy to help out, but I need some guidance:

  1. Should I add plugin pre_integrate after this line? https://github.com/CocoaPods/CocoaPods/blob/3eb1bd365b97af2677e80531f77310c4bb69d9bd/lib/cocoapods/installer.rb#L182
  2. and plugin post_integrate after this line? https://github.com/CocoaPods/CocoaPods/blob/3eb1bd365b97af2677e80531f77310c4bb69d9bd/lib/cocoapods/installer.rb#L930
orta commented 2 years ago

Oh, you want plugins to have extra hooks - sorry, I read this the other way. I guess I still don't see a problem with adding this, I feel like there might be other hooks which handle the same point ( for example cocoapods-keys happens pre-integrate I thought) but your implementation kinda sounds alright.

I'd recommend first writing some tests and then just giving it a stab

soumyamahunt commented 2 years ago

Oh, you want plugins to have extra hooks - sorry, I read this the other way. I guess I still don't see a problem with adding this, I feel like there might be other hooks which handle the same point ( for example cocoapods-keys happens pre-integrate I thought) but your implementation kinda sounds alright.

I'd recommend first writing some tests and then just giving it a stab

@orta is there any reason for these hooks not being available for plugins? I wasn't even aware that these hooks aren't available for plugins, since I couldn't find anything on docs regarding this and I can see the unit test cases for all the plugin hooks including pre_integrate and post_integrate:

https://github.com/CocoaPods/CocoaPods/blob/7577294cd5e6594bd7d6e84f2048fd792a7c520d/spec/unit/installer_spec.rb#L1033 https://github.com/CocoaPods/CocoaPods/blob/7577294cd5e6594bd7d6e84f2048fd792a7c520d/spec/unit/installer_spec.rb#L1040 https://github.com/CocoaPods/CocoaPods/blob/7577294cd5e6594bd7d6e84f2048fd792a7c520d/spec/unit/installer_spec.rb#L1048 https://github.com/CocoaPods/CocoaPods/blob/7577294cd5e6594bd7d6e84f2048fd792a7c520d/spec/unit/installer_spec.rb#L1056

Also, can you point me how you are using pre_integrate hooks in cocoapods-keys I only found pre_install and post_install hooks.

dnkoutso commented 2 years ago

I think those were missed and not invoked for plugins.

soumyamahunt commented 2 years ago

I think those were missed and not invoked for plugins.

@dnkoutso thanks for clarifying, is there any existing work on resolving this or should I create a PR?