Generate JSON compilation database from make (or other compile tools).
The cmake can generate the compilation database with -DCMAKE_EXPORT_COMPILE_COMMANDS=ON.
And the Build EAR try to generate the compilation database, but it maybe failed for some cross-compile project.
compile-db-gen do well for complicate compiler.
Just put your make command after compile-db-gen.py, eg:
compile-db-gen.py make
Then you’ll get the compile_commands.json. And you also can run follow command when you wan’t to get detail:
python compile-db-gen.py trace make OPTS
python compile-db-gen.py parse compile_commands.raw compile_commands.json
for more options, please run
python compile-db-gen.py -h
The strace can follow the compile tools and give the compile detail.
And compile-db-gen.py will follow the log file from strace compile procedural, then output the compile commands.
The strace-4.8 or high required.
The compile-db-gen.py depends on the child terminal informations contain parent pid from strace output, the follow log give hists that child(pid=937) ended, and pid for it’s parent is pid=936.
[pid 936] — SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=937, si_status=0, si_utime=0, si_stime=0} —
but the strace-4.5 seems dosn’t give the child pid.
[pid 936] — si_code=CLD_EXITED SIGCHLD 0 —
I didn’t try compile-db-gen.py with the strace-4.6, strace-4.7, if you run compile-db-gen.py with starce-4.6/4.7, please let me know it success or failed.
scan-build It replace the CC, CXX env string, and get the compile database, but some makefile didn’t care the CC, CXX env settings.
Build EAR It inject libbear.so via LD_PRELOAD or DYLD_INSERT_LIBRARIES environment variables, then filter the compile command. I found Bear didn’t work for some complicate sencen. For example, on amd_64 environment, the libear.so is ELF-64, then make file call some x86 exetable, the LD_PRELOAD won’t work.
clang-tags trace The compile-db-gen.py very similar to ‘clang-tags trace’, but more flexiable.