大型app一般都施行业务分离,使用几个子工程构建各个业务线,但是这些子工程,都不会标注使用了那些Pod库,也没有PodFile,使用的Pod库都放在总的工程workspace里,所以如果想提取子工程里使用了哪些Pod库,是比较费劲的。
于是利用ruby脚本,遍历所有的.m,.h,.pch文件,找到所有的import引用,再解析出来是系统头文件的引用,还是Pod库的引用,最后打印所有去重结果即可
require 'fileutils'
require 'pathname'
require 'Find'
Encoding.default_external = Encoding.find('utf-8');
$realpath = Pathname.new(File.dirname(__FILE__)).realpath
$podArr = []
$sysFWArr = []
$nonFWList = [
"Foundation",
"UIKit",
"objc",
"sys",
]
$systemFWList = [
"CoreLocation",
"CoreMedia",
"CoreGraphics",
"CoreBluetooth",
"CoreMotion",
"PassKit",
"QuartzCore",
"WebKit",
"MessageUI",
"AddressBook",
"AddressBookUI",
"SafariServices",
"AudioToolbox",
"AssetsLibrary",
"Accelerate",
"AdSupport",
"AVFoundation",
"UserNotifications"
]
class PodTool
def isNonImport(name)
$nonFWList.each do |item|
if item == name
return true
end
end
if name.include? "Business"
return true
end
if name.include? "Platform"
return true
end
return false
end
def isSystemImport(name)
$systemFWList.each do |item|
if item == name
return true
end
end
return false
end
def putArr(arr,podName)
arr.each do |item|
if item == podName
return
end
end
arr.push(podName)
end
def findPods(line)
if ( line =~ /#import <(.*)\/.*>/ )
name = $1
if isNonImport(name)
return
end
if isSystemImport(name)
putArr($sysFWArr,name)
else
putArr($podArr,name)
end
end
end
def readFiles(path)
Find.find(path) do |filename|
if filename.include?(".h") or filename.include?(".m") or filename.include?(".pch")
File.open(filename, "r") do |file|
file.each_line do|line|
# puts line
if line.include? "#import <"
findPods(line)
elsif (line.include? "@interface") or (line.include? "@implementation")
break
end
end
end
# break
end
end
end
end
PodTool.new.readFiles("#{$realpath}/FolderToFind")
puts "////////system framework////////////"
puts $sysFWArr
puts "////////3rd party pods////////////"
puts $podArr