使用 Python 开发检查脚本,原理如下:
【注意】
- # 所有项目中引入的头文件
- allImportedFiles = {os.path.splitext(os.path.basename(fileName))[0] for fileName in getImportedFiles(scanCodePaths, *scanExtension)}
- # 所有依赖的 Pod
- allPodNames = [podName for podName in getDependenciedPodNames(podspecPaths)]
- unusedPods = set()
- unusedPodFileCount = 0
- totalPodFileCount = 0
- unfindPods = set()
- for podName in allPodNames:
- for scanPodPath in scanPodPaths:
- podPath = os.path.join(scanPodPath, podName)
- # pod 的各个文件
- filesInPod = {os.path.splitext(os.path.basename(fileName))[0] for fileName in getFileNames(podPath, *scanExtension)}
- totalPodFileCount += len(filesInPod)
- if not filesInPod:
- unfindPods.add(podName)
- elif not allImportedFiles & filesInPod:
- # 两者无交集,则 pod 是无用依赖
- unusedPods.add(podName)
- unusedPodFileCount += len(filesInPod)
- unusedPods -= whiteList # 白名单
- if unusedPods:
- print '//======================= 无用依赖 ========================//'
- print '总依赖 pod ' + str(len(allPodNames)) + '个'
- print '无用依赖 pod ' + str(len(unusedPods)) + '个:'
- for pod in unusedPods:
- print pod
- print '未找到 pod 文件 ' + str(len(unfindPods)) + '个:'
- for pod in unfindPods:
- print pod
- print '总 pod 依赖文件数:' + str(totalPodFileCount)
- print '总无用 pod 依赖文件数:' + str(unusedPodFileCount)
- else:
- print "恭喜~~ 没有无用pod依赖!"
2、结果
命令行输入:
- python scanUnusedPod.py --codes /Users/liqiyu/Work/code/DeliciousFood/Classes --pods /Users/liqiyu/Work/code/iphone-nova/Nova/Pods --podspec /Users/liqiyu/Work/code/DeliciousFood/DeliciousFood.podspec
输出:
脚本检测出工程共有 59 个 Pod 依赖,其中 4 个(NVwebView、Tuan、YapDatabase、NVSound)为无用依赖,1 个(NVServices)为未找到 pod 文件。
查看 NVServices pod 后发现,该 pod 已被废弃,里面只有一个空的 README.md 文件。
3、完整代码
求 Star~~
求 Star~~
求 Star~~
Github 地址:https://github.com/Jlaix/scanUnusedPod
来源: http://blog.csdn.net/a690197843/article/details/70241829