CLANG-QUERY(1)

πŸ“¦
version 13.0.1 Β· 3 versions
, in ubuntu jammy

πŸ’… CLANG-QUERY β€” the clang-query(1) page, but make it make sense

okay bestie, welcome to the User Commands corner of the manual, and yes, this is the whole entire vibe of clang-query. it's giving "AST query tool that runs your little commands," and honestly? iconic.


✨ NAME ✨

clang-query β€” manual page for clang-query 13 πŸŽ€


🌸 DESCRIPTION 🌸

so here's the tea, fr fr β€” this is how you run it:

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

and now the options, which we are going to go through one by one, no skipping, because every single one matters πŸ’–

🌈 OPTIONS 🌈

⭐ Generic Options ⭐

  • --help β€” shows you all the available options. (there's also --help-hidden if you want the extra secret menu, no cap πŸ‘€)
  • --help-list β€” prints out a whole list of the available options. (and yeah, --help-list-hidden exists too, for the hidden ones πŸ’€)
  • --version β€” tells you which version of this program you're running. slay.

πŸ¦‹ clang-query options πŸ¦‹

  • -c=<command> β€” pick a command to run ✨
  • --extra-arg=<string> β€” an extra argument to append to the compiler command line
  • --extra-arg-before=<string> β€” an extra argument to prepend to the compiler command line (yes, before, not after, the order is the whole point 🫢)
  • -f=<file> β€” read commands from a file πŸ“„
  • -p=<string> β€” build path
  • --preload=<file> β€” preload commands from a file and then start interactive mode πŸŽ€
  • --use-color β€” use colors in the detailed AST output. and if you don't set it, colors get used anyway when the terminal connected to standard output supports colors 🌈 lowkey automatic, highkey cute

πŸ’œ the -p lore πŸ’œ

-p <build-path> is how you read a compile command database. that's the whole job, bestie.

for example, it can be a CMake build directory that has a file named compile_commands.json sitting in it β€” use the -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMake option to get that output. and when no build path is specified at all? a search for compile_commands.json will be attempted through all parent paths of the first input file. see:

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

for an example of setting up Clang Tooling on a source tree. iykyk πŸ’…


🧚 the <source0> situation 🧚

<source0> ... β€” this is where you specify the paths of source files. these paths are looked up in the compile command database, and there are rules, bestie, so listen up:

  • if the path of a file is absolute, it needs to point into CMake's source tree.
  • if the path is relative, 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 will be automatically removed 🧹
  • but the rest of a relative path must be a suffix of a path in the compile command database. periodt.

okay genuine warning vibes though: that path stuff is not a suggestion, it's the actual contract. if your relative path isn't a suffix of a path in the compile command database, it's not gonna work, and no amount of manifesting will fix it 😭

and that's the page, bestie!! every flag, every path rule, every word, all of it πŸ’–

this was clang-query 13, dated July 2023 β€” main character energy, absolutely ate, no crumbs left πŸ‘‘βœ¨ bye!! πŸ¦‹

πŸ“¦ where this page comes from