1

I am working on OCLint, and OCLint need all the compile command to do the lint job. now OCLint using xcpretty to parse xcodebuild.log to get the compile commands. So, I have to build the project even I only want to lint few source files. I wonder is there anyway to get the compile commands other than parse the xcodebuild.log?

  • I think there is no suitable other way. But you can think about _reverting your problem_: You can use `cmake` which can create Xcode projects Cmakefiles. BTW. Xcode has a great builtin analyzer. Why are you not using it? – clemens May 11 '17 at 05:28
  • @macmoonshine Thank you very much, I don't familiar with `cmake`, could you be more specific, how I achieve this. And does Xcode buildin analyzer support analyze parts of all source files? – GoInterface May 11 '17 at 06:27
  • I'm not so familiar with `cmake` ;), but you can create Xcode projects easily (http://stackoverflow.com/questions/41829852/how-to-create-xcode-project-from-already-existing-git-cmake-project). You can run the Xcode analyzer with _Product -> Analyze_, or _Shift-Command-B_. – clemens May 11 '17 at 07:52

2 Answers2

2

One way of doing it is to write a wrapper for clang and linkers.

Using this answer: How can I force Xcode to use a custom compiler? you can redirect Xcode to compile your code with your own "clang" which might be a python shell script. This script would just grab a command passed to it and dump it to some file.

One detail though: if you use custom CC Xcode will also try to use it for linking C/C++ files this is why your script has to do nothing if it is called in a linker mode.

I have used this technique for another task: compiling my whole project with -emit-llvm flag to get all my code as LLVM bitcode. The example of a similar Python script can be found here.

Start by writing "hello world" script. Tell Xcode use it as CC, run your project and see the "hello world" string in your build log. From there you will know how to proceed.

Community
  • 1
  • 1
Stanislav Pankevich
  • 11,044
  • 8
  • 69
  • 129
0

I just use the -dry-run and regexpr to filter the compile commands. The -dry-run said, -dry-run do everything except actually running the commands The performance is just ok. And it will be great if xcode provide one. They will be the only who can do this, and I think it is pretty usefull.