build icon indicating copy to clipboard operation
build copied to clipboard

compile_commands.json

Open bhack opened this issue 5 years ago • 25 comments

It could be nice if we could generate/distribute compile_commands.json to better interact with some IDE and our c++ code.

I.e. In Bazel and also in Vscode the the official Bazel team vscode plugin we don't have in tree support to generate compile_commands: https://github.com/bazelbuild/bazel/issues/258 https://github.com/bazelbuild/vscode-bazel/issues/179

I've tried some quite popular community workaround like: https://github.com/grailbio/bazel-compilation-database

But the problem is that we are using --action_env for build when we generate our .bazelrc with python configure.py and so these arguments not supported in other command like e.g. bazel query https://github.com/bazelbuild/bazel/issues/10226. This is going to invalidate the official bazel vscode plugin that need to execute query command but also the bazel-compilation-database workaround cause we have problem to retrieve our env variable.

bhack avatar May 27 '20 12:05 bhack

/cc @gunan This could be interesting to have in Tensorflow itself but I don't want to duplicate the ticket there. I don't know if you have an internal route on the Bazel team.

bhack avatar May 29 '20 23:05 bhack

I am not sure what compile_commands.json file is. Is this file generated by bazel? Could you provide more details?

gunan avatar May 30 '20 01:05 gunan

@gunan compile_commands.json Is https://clang.llvm.org/docs/JSONCompilationDatabase.html and It is used by many IDEs for integrating with c++ project. If you see I've mentioned two Bazel issues (one for Basel itself and the other one for the Bazel team official plugin for Vscode) cause currently you need to use some external tools/workarounds) to generate/distribuire compile_commands.json with Bazel projects.

bhack avatar May 30 '20 08:05 bhack

This is also useful for clangd and Clang Tooling based refactorings.

mihaimaruseac avatar Jun 23 '20 23:06 mihaimaruseac

@mihaimaruseac are you using the tool or not? :wink: See https://github.com/tensorflow/addons/pull/1808#issuecomment-636217541

bhack avatar Jun 23 '20 23:06 bhack

clang-tidy is used, but on the imported code.

What I meant above is other tooling (clang_query and related) and directly on the open source code

mihaimaruseac avatar Jun 24 '20 00:06 mihaimaruseac

From what I can tell, then we would need to update this file every time a new file is added, or a BUILD file is modified?

gunan avatar Jun 24 '20 18:06 gunan

@gunan I've already mentioined two bazel bugs: bazelbuild/bazel#258 bazelbuild/vscode-bazel#179

bhack avatar Jun 24 '20 18:06 bhack

I think I might be able to do it, if I really need this for a security analysis I'm running. No promises yet.

mihaimaruseac avatar Jun 24 '20 19:06 mihaimaruseac

As Bazel team seems is not interested to put resources on this at upstream level many projects are using https://github.com/grailbio/bazel-compilation-database

bhack avatar Jun 24 '20 19:06 bhack

Yes, but I think I have a solution which uses Bazel and a minimal number of additions to the projects .bazelrc

mihaimaruseac avatar Jun 24 '20 21:06 mihaimaruseac

Ok but check to not reinvet the wheel of alternative approaches: https://github.com/grailbio/bazel-compilation-database#alternatives

bhack avatar Jun 24 '20 22:06 bhack

Yes, I'm only trying to get the solution that is most stable and requires fewer changes

mihaimaruseac avatar Jun 24 '20 22:06 mihaimaruseac

@mihaimaruseac Do you think that we could track this issue in the SIG build repo?

bhack avatar Jul 21 '20 12:07 bhack

Yes, let's do that there. Can you open an issue for me please?

I got preempted from working on this, apologies for the delay

mihaimaruseac avatar Jul 21 '20 16:07 mihaimaruseac

Sorry I have no superpowers to migrate this issue.

bhack avatar Jul 21 '20 16:07 bhack

Oh, I meant creating a new one and then we can either close this or just mention this in the other

mihaimaruseac avatar Jul 21 '20 16:07 mihaimaruseac

@gunan So fast. Too fast :wink:

bhack avatar Jul 21 '20 16:07 bhack

Umm, now this should be opened again?

mihaimaruseac avatar Jul 21 '20 16:07 mihaimaruseac

Yup!

bhack avatar Jul 21 '20 16:07 bhack

Check https://github.com/bazelbuild/vscode-bazel/issues/179#issuecomment-773107198

bhack avatar Feb 04 '21 09:02 bhack

Just to add a new resource on this thread:

https://github.com/hedronvision/bazel-compile-commands-extractor

bhack avatar Nov 18 '21 22:11 bhack

Do you think that this could be scheduled in any roadmap?

bhack avatar Jan 25 '22 13:01 bhack

so how to generate the compile_commands.json?

JsBlueCat avatar Jul 09 '22 07:07 JsBlueCat