From: Marcus <baronmarcus2005@gmail.com>
To: nathan@kernel.org, nsc@kernel.org
Cc: linux-kbuild@vger.kernel.org, llvm@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: [PATCH] run-clang-tools: Resolve the compilation database before changing directory
Date: Mon, 9 Nov 2026 22:16:18 +0100 [thread overview]
Message-ID: <20261109211618.1496-1-baronmarcus2005@gmail.com> (raw)
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.
After reading the JSON file, resolve its containing directory to an
absolute path for clang-tidy's -p option. This preserves the caller's path
resolution when the subprocess changes directory.
The issue, fix, and reproducer were developed with OpenAI Codex assistance.
Verified with Python 3.13 and clang-tidy 23.1.4 using a C file requiring a
definition from the database, with relative and absolute database paths
outside the build directory and a database in the working directory.
Fixes: 6ad7cbc01527 ("Makefile: Add clang-tidy and static analyzer support to makefile")
Signed-off-by: Marcus <baronmarcus2005@gmail.com>
---
scripts/clang-tools/run-clang-tools.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/scripts/clang-tools/run-clang-tools.py b/scripts/clang-tools/run-clang-tools.py
index 79d58b34..cc19f8bb 100755
--- a/scripts/clang-tools/run-clang-tools.py
+++ b/scripts/clang-tools/run-clang-tools.py
@@ -86,6 +86,8 @@ def main():
with open(args.path) as f:
datastore = json.load(f)
+ args.path = os.path.dirname(os.path.abspath(args.path))
+
lock = multiprocessing.Lock()
try:
with multiprocessing.Pool(initializer=init, initargs=(lock, args)) as pool:
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.51.2.windows.1
reply other threads:[~2026-11-09 21:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261109211618.1496-1-baronmarcus2005@gmail.com \
--to=baronmarcus2005@gmail.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=nathan@kernel.org \
--cc=nsc@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®