bazel icon indicating copy to clipboard operation
bazel copied to clipboard

obtain compilation flags or compilation database from bazel

Open cnsgsz opened this issue 11 years ago • 31 comments

to have good auto complete, etc in emacs, etc, tools like irony mode or semantic often requires either compilation flags or compilation database (e.g. see compilation database under https://github.com/Sarcasm/irony-mode). is there an easy way to get that from Bazel?

cnsgsz avatar Jun 20 '15 18:06 cnsgsz

Do you mean you want to get the list of flag /commands for Bazel? For that we have 'bazel help completion' that we use for generating shell completion helpers. Le sam. 20 juin 2015 à 20:50, cnsgsz [email protected] a écrit :

to have good auto complete, etc in emacs, etc, tools like irony mode or semantic often requires either compilation flags or compilation database (e.g. see compilation database under https://github.com/Sarcasm/irony-mode). is there an easy way to get that from Bazel?

— Reply to this email directly or view it on GitHub https://github.com/google/bazel/issues/258.

Damien

damienmg avatar Jun 20 '15 20:06 damienmg

I meant the full gcc commands bazel use for each compilation unit, like gcc -I xxx -D yyy -include zzz foo.cc, or something similar that would reveal the dependencies between files. Tools for auto code completion such as irony mode or semantic in emacs requires those information to perform well.

cnsgsz avatar Jun 20 '15 20:06 cnsgsz

Is the -s flag what you are looking for (it prints the list of command it executes and there is also --nobuild to don't actually execute the build commands)?

I don't really understand why the code completion need those. Do you know why it needs it and what exactly it needs? The part on "compilation database" is pretty obscure. Le sam. 20 juin 2015 à 22:48, cnsgsz [email protected] a écrit :

I meant the full gcc commands bazel use for each compilation unit, like gcc -I xxx -D yyy -include zzz foo.cc, or something similar that would reveal the dependencies between files. Tools for auto code completion such as irony mode or semantic in emacs requires those information to perform well.

— Reply to this email directly or view it on GitHub https://github.com/google/bazel/issues/258#issuecomment-113818771.

Damien

damienmg avatar Jun 20 '15 20:06 damienmg

P3 for now because so far it seems a solution already exists (the -s flag).

laszlocsomor avatar Jun 23 '15 11:06 laszlocsomor

I think it's actually resolved. Closing for now, please ping if you still have questions.

damienmg avatar Jun 23 '15 12:06 damienmg

I got something like below with -s. However, the path under -iquote seems to be a temporary directory, rather than the real include path/directory. I think the auto completion tool needs the real include directory/file to know when a .c says #include foo.h, which foo.h it is referring to.

(cd /home/swang/.cache/bazel/_bazel_swang/1255f70669ee87603abcd2c127b1fe2d/project &&
exec env -
INTERCEPT_LOCALLY_EXECUTABLE=1
/usr/bin/gcc '-std=c++0x' -iquote . -iquote bazel-out/local_linux-fastbuild/genfiles -isystem tools/cpp/gcc3 '-frandom-seed=bazel-out/local_linux-fastbuild/bin/tools/cpp/_objs/malloc/tools/cpp/empty.pic.o' -MD -MF bazel-out/local_linux-fastbuild/bin/tools/cpp/_objs/malloc/tools/cpp/empty.pic.d -fPIC -c tools/cpp/empty.cc -o bazel-out/local_linux-fastbuild/bin/tools/cpp/_objs/malloc/tools/cpp/empty.pic.o)

cnsgsz avatar Jun 27 '15 03:06 cnsgsz

The path under iquote should be valid from the workspace too after a Bazel build Le sam. 27 juin 2015 à 05:49, cnsgsz [email protected] a écrit :

I got something like below with -s. However, the path under -iquote seems to be a temporary directory, rather than the real include path/directory. I think the auto completion tool needs the real include directory/file to know when a .c says #include foo.h, which foo.h it is referring to.

(cd /home/swang/.cache/bazel/_bazel_swang/1255f70669ee87603abcd2c127b1fe2d/project &&
exec env -
INTERCEPT_LOCALLY_EXECUTABLE=1
/usr/bin/gcc '-std=c++0x' -iquote . -iquote bazel-out/local_linux-fastbuild/genfiles -isystem tools/cpp/gcc3 '-frandom-seed=bazel-out/local_linux-fastbuild/bin/tools/cpp/_objs/malloc/tools/cpp/empty.pic.o' -MD -MF bazel-out/local_linux-fastbuild/bin/tools/cpp/_objs/malloc/tools/cpp/empty.pic.d -fPIC -c tools/cpp/empty.cc -o bazel-out/local_linux-fastbuild/bin/tools/cpp/_objs/malloc/tools/cpp/empty.pic.o)

— Reply to this email directly or view it on GitHub https://github.com/google/bazel/issues/258#issuecomment-115953204.

damienmg avatar Jun 27 '15 07:06 damienmg

when I do ls bazel-out/local_linux-fastbuild/, I only see bin under it, not genfile.

cnsgsz avatar Jun 27 '15 16:06 cnsgsz

Well if you have no genfiles then it's normal the folder isn't created yet. It can happens if you haven't perform a full build yet.

damienmg avatar Jun 29 '15 06:06 damienmg

I just bazel clean and bazel build, and has the binary. But still there is only bin under local_linux-fastbuild, not genfiles.

cnsgsz avatar Jun 30 '15 02:06 cnsgsz

I have reopen the bug. We are going on working on IDE and provide a generic interface that might include what you want.

damienmg avatar Jun 30 '15 08:06 damienmg

I confirmed it will be included in our IDE support. We will get back to it when our IDE support is out.

damienmg avatar Jun 30 '15 13:06 damienmg

Any update?

shawnLeeZX avatar Aug 22 '16 13:08 shawnLeeZX

This would be super useful for me as well. I see that the some IDE support has been added, how could this be implemented from the current IDE support?

ghost avatar Sep 29 '16 17:09 ghost

I believe the aspects should provide all you need: https://bazel.build/blog/2016/06/10/ide-support.html

dslomov avatar Dec 08 '16 17:12 dslomov

+1. Compilation database is really useful for setting up a ycmd development env.

amosbird avatar Dec 25 '16 14:12 amosbird

So is there a way to generate a LibTooling-compatible compilation database for use with Clang's analyzers and with Vim's YouCompleteMe plugin for C++? I couldn't find a way to do it, preventing me from switching away from CMake (which does generate one). Clang-Tidy etc. also require the same compilation database for C++.

Sydius avatar May 07 '17 01:05 Sydius

+1 for compilation database support.

chpatton013 avatar May 09 '17 20:05 chpatton013

This would allow facebook/infer#457 - +1?

petemounce avatar Aug 09 '17 09:08 petemounce

I think ideally this would be doable via aspects (assuming that they have access to things like e.g. compilation flags), but I couldn't find any existing example in the wild that does this.

I did find this, though: https://github.com/vincent-picaud/Bazel_and_CompileCommands, which uses action_listener and extra_action to generate a compilation database. It requires a bit of setup in the form of some Python scripts that perform the post-processing, but there's a convenient shell script that can generate all the needed files for you. I was able to successfully use it in my project: https://github.com/voithos/quarkGL

voithos avatar Sep 03 '17 04:09 voithos