Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Post-Install of Cocoapod get main project directly

Tags:

ruby

cocoapods

In creating a CocoaPod Podspec for a vendored_framework I need to install a shell script to be run after all other build_phases in the main project. The only way I have found to do this is by groping the directory for the .xcodeproj file from the Podfile.

post_install do |installer|
  project_name = Dir.glob("*.xcodeproj").first
  project = Xcodeproj::Project.open(project_name)
  project.targets.each do |target|
    inject_shell_script_build_phase(target)
  end
  project.save
end

This seems ridiculous given that pod install or pod update is running and clearly has this information already. Is there a way to get the project reference directly without having to glob or hardcode the project filename?

like image 376
Cameron Lowell Palmer Avatar asked Sep 19 '25 13:09

Cameron Lowell Palmer


1 Answers

This should do the trick... Notice the post_integrate hook. Otherwise my changes got overridden (ignored?) unless I did it via the direct file open.

post_integrate do |installer|
  project =  installer.aggregate_targets[0].user_project
  project.targets.each do |target|
    inject_shell_script_build_phase(target)
  end
  project.save
end
like image 65
Hari Honor Avatar answered Sep 22 '25 11:09

Hari Honor