From: Matthias Kaehlcke <mka@chromium.org>
To: Tom Roeder <tmroeder@google.com>,
Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: linux-kernel@vger.kernel.org,
Raul E Rangel <rrangel@chromium.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Tom Hughes <tomhughes@chromium.org>,
Douglas Anderson <dianders@chromium.org>,
Ryan Case <ryandcase@chromium.org>, Yu Liu <yudiliu@google.com>,
Matthias Kaehlcke <mka@chromium.org>
Subject: [PATCH] gen_compile_command: Add support for separate KBUILD_OUTPUT directory
Date: Thu, 20 Jun 2019 11:45:23 -0700 [thread overview]
Message-ID: <20190620184523.155756-1-mka@chromium.org> (raw)
gen_compile_command.py currently assumes that the .cmd files and the
source code live in the same directory, which is not the case when
a separate KBUILD_OUTPUT directory is used.
Add a new option to specify the kbuild output directory. If the
option is not set the kernel source directory is used.
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
Feel free to bikeshed about the option names ;-)
scripts/gen_compile_commands.py | 28 +++++++++++++++++++---------
1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/scripts/gen_compile_commands.py b/scripts/gen_compile_commands.py
index 7915823b92a5..5a738ec66cc7 100755
--- a/scripts/gen_compile_commands.py
+++ b/scripts/gen_compile_commands.py
@@ -31,15 +31,21 @@ def parse_arguments():
Returns:
log_level: A logging level to filter log output.
- directory: The directory to search for .cmd files.
+ source_directory: The kernel source directory.
+ kbuild_output_directory: The directory to search for .cmd files.
output: Where to write the compile-commands JSON file.
"""
usage = 'Creates a compile_commands.json database from kernel .cmd files'
parser = argparse.ArgumentParser(description=usage)
- directory_help = ('Path to the kernel source directory to search '
+ directory_help = ('Path to the kernel source directory'
'(defaults to the working directory)')
parser.add_argument('-d', '--directory', type=str, help=directory_help)
+ kbuild_output_directory_help = ('Path to the directory to search for '
+ '.cmd files'
+ '(defaults to the kernel source directory)')
+ parser.add_argument('-k', '--kbuild-output-directory', type=str,
+ help=kbuild_output_directory_help)
output_help = ('The location to write compile_commands.json (defaults to '
'compile_commands.json in the search directory)')
@@ -58,11 +64,14 @@ def parse_arguments():
if log_level not in _VALID_LOG_LEVELS:
raise ValueError('%s is not a valid log level' % log_level)
- directory = args.directory or os.getcwd()
- output = args.output or os.path.join(directory, _DEFAULT_OUTPUT)
- directory = os.path.abspath(directory)
+ source_directory = args.directory or os.getcwd()
+ output = args.output or os.path.join(source_directory, _DEFAULT_OUTPUT)
+ source_directory = os.path.abspath(source_directory)
- return log_level, directory, output
+ kbuild_output_directory = args.kbuild_output_directory or source_directory
+ kbuild_output_directory = os.path.abspath(kbuild_output_directory)
+
+ return log_level, source_directory, kbuild_output_directory, output
def process_line(root_directory, file_directory, command_prefix, relative_path):
@@ -109,7 +118,8 @@ def process_line(root_directory, file_directory, command_prefix, relative_path):
def main():
"""Walks through the directory and finds and parses .cmd files."""
- log_level, directory, output = parse_arguments()
+ log_level, source_directory, kbuild_output_directory, output = \
+ parse_arguments()
level = getattr(logging, log_level)
logging.basicConfig(format='%(levelname)s: %(message)s', level=level)
@@ -118,7 +128,7 @@ def main():
line_matcher = re.compile(_LINE_PATTERN)
compile_commands = []
- for dirpath, _, filenames in os.walk(directory):
+ for dirpath, _, filenames in os.walk(kbuild_output_directory):
for filename in filenames:
if not filename_matcher.match(filename):
continue
@@ -131,7 +141,7 @@ def main():
continue
try:
- entry = process_line(directory, dirpath,
+ entry = process_line(source_directory, dirpath,
result.group(1), result.group(2))
compile_commands.append(entry)
except ValueError as err:
--
2.22.0.410.gd8fdbe21b5-goog
next reply other threads:[~2019-06-20 18:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-20 18:45 Matthias Kaehlcke [this message]
2019-06-20 19:23 ` Tom Roeder
2019-06-20 20:47 ` Matthias Kaehlcke
2019-06-20 19:53 ` Nick Desaulniers
2019-06-20 20:13 ` Doug Anderson
2019-06-20 20:25 ` Nick Desaulniers
2019-06-20 20:38 ` Nathan Chancellor
2019-06-20 20:57 ` Doug Anderson
2019-06-20 20:54 ` Matthias Kaehlcke
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=20190620184523.155756-1-mka@chromium.org \
--to=mka@chromium.org \
--cc=dianders@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ndesaulniers@google.com \
--cc=rrangel@chromium.org \
--cc=ryandcase@chromium.org \
--cc=tmroeder@google.com \
--cc=tomhughes@chromium.org \
--cc=yamada.masahiro@socionext.com \
--cc=yudiliu@google.com \
/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®