Using oclint-xcodebuild¶
OCLint recognizes a file called compile_commands.json
to figure out the compiler options for parsing each file. By having a compile_commands.json
file, analyzing projects with a large codebase becomes easier. Since all compiler options are implicitly configured in Xcode workspace/project settings, and you can see what actually happens when you invoke xcodebuild
in terminal, this helper program then try to extract adequate compiler options, convert them into JSON Compilation Database format, and save it into compile_commands.json
file.
See also
To gain some context about JSON Compilation Database and compile_commands.json
, read using oclint-json-compilation-database.
Run xcodebuild¶
First of all, you need to help yourself a little bit. xcodebuild
is a command line tool that Apple provides along with your Xcode application to let you build Xcode workspace/project in the terminal.
Read Apple’s official xcodebuild Manual Page from Mac Developer Library is a good starting point if you haven’t done any tasks about xcodebuild
.
It is a quite simple task to some people by figuring out the correct options for xcodebuild
. However, some people may feel it’s not intuitive, so be patient, and take you time. You may find many online tutorials and blog posts that may help.
Okay, we believe you are quite confidence of running xcodebuild
to build your Xcode project. Now, there are two things please pay attention:
- You need to save the
xcodebuild
output to a log file, by convention, name itxcodebuild.log
. You can usexcodebuild <options> | tee xcodebuild.log
to pipe every line of the output toxcodebuild.log
file. - If a source file has been built by Xcode, and it’s not modified since last build, then it might not be built again when you invoke
xcodebuild
. In other words, if it happens, this file won’t be shown in the log. So you 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. (Hope you understand what clean build means after spending the time on learningxcodebuild
.)
Run oclint-xcodebuild¶
So a xcodebuild.log
file should be there properly on the root folder of your Xcode project. Simply run
oclint-xcodebuild
The compile_commands.json
will be generated to the same folder.
What’s next¶
Now you have compile_command.json
file for your Xcode project, you can move onto use oclint-json-compilation-database and use OCLint to inspect your codebase.
Note
oclint-xcodebuild
is still an experimental project. The success of it depends various things, e.g. Mac OS X version, the Xcode version and project settings. However, since developers who use Xcode are familiar with Apple’s manner of supporting only the latest version and one previous version, so oclint-xcodebuild
tries to follow this convention. Your feedback is warmly welcome to help improve this helper program.