Use oclint through xcodebuild in Mac

Source: Internet
Author: User

Step 1: download and install oclint

: Http://oclint.org/downloads.html

Select Mac OS X or Darwin package and download it to your local device.

The directory is similar to the following:

oclint-release|-bin|-lib|---clang|-----3.4|-------include|-------lib|---oclint|-----rules|-----reporters
 
Installation official guide: http://docs.oclint.org/en/dev/intro/installation.html

When we run oclint in bash (terminal), the command cannot be found. We need to add the path of the execution file to the environment variable or copy the execution file to the system directory.

Method 1 (recommended): add the path to the environment variable (actually in the. bash_profile or. bashrc file, you can search for the two)

Oclint_home =/path/to/oclint-release // path/to/oclint-release is the path for storing execution files, for example: /users/XXX/desktop/oclint-0.9.dev.a6ffa25export Path = $ oclint_home/bin: $ path
For. bash_profile, the MAC system may not exist. The steps for creating and editing are as follows:
http://blog.csdn.net/openglnewbee/article/details/36663591
Bashrc is located in the/etc directory. You can use command + Shift + G to go to/etc. Find the bashrc file and edit it after modifying its permissions.
 
Method 2: copy the execution file to the system directory (Please try it yourself)

A few directories are supposed to be in the systemPathAlready, 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/binIs inPath(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, becauseOclintExecutable searches$ (/Path/to/bin/oclint)/../lib/clang,$ (/Path/to/bin/oclint)/../lib/oclint/RulesAnd$ (/Path/to/bin/oclint)/../lib/oclint/reportersFor builtin headers and dynamic libraries by default.

After executing one of the preceding two methods, we can say that the oclint has been installed. The following prompt is displayed when you run oclint in Bash:

oclint: Not enough positional command line arguments specified!
Step 2: run the oclint command through xcodebuild
1. Run the CP command in Bash to enter the project path that requires lint
2. Execute: xcodebuild | tee xcodebuild. Log in bash.
This command calls xcodebuild to compile and input relevant log information to xcodebuild. log. This log file is necessary for subsequent steps and is generated in the current project directory. The official explanation is as follows:
We need to save the xcodebuild output to a log file, by convention, name it xcodebuild.log. We can use xcodebuild <options> | tee xcodebuild.log to pipe every line of the output to xcodebuild.log file.
3. Execute oclint-xcodebuild. Log in bash.
This step uses the previous one. the log file uses the oclint-xcodebuild executable file to generate a JSON format file named compile_commands.json. The file should contain multiple sets of content, where the keys are directory, command, and file, the file should not be empty. This file is required for the next step. 4. Execute oclint-JSON-compilation-database in Bash. In this step, the lint is actually executed and the result should be output on the terminal after execution.
To output the report to a file, run the following command:
oclint-json-compilation-database -- -o=report.html
Official Reference Guide: http://docs.oclint.org/en/dev/guide/xcodebuild.html
Note:
1. octool 0.7 and earlier versions do not support xcode5.
2. Run clean before running the command. You can also run the following command in step 2:

Xcodebuild-dry-run | tee xcodebuild. Log description:

If a source file has been builtXcodebuild, And it's not been modified since last build, then it might not be compiled again when you invokeXcodebuildThe second time. In other words, if it happens, this file won't be shown in the log. So we won't see it inCompile_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'tbeen modified, then it's okay to keep the existingXcodebuild. LogAndCompile_commands.jsonTo save time.

IfXcodebuildBuild can be guaranteed to be successful with the options specified, then we cocould also use-Dry-runOptionBuildThe project without actually running the commands, so that we can still captureXcodebuildLog but with CED time.

 



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.