使用 VSCode debug CocoaPods 和插件源码
gem install ruby-debug-ide
gem install debase- Create a
Gemfilein project root and add the following content to it
gem 'cocoapods', path: 'path/to/cocoapods/'
gem 'cocoapods-binary', path: 'path/to/cocoapods-binary/'
gem 'ruby-debug-ide'
gem 'debase'- run
bundle install - Create
.vscode/launch.jsonin project root
{
"configurations": [{
"name": "Debug CocoaPods Plugin with Bundler",
"showDebuggerOutput": true,
"type": "Ruby",
"request": "launch",
"useBundler": true,
"cwd": "${workspaceRoot}/Testing",
"program": "${workspaceRoot}/cocoapods/bin/pod",
"args": ["install"]
}
}- Add some breakpoint within VSCode
- Press F5 or hit menu
Debug - Start Debugging
Don't waste your time! Use bundler now!
- Clone CocoaPods
git clone https://github.com/CocoaPods/CocoaPods.git- Checkout cloned repo to match the version you have installed on your laptop
git checkout `pod --version`- Create
.vscode/launch.jsonin CocoaPods' root folder
{
"configurations": [{
"name": "Debug CocoaPods Plugin",
"showDebuggerOutput": true,
"type": "Ruby",
"request": "launch",
"cwd": "path/to/podfile/dir", // where the `pod` command execute (the folder should contain a `Podfile`)
"program": "${workspaceRoot}/bin/pod",
"args": ["install"] // `pod` command arguments
}]
}- Comment
bin/pod:L27 (# require 'bundler/setup') - Add some breakpoint within VSCode
- Press F5 or hit menu
Debug - Start Debugging
- Create a new folder, all actions below are under this folder
- Clone & checkout CocoaPods source code
- Clone or create a CocoaPods plugin
- Copy
.vscodeto this folder - Make some changes in
.vscode/launch.jsoncwd: where thepodcommand execute (the folder should contain aPodfile)pluginPath: path to the pluginargs:podcommand arguments
- Change
cocoapods/bin/pod:L27- From
require 'bundler/setuptorequire_relative '../../.vscode/plugin_patch', just like this
- From
- Add some breakpoint within VSCode
- Press F5 or hit menu
Debug - Start Debugging
The CocoaPods version in this repository is
1.8.0.beta.1, incase some version incompatible issue with CocoaPods-Core or other gems, you should install this version's CocoaPods in your Mac too
- Clone this repository
- Open it with VSCode
- Add a breakpoint somewhere you like to explore
- eg.
cocoapods/lib/cocoapods/command/install.rb:L46 - eg.
cocoapods-binary/lib/cocoapods-binary/Main.rb:L101
- eg.
- Press F5 or hit menu
Debug - Start Debugging - All set 🌸
If you have any question, don't hesitate to fire a issue 😉
Appreciate a 🌟 if you like it.

