博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mac下通过xcodebuild使用oclint
阅读量:4592 次
发布时间:2019-06-09

本文共 3588 字,大约阅读时间需要 11 分钟。

step1 :下载oclint并安装

下载地址: http://oclint.org/downloads.html

选择mac os x或者darwin的包,下载到本地。

文件夹类似以下:

oclint-release|-bin|-lib|---clang|-----3.4|-------include|-------lib|---oclint|-----rules|-----reporters
 
安装官方指南: http://docs.oclint.org/en/dev/intro/installation.html

我们此时在bash(终端terminal)中运行oclint会告诉我们命令找不到。我们须要把它的运行文件路径增加到环境变量或者把运行文件复制到系统文件夹。

方法1(推荐):把路径加到环境变量中(实际是.bash_profile或者.bashrc文件里,关于这两者有不知道的同学能够搜索之)

OCLINT_HOME=/path/to/oclint-release   // /path/to/oclint-release 是运行文件存放路径,比如:/Users/xxx/Desktop/oclint-0.9.dev.a6ffa25export PATH=$OCLINT_HOME/bin:$PATH
关于.bash_profile,mac系统里本身可能不存在,创建和编辑的步骤见下文:
http://blog.csdn.net/openglnewbee/article/details/36663591
关于bashrc,位于/etc文件夹下。使用command+shift+g 能够前往/etc,找到bashrc文件改动权限后能够编辑。
 
方法2:把运行文件复制到系统文件夹(请自行尝试)
 

A few directories are supposed to be in the system PATH already, to mention a few, /usr/local/bin, /usr/bin, /bin, etc. Therefore, it’s also possible to copy the OCLint binaries into one of these folders, and move the dependencies over. As an example, presumes /usr/local/bin is in the PATH (may require root permission).

  1. cp bin/oclint* /usr/local/bin/
  2. cp -rp lib/* /usr/local/lib/

Dependency libraries are required to be put into appropriate directory, because oclint executable searches $(/path/to/bin/oclint)/../lib/clang, $(/path/to/bin/oclint)/../lib/oclint/rules and $(/path/to/bin/oclint)/../lib/oclint/reporters for builtin headers and dynamic libraries by default.

以上两个方法运行完当中1个我们就能够说oclint已经安装完毕了。此时在bash中运行oclint应该得到例如以下提示:

oclint: Not enough positional command line arguments specified!
 
step 2:通过xcodebuild运行oclint命令
1.在bash中通过cd命令进到须要lint的工程路径下
2.在bash中运行:xcodebuild | tee xcodebuild.log 
(若工程中存在多个不同的target,依照例如以下格式输入: xcodebuild  -target selectedTargetName | tee xcodebuild.log,将须要跑的target名字填入到命令中  )
此命令调用xcodebuild进行了编译并把相关日志信息输入到xcodebuild.log。该log文件是兴许步骤的必要条件,生成在当前的工程文件夹中.官方解释例如以下:
We need to save the xcodebuild output to a log file, by convention, name it xcodebuild.log. We can use xcodebuild 
| tee xcodebuild.log to pipe every line of the output to xcodebuild.log file.
3.在bash中运行 oclint-xcodebuild xcodebuild.log
此步骤是利用之前的.log文件通过oclint-xcodebuild的可运行文件生成了名为compile_commands.json的json格式文件,该文件应该包括了多组内容。当中的key分别为directory、command、file,该文件不应该为空。

此文件是下一步输入的必要条件。

4. 在bash中运行 oclint-json-compilation-database。此步骤是真正运行了lint,运行完应该在终端输出结果。

若希望输出报告到文件里,运行例如以下命令:
oclint-json-compilation-database -- -o=report.html
 
官方參考指南:http://docs.oclint.org/en/dev/guide/xcodebuild.html
 
注意事项:
1.octool 0.7及曾经的版本号不支持xcode5.
2.在运行前注意运行clean,也可在step2中的第二步运行例如以下命令:

xcodebuild -dry-run | tee xcodebuild.log 说明例如以下:

If a source file has been built by xcodebuild, and it’s not been modified since last build, then it might not be compiled again when you invoke xcodebuild the second time. In other words, if it happens, this file won’t be shown in the log. So we won’t see it in the compile_commands.json. To avoid that, use clean build by removing all build products and intermediate files from the build directory.

However, cleaning and building the entire project takes longer time, especially for those big projects. In this case, if file structure hasn’t been changed, and build settings haven’t been modified, then it’s okay to keep the existing xcodebuild.log and compile_commands.json to save time.

If the xcodebuild build can be guaranteed to be successful with the options specified, then we could also use -dry-run option to build the project without actually running the commands, so that we can still capture the xcodebuild log but with reduced time.

 

转载于:https://www.cnblogs.com/mengfanrong/p/5210709.html

你可能感兴趣的文章
LinkedList、ArrayList各自的使用场景,如何确认应该用哪一个?
查看>>
java 并发——内置锁
查看>>
微信小程序实现各种特效实例
查看>>
JAVA编程思想读书笔记(三)--RTTI
查看>>
[洛谷P3931]SAC E#1 - 一道难题 Tree
查看>>
设计模式学习总结:(5)装饰模式
查看>>
sql JOIN语句应注意on与where的区别
查看>>
[转载]python 详解re模块
查看>>
HDU - 4686 函数积的前缀和
查看>>
k8s系列---EFK日志系统
查看>>
Python list、tuple、dict区别
查看>>
20190127-将一个文件拆分为多个新文件
查看>>
在DevExpress程序中使用GridView直接录入数据的时候,增加列表选择的功能
查看>>
【经验】在CSS中定义a:link、a:visited、a:hover、a:active顺序
查看>>
异常处理
查看>>
Div+Css网页布局
查看>>
linux基本命令
查看>>
Practical Java笔记二:不要使用缺省的equal方法
查看>>
主键和唯一索引的区别(转)
查看>>
2013551814第六次作业
查看>>