rizsotto / Bear

Bear is a tool that generates a compilation database for clang tooling.
GNU General Public License v3.0
4.97k stars 321 forks source link

[Request] Ignore some flags while compiling and generating dependencies .d #74

Closed jonthn closed 9 years ago

jonthn commented 9 years ago

Bear has already helped me a lot. But I'm facing an issue and I'm not sure if it was the case with 1.x releases

When I compile my project I use the flags :

cc .... -MMD -MP   ... -o my_unit.o -c my_unit.c

in order to generate the corresponding .d files and I would like that Bear don't store these flags because if it does, then oclint recreate the .d files in the wrong directory.

rizsotto commented 9 years ago

Thanks Jonathan for your report. The new version filters out all -MM? entries, because it is considered to do only the preprocess step of the compilation. It might be a wrong presumption... To fix your problem quickly, open the file 'bear' at line 350, and change the regex to r'^-E$'.

jonthn commented 9 years ago

Thanks for the quick feedback unfortunately the change you proposed doesn't solve my problem.

So for example with the current version of Bear I get this (even with change to the regex) :

    {
        "command": "cc -arch i386 -MMD -MP -fPIC -isystem /usr/include -I/tmp/myproject/include -DNDEBUG -o /tmp/myproject/src/my_file1.o -c  /tmp/myproject/src/my_file1.c", 
        "directory": "/tmp/myproject/src/", 
        "file": "/tmp/myproject/src/my_file1.c"
    }, 

and the output I'm looking for (MMD & MP as you said doesn't impact the compilation so I want to remove them) :

    {
        "command": "cc -arch i386 -fPIC -isystem /usr/include -I/tmp/myproject/include -DNDEBUG -o /tmp/myproject/src/my_file1.o -c  /tmp/myproject/src/my_file1.c", 
        "directory": "/tmp/myproject/src/", 
        "file": "/tmp/myproject/src/my_file1.c"
    }, 
rizsotto commented 9 years ago

I see now. So, you want these compilation in the output, but you want those flags to get rid of. Bear does filtering the compiler invocations, but does not change the flags. How about if you run a post-processing step, which takes a compilation database as input and generate a new one, but modify the command line as you wish? And what if Bear does this post processing step? (I think that was you wanted originally.) I will be away from keyboard for three months, but will come back to this topic.

jonthn commented 9 years ago

Yes I hoped that Bear would do this post processing but I indeed change how I invoke the compiler with a special argument to my Makefiles in order to omit those -MMD -MP flags which is not so much trouble because I only re-generate my database from time to time.