CLANG-QUERY(1)

πŸ“¦
version 16.0.6 Β· 2 versions
, in debian bookworm

πŸ’– CLANG-QUERY πŸ’–

okay bestie, welcome to clang-query β€” that's the manual page for clang-query 16, and it lives in section 1 of the manual. it's a whole vibe and it's gonna change your life, fr fr. sit down, grab a lil snack πŸ“, and let's get into it.


✨ DESCRIPTION ✨

here's the whole entire usage situation, no cap:

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

and then it just goes straight into OPTIONS, iconic honestly.


🌈 OPTIONS 🌈

🫢 Generic Options 🫢

the lil housekeeping flags, the ones that just exist so you know what exists:

  • --help β€” shows you all the available options. and if you want even more, there's --help-hidden for that πŸ’…
  • --help-list β€” prints the list of available options. and yup, --help-list-hidden if you want the hidden ones too
  • --version β€” tells you the version of this program. that's it. that's the whole job πŸ‘‘

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

now the actual main character flags:

  • -c <command> β€” give it a command to run, just like that
  • --extra-arg=<string> β€” an extra argument that gets appended to the compiler command line
  • --extra-arg-before=<string> β€” same energy but it gets prepended to the compiler command line instead
  • -f <file> β€” read your commands from a file
  • -p <string> β€” the build path
  • --preload=<file> β€” preloads commands from a file and then drops you straight into interactive mode ✨
  • --use-color β€” uses colors in the detailed AST output. and listen, if you don't set this? colors still show up if the terminal connected to standard output supports colors. so it's giving "optional but also not really optional" 😭

πŸŽ€ about that build path tho πŸŽ€

so -p <build-path> is what you use to read a compile command database. very demure, very mindful.

for example (and I mean literally for example, this is straight from the source bestie), it can be a CMake build directory that has a file named compile_commands.json chilling inside it. to get that output you use the -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMake option.

and when you don't specify a build path at all? it goes on a lil quest πŸ” searching for compile_commands.json through all parent paths of the first input file.

want an example of setting up Clang Tooling on a source tree? they got you:

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

🌸 and the source files 🌸

<source0> ... β€” this is where you specify the paths of your source files. these paths get looked up in the compile command database.

here's the tea though, and it's kinda specific so stay with me:

  • 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 has to be in a subdirectory of the current working directory.
  • "./" prefixes in relative files get automatically removed (you're welcome), but the rest of a relative path must be a suffix of a path in the compile command database.
lowkey that last part is the one that gets people, so read it twice bestie, I'm not even joking πŸ™ˆ

and that's the whole page!! you ate that, honestly. this was clang-query 16, dated October 2023, and I'm obsessed with you for reading the whole thing. go compile something cute πŸ’–βœ¨πŸŽ€πŸ¦‹πŸ’…

πŸ“¦ where this page comes from