Compile/refactor iOS Xcode projects

I've written a simple libtooling based tool to refactor source code, and
while it works on simple projects, I'd really like to run it over an iOS
Xcode project. Is there a way to do this?

I've tried compiling iOS apps through command line (using
http://commandlinefanatic.com/cgi-bin/showarticle.cgi?article=art024), but
that hasn't worked for me, and I'd like to create an easier experience for
people wanting to use the tool. Is there a good way to run the tool over a
project and refactor source? I'm not married to libtooling, if libclang
provides an easier way to do this.

In article <1393616491465-4038170.post@n3.nabble.com>,
    s0rcy <siddarth13+clangcfe@gmail.com> writes:

I've written a simple libtooling based tool to refactor source code, and
while it works on simple projects, I'd really like to run it over an iOS
Xcode project. Is there a way to do this?

I think your best bet is to find some way of creating a
compile_commands.json from your Xcode project.

CMake can go the reverse direction -> making an Xcode project from
CMakeLists.txt.

Xcode projects are simple text files, you could probably get yourself
generating a reasonable compile_commands.json from a simple perl or
python script.

To run frontend tools on xcode projects, a first solution is indeed to
generate a file compile_commands.json, possibly using xcodebuild -dry-run
and some parsing script like "oclint-xcodebuild" (see the oclint
project on github).

It is also possible to run frontend plugins directly by setting
appropriate "build settings" of xcode. (Several ways to do this, you
can set them on the command line for instance: xcodebuild build
FOO=bla.)

Here are a few build settings that I found useful to inject C flags:
  OTHER_CFLAGS
  OTHER_CPLUSPLUSFLAGS

or to replace the compiler(s) and linker(s):
  CC
  CPLUSPLUS
  LD
  LDPLUSPLUS
  LIBTOOL

The same approach works to control the "analyze" action:
  CLANG_ANALYZER_EXEC
  CLANG_ANALYZER_OTHER_FLAGS

Disclaimer: some of those build settings are undocumented (afaik). Use
at your own risk.

-- Mathieu

Thanks for the responses!

I managed to get the command line build to work, but it's a bit ghetto - the
suggestion for oclint-xcodebuild and running the tool using the resulting
compilation database looks like something I should investigate.

Adding a clang plugin as CC flags in Xcode seemed like a workable solution,
but from what I can understand, that doesn't let you reason about
declarations across files. Is there accurate?

In article <1394296800923-4038346.post@n3.nabble.com>,
    s0rcy <siddarth13+clangcfe@gmail.com> writes:

I managed to get the command line build to work, but it's a bit ghetto - the
suggestion for oclint-xcodebuild and running the tool using the resulting
compilation database looks like something I should investigate.

I stumbled on this today:
<http://ffevotte.github.io/clang-tags/>

See Section 2.1 "Creating the compilation database", which shows a way
to create the compile_commands.json by tracing an actual build.