-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generated compile_commands.json
uses relative paths for directory
field
#307
Comments
The problem is that if you write out absolute paths, its no longer possible to cache the compilation database between users. It's fairly annoying. |
Is sharing compilation database between users a common thing to do? It's an artefact of build tool, why would you share it instead of generate per user? Another question is whether the utility of being able to share the compilation database outweigh not being able to use clangd, without postprocessing the compilation database, which seems rather annoying. |
Sharing between users is super common, since it speeds everything up. That said, sharing a useless pile of bytes that doesn't work has no value. Maybe the toolchain should have a boolean as to whether it generates absolute paths (with no caching) or relative paths (which are cached). I'm trying to find out how we deal with this internally, since we use |
It seems like internally we use Bxl as a wrapper that takes the |
I would expect generating the compilation database to be very fast, is it actually worth speeding up via caching? |
There's downstream consumers that care if the file was cached or updated, so it gets a bit tricky when we write out these paths if you want to turn something absolute. |
Could you elaborate @bobyangyf? (I somehow missed the replies on this issue, but recently hit this again) More generally, my understanding is that the preferred solution for this would be to use other scripts to generate compilation databases. I don't necessarily mind this, but it is somewhat confusing that there exists a first class |
For the record, I have been using the following script lately: load("@prelude//utils:utils.bzl", "flatten")
load("@prelude//cxx/comp_db.bzl", "CxxCompilationDbInfo")
load("@prelude//cxx/compile.bzl", "CxxSrcCompileCommand")
def _make_entry(ctx: bxl.Context, compile_command: CxxSrcCompileCommand) -> dict:
args = compile_command.cxx_compile_cmd.base_compile_cmd.copy()
# This prevents clangd from jumping into `buck-out` using Go To Definition,
# which significantly improves user experience.
args.add(["-I", "."])
args.add(compile_command.cxx_compile_cmd.argsfile.cmd_form)
args.add(compile_command.args)
ctx.output.ensure_multiple(args)
return {
"file": compile_command.src,
"directory": ctx.fs.abs_path_unsafe(ctx.root()),
"arguments": args,
}
def make_compilation_database(ctx: bxl.Context, actions):
db = []
for name, analysis_result in ctx.analysis(flatten(ctx.cli_args.targets)).items():
comp_db_info = analysis_result.providers().get(CxxCompilationDbInfo)
if comp_db_info:
db += [_make_entry(ctx, cc) for cc in comp_db_info.info.values()]
db_file = actions.declare_output("compile_commands.json")
actions.write_json(
db_file.as_output(),
db,
with_inputs = True,
pretty = True,
)
return db_file
def _gen_impl(ctx: bxl.Context):
actions = ctx.bxl_actions().actions
ctx.output.print(ctx.output.ensure(make_compilation_database(ctx, actions)))
gen = bxl_main(
impl = _gen_impl,
cli_args = {
"targets": cli_args.list(cli_args.target_expr()),
},
) What I like about is is that:
|
This is a diffent approach than facebook#510. The main differences are: - All required dependencies, such as generated code, are materialized, so that tools that use the compilation database work can find those and work properly. - Files that are included in multiple targets result in multiple entries in the compilation database. Closes facebook#307
Summary: This is a diffent approach than #510. The main differences are: - All required dependencies, such as generated code, are materialized, so that tools that use the compilation database work can find those and work properly. - Files that are included in multiple targets result in multiple entries in the compilation database. Closes #307 Pull Request resolved: #810 Reviewed By: scottcao Differential Revision: D66984456 Pulled By: cjhopman fbshipit-source-id: e53c5cfdcf32e4c34331d7343c06a486a971d27e
The move to `cxx_internal_tools` broke open source users that had a custom `make_comp_db` to work around facebook#307. This commit makes it configurable so that OSS users can again provide their own script to generate legal `compile_commands.json` files. A few remaining tools are made `PUBLIC` so that OSS users can simply reuse them.
Summary: The move to `cxx_internal_tools` broke open source users that had a custom `make_comp_db` to work around facebook/buck2#307. This commit makes it configurable so that OSS users can again provide their own script to generate legal `compile_commands.json` files. A few remaining tools are made `PUBLIC` so that OSS users can simply reuse them. X-link: facebook/buck2#847 Reviewed By: dtolnay Differential Revision: D68327054 fbshipit-source-id: 3c553e7d575928e07728e7525138f45d9b6f2413
Summary: The move to `cxx_internal_tools` broke open source users that had a custom `make_comp_db` to work around #307. This commit makes it configurable so that OSS users can again provide their own script to generate legal `compile_commands.json` files. A few remaining tools are made `PUBLIC` so that OSS users can simply reuse them. Pull Request resolved: #847 Reviewed By: dtolnay Differential Revision: D68327054 fbshipit-source-id: 3c553e7d575928e07728e7525138f45d9b6f2413
Hi,
I'm having issues using the generated the output from the
compilation-database
subtarget, which seems to boil down to clangd not liking relativedirectory
fields.Here's how to reproduce the issue using
examples/with_prelude
:At this point clangd starts, but it generates a bunch of erroneous diagnostics and doesn't let me go to the definition of
print_hello
. If I editcompile_commands.json
to makedirectory
an absolute path and openmain.cpp
again, everything works.Arguably, clangd could support relative paths, but looking around on the internet indicates that this is unlikely (also clang-tidy depends on absolute
directory
paths).Could the
directory
path that Buck2 generates be made absolute?Thanks!
The text was updated successfully, but these errors were encountered: