From: vngocvan <vngocvan@gmail.com>
To: nathan@kernel.org, nsc@kernel.org
Cc: ndesaulniers@google.com, morbo@google.com,
justinstitt@google.com, masahiroy@kernel.org,
llvm@lists.linux.dev, linux-kbuild@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] gen_compile_commands: honor the build directory for modules
Date: Thu, 15 Oct 2026 20:57:52 +0700 [thread overview]
Message-ID: <20261015135752.17028-1-vngocvan@gmail.com> (raw)
When invoked from outside the build tree with -d and a modules.order
argument, the script opens .mod files relative to the current directory
instead of the specified build directory. This can fail with
FileNotFoundError or collect commands from unrelated artifacts in the
current directory.
Pass the build directory to cmdfiles_for_modorder() and resolve both
the .mod files and their associated .cmd files relative to it. Absolute
paths continue to work, and the output location is unchanged.
Fixes: ecca4fea1ede ("gen_compile_commands: support *.o, *.a, modules.order in positional argument")
Signed-off-by: vngocvan <vngocvan@gmail.com>
---
scripts/clang-tools/gen_compile_commands.py | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/scripts/clang-tools/gen_compile_commands.py b/scripts/clang-tools/gen_compile_commands.py
index 8d14b81efd73..149135f85f19 100755
--- a/scripts/clang-tools/gen_compile_commands.py
+++ b/scripts/clang-tools/gen_compile_commands.py
@@ -124,7 +124,7 @@ def cmdfiles_for_a(archive, ar):
yield to_cmdfile(obj)
-def cmdfiles_for_modorder(modorder):
+def cmdfiles_for_modorder(modorder, root_directory):
"""Generate the iterator of .cmd files associated with the modules.order.
Parse the given modules.order, and yield every .cmd file used to build the
@@ -132,6 +132,7 @@ def cmdfiles_for_modorder(modorder):
Args:
modorder: The modules.order file to parse
+ root_directory: The directory where the objects were built
Yields:
The path to every .cmd file found
@@ -142,11 +143,11 @@ def cmdfiles_for_modorder(modorder):
base, ext = os.path.splitext(obj)
if ext != '.o':
sys.exit('{}: module path must end with .o'.format(obj))
- mod = base + '.mod'
+ mod = os.path.join(root_directory, base + '.mod')
# Read from *.mod, to get a list of objects that compose the module.
with open(mod) as m:
for mod_line in m:
- yield to_cmdfile(mod_line.rstrip())
+ yield os.path.join(root_directory, to_cmdfile(mod_line.rstrip()))
def process_line(root_directory, command_prefix, file_path):
@@ -206,7 +207,7 @@ def main():
elif path.endswith('.a'):
cmdfiles = cmdfiles_for_a(path, ar)
elif path.endswith('modules.order'):
- cmdfiles = cmdfiles_for_modorder(path)
+ cmdfiles = cmdfiles_for_modorder(path, directory)
else:
sys.exit('{}: unknown file type'.format(path))
base-commit: 0fcb05b72344f40806cbe810de8872f1698bf053
--
2.56.0
next reply other threads:[~2026-10-15 13:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 13:57 vngocvan [this message]
2026-10-15 15:33 ` [PATCH] gen_compile_commands: honor the build directory for modules Nick Desaulniers
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=20261015135752.17028-1-vngocvan@gmail.com \
--to=vngocvan@gmail.com \
--cc=justinstitt@google.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=masahiroy@kernel.org \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.