OCLint静态语法分析工具(安装使用步骤)

来源:互联网 发布:linux sap systemcopy 编辑:程序博客网 时间:2024/05/16 14:59

Brief Introduction:

homepage

OCLint is a static code analysis tool for improving quality and reducing defects by inspecting C, C++ and Objective-C code and looking for potential problems like:

  • Possible bugs - empty if/else/try/catch/finally statements
  • Unused code - unused local variables and parameters
  • Complicated code - high cyclomatic complexity, NPath complexity and high NCSS
  • Redundant code - redundant if statement and useless parentheses
  • Code smells - long method and long parameter list
  • Bad practices - inverted logic and parameter reassignment

Get OCLint

You can get the latest version by building from source code or downloading pre-compiled binaries.


Installation¶

Both pre-compiled binary distribution and local build bundle should end up with an OCLint release with which file tree similar to this:

oclint-release|-bin|-lib|---clang|-----3.4|-------include|-------lib|---oclint|-----rules|-----reporters

Even without installation, oclint is able to be invoked directly from bin directory now.

In order to ease the invocation, it’s recommended to add OCLint’s bin folder to system PATH, the environment variable that tells system which directories to search for executable files.

(即使没有安装,oclint能够直接从bin目录调用。 
为了缓解调用,它建议添加OCLint的bin文件夹到系统路径,环境变量,告诉系统目录来搜索可执行文件。)

Option 1: Directly Adding to PATH¶

Following code snippet is an example for the .bashrc or .bash_profile file that is sourced when terminal launches.

OCLINT_HOME=/path/to/oclint-releaseexport PATH=$OCLINT_HOME/bin:$PATH

Option 2: Copying OCLint to System PATH¶

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.

Verifying Installation¶

Open a new terminal prompt, and execute oclint directly from there and expect message similar to below:

$ oclintoclint: Not enough positional command line arguments specified!Must specify at least 1 positional arguments: See: oclint -help

That’s it – if OCLint is pretty new to you, tutorial would lead you by applying the tool to a sample code, and explaining a few concepts along the way.

0 0
原创粉丝点击