Generate Clang compilation database

747 views
Skip to first unread message

Jon Butler

unread,
Feb 26, 2014, 6:36:14 PM2/26/14
to chromi...@chromium.org
Hi all,

I'm writing some basic static analysis tools for Blink and Chromium, and I wondered if anyone could tell me the best way to provide the correct includes and defines to each file being analysed? For context, I'm using libtooling and running the script over a subtree of code. Clang docs seem to suggest that getting cmake to generate a JSON-formatted compilation database is the typical way to go about this, but with Chromium's slightly funky build system, I'm not sure that's an option.

I've seen a project called Build EAR (BEAR), which looks like it intercepts calls to the compiler and stashes the options used for each one, but I know a number of Googlers are using Clang, and I'm sure they've got a better / less hacky way.

Thanks in advance,
Jon

James Robinson

unread,
Feb 26, 2014, 6:39:47 PM2/26/14
to jbu...@chromium.org, Chromium-dev
You can ask ninja what includes/flags/etc it would use for a given target.  That's how chromium.ycm_extra_conf.py works:


There's a big of complexity here in mapping a file to a target (this guesses), but it works pretty well.

- James


--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.

Scott Graham

unread,
Feb 26, 2014, 6:47:07 PM2/26/14
to James Robinson, jbu...@chromium.org, Chromium-dev
I don't think the ycm script uses this, but there's also ninja -t compdb which might be close to what you want.

Dirk Pranke

unread,
Feb 26, 2014, 6:57:41 PM2/26/14
to Scott Graham, James Robinson, jbu...@chromium.org, Chromium-dev
This. I would be surprised if ninja -t compdb isn't what you want.

Vivek Galatage

unread,
Feb 26, 2014, 10:34:39 PM2/26/14
to Dirk Pranke, jbu...@chromium.org, Scott Graham, James Robinson, Chromium-dev
I was also exploring this option and I got the ninja tool's "-t commands" option handy for this.

You could execute "ninja -C out\Release -t commands <target name>" which just outputs the commands those will be executed. Then we could write the logic to parse the correct includes and the defines from this output. 

Hope this helps! All the best.

yezhang989

unread,
Jan 4, 2018, 2:27:52 AM1/4/18
to Chromium-dev, jbu...@chromium.org
Hi, Jon Butler.
 
Did you find a way to generate a compilation database for Blink and Chromium?
 
--yezhang

在 2014年2月27日星期四 UTC+8上午7:36:14,Jon Butler写道:

Daniel Cheng

unread,
Jan 4, 2018, 3:11:11 AM1/4/18
to yezha...@gmail.com, Chromium-dev, jbu...@chromium.org
https://cs.chromium.org/chromium/src/tools/clang/scripts/generate_compdb.py is a helper script that generates compile DBs for Chromium.

Daniel

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/288429ba-7ca0-49ea-b687-d8a1d3454960%40chromium.org.
Reply all
Reply to author
Forward
0 new messages