For a Ruby debug environment setup and basic Ruby syntax, see this compilation of Ruby and Cocoapods articles.
Cocoapods debugging environment construction
Download the source code
We downloaded Cocoapods source code locally on GitHub.
Create the Xcode project
Create a new Xcode project locally. Go to the root directory of your project and create a Podfile.
Platform: ios, '10.0' use_frameworks! target 'TestLibrary' do pod 'AFNetworking' endCopy the code
Create Gemfile
Put the Cocoapods source code and Xcode project in the same directory and create a Gemfile file in this directory. The directory structure of the file is as follows
├── Heavy Exercises ── Heavy Exercises ── Heavy Exercises ── Heavy Exercises ── Heavy Exercises ── Heavy Exercises ── TestLibrary. Xcodeproj └ ─ ─ the buildCopy the code
Introduce the Ruby debugging library in Gemfile.
source 'https://rubygems.org'
gem 'cocoapods', path: './CocoaPods' // 1
gem 'ruby-debug-ide' // 2
gem 'debase' // 3
Copy the code
- 1, specify
CocoaPods
The path. - 2,3: dependency libraries for Ruby debugging
Create a launch. Json
Use VSCode to open the directory folder, in the root directory, create a.vscode folder, in the.vscode folder, create a launch.json file, the directory structure is as follows.
In launch.json, configure the application launch parameters:
{
"configurations": [
{
"name": "Debug CocoaPods Plugin",
"showDebuggerOutput": true,
"type": "Ruby",
"request": "launch",
"useBundler": true,
"cwd": "${workspaceRoot}/TestLibrary", // 1
"program": "${workspaceRoot}/CocoaPods/bin/pod", // 2
"args": ["install", "--verbose"], // 3
}]
}
Copy the code
- 1, the pod command execution path. Will look under that path
Podfile
File. - 2, specify the use
pod
Explain the document. - 3, the command parameter executed, in this case is
pod install --verbose
bundle install
After creating the project dependencies, execute the bundle install on the terminal. Then, set a breakpoint in your Podfile and run the program F5:
That way, we can debugCocoapods
The source code.
Pod Install
When we look at the function call stack during Pod Install, we can see:
It’s going to executePod::Command.run(ARGV)
Parameters as follows:["install","--verbose"]
.Command
inheritanceCLAide::Command
.CLAide
Is a command interpreter aboutCLAid
Interested can refer to the big melon groundCocoaPods command resolve-claide.
Step through the program. After parsing the CLAide, the code executes to the run method in the install.rb file
First check if the Podfile file exists, if not, raise No ‘Podfile’ found in the project directory. The exception.
If the file extension is “”.podfile.rb, wrap the file as a PodFile object.
We are inPodfile
In the file, totarget
Method, which passes two arguments:targetName
andblock
In thepod install
, the callblock
Methods.
Q&A
[!] No `Podfile’ found in the project directory.
We reported this error with a warning when we created the Podfile during source debugging
WARNING: CocoaPods requires your terminal to be using UTF-8 encoding.
Consider adding the following to ~/.profile:
export LANG=en_US.UTF-8
Copy the code
To solve this problem, add export LANG= en_us.utF-8 to the.bash_profile or.zshrc file.
The sample project
This article debugging project, I have uploaded to Github Cocoapods debugging, there is a need to download themselves.