美文网首页
静态分析工具 - Oclint

静态分析工具 - Oclint

作者: 3479da3be4fa | 来源:发表于2018-06-06 12:52 被阅读8次

CLint 是一个强大的静态代码分析工具, 可以用来提高代码质量, 查找潜在的 bug, 主要针对c,c++和 Objective-c 的静态分析。 功能非常强大。

1、 oclint 与 xcpretty 的安装

推荐是用 Homebrew 来安装, 快速且节省精力, 也可以选择源码安装或者 release 包来安装,不过需要配置环境变量的内容。 使用Homebrew 安装时, 需要先设置 brew 的第三方仓库,然后安装,

xcpretty 用于解析 xcodebuild 构建日志, 解析后的结果交给 oclint 来使用。

oclint 的安装还是比较简单方便的, 推荐安装方法:

oclint 的安装:

xcpretty 的安装:

简单轻松的三条命令环境部署完成。

2、 构建与静态代码扫描

1) 构建与解析日志

xcodebuild 命令构建部署

xcodebuild 默认构建的格式 Release , 如果特殊需求, 需要在 xcode 工程内去修改相关工程配置, 构建Debug 或者 Ad 包自行添加相关参数。 build 之后, 使用 xcpretty 来解析编译日志即可。

brew tap oclint/formulae

brew install oclint

sudo gem install xcpretty

的输出格式为 json 格式。

输出的数据为

build/reports/compilation_db.json。

CODE_SIGN_IDENTITY="xxx"

DEVELOPER_DIR="/Applications/Xcode7.app"xcodebuild

CODE_SIGN_IDENTITY=${CODE_SIGN_IDENTITY} clean

DEVELOPER_DIR="/Applications/Xcode7.app"xcodebuild

2) 解析结果使用 oclint 做扫描

使用oclint 时需要将 build/reports/compilation_db.json 重新命名为 compile_commands.json

并移动至当前目录。

将结果输出格式为

pmd 格式, 然后通过 jenkins 的 pmd 插件就可以做结果的展示了。

3) oclint 其它参数

-e Pods

-- -rc=LOG_LINE =100

LINT_DISABLE_RULES = "

-disable-rule= LongClass

-disable-rule= LongLine

-disable-rule= LongMethod

-disable-rule= LongVariableName

-disable-rule= ShortVariableName

-disable-rule= HighNcssMethod

-disable-rule= DeepNestedBlock

-disable-rule= TooManyFields

-disable-rule= TooManyMethods

-disable-rule= TooManyParameters

-disable-rule= IVarAssignmentOutsideAccessorsOrInit

命令行最后加入 $LINT_DISBALE_RULES 可以禁用某些不需要的规则

3、 中间出现的问题

1) oclint: error: violations exceed threshold

超过了阈值, 所以调大了-max-priority-1=9999 -max-priority-2=9999 -max-priority-3=9999

2)

出现了 code sign 错误

xcodebuild 后面加上参数 CODE_SIGN_IDENTITY 就行了

CODE_SIGN_IDENTITY=${CODE_SIGN_IDENTITY} | xcpretty -r json-compilation-database

cp build/reports/compilation_db.json compile_commands.json

oclint-json-compilation-database -e Pods -- -o=lint.xml -report-type=pmd -stats

-max-priority-1=9999 -max-priority-2=9999 -max-priority-3=9999

-rc LONG_LINE=500 -rc LONG_VARIABLE_NAME=100

微信+17031115530,拉测试微信群交流

相关文章

网友评论

      本文标题:静态分析工具 - Oclint

      本文链接:https://www.haomeiwen.com/subject/yjdbsftx.html