In iOS development, we often use CocoaPods to manage three-party dependencies. If you want to view the running process of CocoaPods, you can use the ruby debugging environment to debug CocoaPods source code.
1. Build a ruby debugging environment
You can refer to this article to build a ruby debugging environment. The CocoaPods debugging environment only needs to be modified on this basis.
VSCode builds a ruby development and debugging environment
Two cocoaPods source code
Download the CocoadPods source code and clone the source code locally
https://github.com/CocoaPods/CocoaPods
Prepare the iOS project named iOSProject, create a new directory, put the CocoaPods source code and iOS project in this directory, and create a new Gemfile file in this directory.
Introduce Ruby library in Gemfile
source 'https://gems.ruby-china.com/'
gem 'ruby-debug-ide'
gem 'debase', '0.2.5.beta2'
gem 'cocoapods', path: './CocoaPods'
gem 'cocoapods', path: './CocoaPods' This line is to import CocoaPods in source code
Three configuration VSCode debugging
In VSCode, click the Debug menu on the left, and then click create a launch.json file.
Select Ruby in the pop-up selection box Select debugger, and then select Debug Local File.
Write content in launch.json.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug Local File",
"type": "Ruby",
"request": "launch",
"program": "${workspaceRoot}/CocoaPods/bin/pod",
"cwd": "${workspaceRoot}/iOSProject",
"args": ["install"]
}
]
}
The program field is the directory of the pod executable file, cwd is the current working directory, where iOSProject is the project name, replace it according to actual needs, and args is the command parameter.
Click the debug button to run the program, if an error occurs
WARNING: CocoaPods requires your terminal to be using UTF-8 encoding.
Consider adding the following to ~/.profile:
export LANG=en_US.UTF-8
You need to add export LANG=en_US.UTF-8 to the configuration file of the terminal, restart the terminal, restart VSCode, and run the program again with debug. Open the install.rb file, add a breakpoint in the run method, and the breakpoint can be broken normally.