CLANG-QUERY(1)

πŸ“¦ version 12.0.1, in ubuntu jammy

πŸ’– NAME πŸ’–

okay so bestie, this is the manual page for clang-query β€” yes, the whole CLANG-QUERY(1) situation, she's a User Commands girlie, and she's version 12. come sit with me, we're gonna get through this together 🫢


✨ DESCRIPTION ✨

here's how you actually call her:

USAGE: clang-query [options] <source0> [... <sourceN>]

and here's everything she takes, no skips, no cuts, we're doing all of it πŸ‘‘

🌈 Generic Options 🌈

  • --help β€” shows you all the available options. and if that wasn't enough for you, --help-hidden gives you even more πŸ‘€
  • --help-list β€” prints the list of available options. and yeah, there's a --help-list-hidden for more, because of course there is πŸ’…
  • --version β€” tells you which version of the program you're running. classic, iconic, never misses.

πŸŽ€ clang-query options πŸŽ€

  • -c=<command> β€” specify the command to run
  • --extra-arg=<string> β€” an extra argument that gets appended to the compiler command line
  • --extra-arg-before=<string> β€” an extra argument that gets prepended to the compiler command line (yes bestie, before, not after, they're different, don't mix them up πŸ’€)
  • -f=<file> β€” read commands from a file
  • -p=<string> β€” the build path
  • --preload=<file> β€” preload commands from a file and start interactive mode. it's giving multitasking 🌸
  • --use-color β€” uses colors in detailed AST output. and here's the tea: if you don't set this, colors get used anyway if the terminal connected to standard output supports colors. so like, it's flexible. she's flexible.

πŸ¦‹ about that build path πŸ¦‹

so -p <build-path> is what you use to read a compile command database. yes, "database", very serious, very grown-up.

for example β€” and this is literally the example β€” it can be a CMake build directory that has a file called compile_commands.json in it. to get that output, use the -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMake option. πŸŽ€

and if you don't specify a build path? then she goes searching for compile_commands.json through all the parent paths of the first input file. she's resourceful like that.

if you want an example of setting up Clang Tooling on a source tree, go here:

https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html

πŸ’œ about those source files πŸ’œ

<source0> ... you specify the paths of source files. and here's the part you actually need to remember:

  • these paths get looked up in the compile command database
  • if the path of a file is absolute, it needs to point into CMake's source tree
  • if the path is relative, then the current working directory needs to be in the CMake source tree, and the file must be in a subdirectory of the current working directory
  • "./" prefixes in the relative files get automatically removed
  • but the rest of a relative path must be a suffix of a path in the compile command database
lowkey this is the part that trips everyone up so read it twice bestie, i'm not even joking 😭

and that's the whole vibe. clang-query 12, born February 2022, forever repping CLANG-QUERY(1). slay, periodt, go query some clang πŸ’…βœ¨

πŸ“¦ where this page comes from