Skip to content
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

implement features #9

Open
rizsotto opened this issue Jan 23, 2018 · 3 comments
Open

implement features #9

rizsotto opened this issue Jan 23, 2018 · 3 comments

Comments

@rizsotto
Copy link

Hey Guillaume, nice tool you've wrote. I was wondering that what's your opinion to implement these compilation database manipulations?

  • convert all file path to relative from absolute
  • convert all file path to absolute from relative

(Paths can be in directory and file, but also in the command arguments too. Like -I/path/to/include or -o /path/to/output.)

  • filter out duplicate entries.
  • filter compilation commands arguments.

(Duplicates could be when the directory and file, but the command has minor irrelevant differences like -MD or -static which are either preprocessing or linking flags. That's where the flag filtering could help.)

  • exclude files with pattern

(Some project contains dependency code, which they might not want to run the tooling against.)

@Sarcasm
Copy link
Owner

Sarcasm commented Mar 1, 2018

Converting file paths relative <-> absolute, why not, but I'm curious, what use case do you have in mind?
I remember a bug, in clang-tidy I believe, where I needed absolute paths in the compilation database or something like that.
Found it: https://bugs.llvm.org/show_bug.cgi?id=22385

To filter duplicate entries, there is something already, but it's nothing smart, it just outputs one compile command per file:

compdb -p build/ list --unique

Filtering compilation commands arguments would be nice, but I'm wondering if/when I will get to it.

Excluding files with pattern, is something I'd like very much, for the reason you mentioned.
I got this exact issue today.

@d
Copy link

d commented Jul 8, 2019

@Sarcasm In general, custom tools written with libASTMatchers and libTooling have a problem dealing with files that are compiled from different directories. Specifically, when clang -I../../foo and clang -I../foo point to the same foo header search path, the LLVM filesystem abstraction gets really confused about foo.h (at foo/foo.h). This is a problem, when we capture the compilation database for an autoconf + recursive GNU Make project and run Clang-based tools over all files. We are forced to:

  1. Either rewrite the compilation database to all align on the same base directory; or
  2. run something like xargs -n1 <my tool> -p build.debug to work around this

@sim642
Copy link

sim642 commented Nov 23, 2021

I've just hit upon another use case for the absolute→relative paths conversion. In a CI environment, I generate the compilation database from cmake in one place and then want to use it to analyze the project inside a Docker container (with things mounted, but to a different path!). All the commands in the compilation database then refer to non-existent files, although relatively they could still be found.

In many cases it's not really feasible to ensure that all the containers manipulate the project at the exact same path, because different containers might require you to mount your stuff into different places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants