Skip to content

X140Yu/debug_cocoapods_plugins_in_vscode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Debug CocoaPods & Plugins in VSCode

中文版本点这里

使用 VSCode debug CocoaPods 和插件源码

Debug cocoapods

Debug plugin

Pre-requirements

Install Debug Gems

gem install ruby-debug-ide
gem install debase

Install VSCode Ruby Plugin

Ruby

Debug With bundler

  • Create a Gemfile in 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.json in 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

Debug without bundler

Don't waste your time! Use bundler now!

Debug 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.json in 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

Debug CocoaPods & plugin

  • Create a new folder, all actions below are under this folder
  • Clone & checkout CocoaPods source code
  • Clone or create a CocoaPods plugin
  • Copy .vscode to this folder
  • Make some changes in .vscode/launch.json
    • cwd: where the pod command execute (the folder should contain a Podfile)
    • pluginPath: path to the plugin
    • args: pod command arguments
  • Change cocoapods/bin/pod:L27
    • From require 'bundler/setup to require_relative '../../.vscode/plugin_patch', just like this
  • Add some breakpoint within VSCode
  • Press F5 or hit menu Debug - Start Debugging

Example of debugging CocoaPods & plugin

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
  • 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.