Re: [PATCH] run-clang-tools: Resolve the compilation database before changing directory

From: Nathan Chancellor

Date: Wed Nov 11 2026 - 01:08:24 EST


> The script reads the compilation database relative to its working
> directory, but passes the same path to clang-tidy after switching to each
> entry's directory. When the database is outside the build directory, a
> relative path can therefore point to a nonexistent location. clang-tidy
> then runs without the recorded compilation flags or finds an unrelated
> database in a parent directory.
>
> For example, invoking the script with database/compile_commands.json from
> the parent of database/ and build/ fails to load the database when its
> entries use build/ as their directory.

I do not believe this script is meant to be called arbitrarily by a
user. It is only designed to be called within Kbuild directly via the
clang-tidy and clang-analyzer targets. The rules for those targets
mandate using the current build's compile_commands.json through their
prerequisites, so the script's current working directory must be the
same as the directory of every entry in compile_commands.json, so I do
not think your reproducer can happen in practice. If it can happen
through using one of those targets, please demonstrate how.

--
Cheers,
Nathan