1.xcode项目中新增Aggregate,初步建好Aggregate,且脚本也添加好了,具体脚步看下面
1 示例
2.Aggregate已经建成,接下来就是写脚步了,前面文章的具体介绍的整理和使用
3.你可以直接在xcode中新建的script中直接写,也可以单独的创建一个文件,然后单独的管理脚步。那这里就单独介绍创建文件吧,在script中写上如下
chmod -R 777 $SRCROOT/oclint
$SRCROOT/oclint/oclint.sh
具体就是在项目同级目录下创建oclint文件,然后创建一个名字为oclint.sh的文件,并把如下脚步复制上去,最后在xcode中scheme选中你刚刚创建的Aggregate,并按command + b ,看具体的编译情况,具体带有⚠️的注释中需要替换你项目的文件名和忽略文件名
4.通用脚步如下,通用哦!
#!/bin/bash
# 指定编码
export LANG="zh_CN.UTF-8"
export LC_COLLATE="zh_CN.UTF-8"
export LC_CTYPE="zh_CN.UTF-8"
export LC_MESSAGES="zh_CN.UTF-8"
export LC_MONETARY="zh_CN.UTF-8"
export LC_NUMERIC="zh_CN.UTF-8"
export LC_TIME="zh_CN.UTF-8"
export LC_ALL=
function checkDepend () {
command -v xcpretty >/dev/null 2>&1 || {
echo >&2 "I require xcpretty but it's not installed. Install:gem install xcpretty";
exit
}
command -v oclint-json-compilation-database >/dev/null 2>&1 || {
echo >&2 "I require oclint-json-compilation-database but it's not installed. Install:brew install oclint";
exit
}
}
function oclintForProject () {
# 检测依赖
checkDepend
projectName=$1
scheme=$2
reportType=$3
REPORT_PMD="pmd"
REPORT_XCODE="xcode"
REPORT_HTML="html"
myworkspace=${projectName}
myscheme=${scheme}
echo "myworkspace是:${myworkspace}"
echo "myscheme是:${myscheme}"
echo "reportType为:${reportType}"
# 清除上次编译数据
if [ -d ./build/derivedData ]; then
echo '-----清除上次编译数据derivedData-----'
rm -rf ./build/derivedData
fi
# xcodebuild -workspace $myworkspace -scheme $myscheme clean
xcodebuild clean
echo '-----开始编译-----'
# 生成编译数据
xcodebuild -workspace ${myworkspace} -scheme ${myscheme} -sdk iphonesimulator -derivedDataPath ./build/derivedData -configuration Debug COMPILER_INDEX_STORE_ENABLE=NO | xcpretty -r json-compilation-database -o compile_commands.json
if [ -f ./compile_commands.json ]
then
echo '-----编译数据生成完毕-----'
else
echo "-----生成编译数据失败-----"
return -1
fi
echo '-----分析中-----'
# 自定义排除警告的目录,将目录字符串加到数组里面 ⚠️⚠️⚠️⚠️⚠️
# 转化为:-e Debug.m -e Port.m -e Test
exclude_files=("Pods" )
exclude=""
for i in ${exclude_files[@]}; do
exclude=${exclude}"-e "${i}" "
done
echo "排除目录:${exclude}"
# 分析reportType
if [[ ${reportType} =~ ${REPORT_PMD} ]]
then
nowReportType="-report-type pmd -o pmd.xml"
elif [[ ${reportType} =~ ${REPORT_HTML} ]]
then
nowReportType="-report-type html -o yuyinbobao_oclint_result.html"
else
nowReportType="-report-type xcode"
fi
# 自定义report 如:
# nowReportType="-report-type html -o oclint_result.html"
# 生成报表
oclint-json-compilation-database ${exclude} -- \
${nowReportType} \
-rc LONG_LINE=200 \
-rc NESTED_BLOCK_DEPTH=5 \
-rc MINIMUM_CASES_IN_SWITCH=3 \
-rc=LONG_METHOD=200 \
-disable-rule ShortVariableName \
-disable-rule UnusedMethodParameter \
-max-priority-1=100 \
-max-priority-2=200 \
-max-priority-3=500
rm compile_commands.json
if [[ ${reportType} =~ ${REPORT_PMD} ]] && [ ! -f ./pmd.xml ]
then
echo "-----分析失败-----"
rm -rf ./build
return -1
else
echo '-----分析完毕-----'
rm -rf ./build
return 0
fi
}
# 替换workspace的名字 ⚠️⚠️⚠️
myworkspace="XXXX.xcworkspace"
# 替换scheme的名字 ⚠️⚠️⚠️
myscheme="XXXX"
# 输出方式 xcode/pmd/html
reportType="html"
oclintForProject ${myworkspace} ${myscheme} ${reportType}