From: Nick Desaulniers <ndesaulniers@google.com>
To: Masahiro Yamada <masahiroy@kernel.org>
Cc: Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>,
Nathan Huckleberry <nhuck@google.com>,
Tom Roeder <tmroeder@google.com>,
clang-built-linux <clang-built-linux@googlegroups.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 3/9] gen_compile_commands: do not support .cmd files under tools/ directory
Date: Fri, 21 Aug 2020 17:27:02 -0700 [thread overview]
Message-ID: <CAKwvOdn0VyObYvoBqoXPGT4o8LPSPsvc=pNpvVtu6jRxxhOKiA@mail.gmail.com> (raw)
In-Reply-To: <20200821190159.1033740-4-masahiroy@kernel.org>
On Fri, Aug 21, 2020 at 12:02 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> The tools/ directory uses a different build system, and the format of
> .cmd files is different because the tools builds run in a different
> work directory.
>
> Supporting two formats compilicates the script.
>
> The only loss by this change is objtool.
>
> Also, rename the confusing variable 'relative_path' because it is
> not necessarily a relative path. When the output directory is not
> the direct child of the source tree (e.g. O=foo/bar), it is an
> absolute path. Rename it to 'file_path'.
>
> os.path.join(root_directory, file_path) works whether the file_path
> is relative or not. If file_path is already absolute, it returns it
> as-is.
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
>
> Changes in v2:
> - New patch
>
> scripts/gen_compile_commands.py | 31 +++++++++++--------------------
> 1 file changed, 11 insertions(+), 20 deletions(-)
>
> diff --git a/scripts/gen_compile_commands.py b/scripts/gen_compile_commands.py
> index 535248cf2d7e..1b9899892d99 100755
> --- a/scripts/gen_compile_commands.py
> +++ b/scripts/gen_compile_commands.py
> @@ -59,23 +59,21 @@ def parse_arguments():
> return args.log_level, directory, output
>
>
> -def process_line(root_directory, file_directory, command_prefix, relative_path):
> +def process_line(root_directory, command_prefix, file_path):
> """Extracts information from a .cmd line and creates an entry from it.
>
> Args:
> root_directory: The directory that was searched for .cmd files. Usually
> used directly in the "directory" entry in compile_commands.json.
> - file_directory: The path to the directory the .cmd file was found in.
> command_prefix: The extracted command line, up to the last element.
> - relative_path: The .c file from the end of the extracted command.
> - Usually relative to root_directory, but sometimes relative to
> - file_directory and sometimes neither.
> + file_path: The .c file from the end of the extracted command.
> + Usually relative to root_directory, but sometimes absolute.
>
> Returns:
> An entry to append to compile_commands.
>
> Raises:
> - ValueError: Could not find the extracted file based on relative_path and
> + ValueError: Could not find the extracted file based on file_path and
> root_directory or file_directory.
> """
> # The .cmd files are intended to be included directly by Make, so they
> @@ -84,20 +82,13 @@ def process_line(root_directory, file_directory, command_prefix, relative_path):
> # by Make, so this code replaces the escaped version with '#'.
> prefix = command_prefix.replace('\#', '#').replace('$(pound)', '#')
>
> - cur_dir = root_directory
> - expected_path = os.path.join(cur_dir, relative_path)
> - if not os.path.exists(expected_path):
> - # Try using file_directory instead. Some of the tools have a different
> - # style of .cmd file than the kernel.
> - cur_dir = file_directory
> - expected_path = os.path.join(cur_dir, relative_path)
> - if not os.path.exists(expected_path):
> - raise ValueError('File %s not in %s or %s' %
> - (relative_path, root_directory, file_directory))
> + abs_path = os.path.abspath(os.path.join(root_directory, file_path))
> + if not os.path.exists(abs_path):
> + raise ValueError('File %s not found' % abs_path)
> return {
> - 'directory': cur_dir,
> - 'file': relative_path,
> - 'command': prefix + relative_path,
> + 'directory': root_directory,
> + 'file': abs_path,
> + 'command': prefix + file_path,
> }
>
>
> @@ -122,7 +113,7 @@ def main():
> result = line_matcher.match(f.readline())
> if result:
> try:
> - entry = process_line(directory, dirpath,
> + entry = process_line(directory,
> result.group(1), result.group(2))
> compile_commands.append(entry)
> except ValueError as err:
> --
> 2.25.1
>
--
Thanks,
~Nick Desaulniers
next prev parent reply other threads:[~2020-08-22 0:27 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-21 19:01 [PATCH v2 0/9] kbuild: clang-tidy Masahiro Yamada
2020-08-21 19:01 ` [PATCH v2 1/9] gen_compile_commands: parse only the first line of .*.cmd files Masahiro Yamada
2020-08-21 19:01 ` [PATCH v2 2/9] gen_compile_commands: use choices for --log_levels option Masahiro Yamada
2020-08-22 0:23 ` Nick Desaulniers
2020-08-21 19:01 ` [PATCH v2 3/9] gen_compile_commands: do not support .cmd files under tools/ directory Masahiro Yamada
2020-08-22 0:27 ` Nick Desaulniers [this message]
2020-08-21 19:01 ` [PATCH v2 4/9] gen_compile_commands: reword the help message of -d option Masahiro Yamada
2020-08-22 0:29 ` Nick Desaulniers
2020-08-22 1:55 ` Masahiro Yamada
2020-08-22 2:05 ` Nick Desaulniers
2020-08-21 19:01 ` [PATCH v2 5/9] gen_compile_commands: make -o option independent " Masahiro Yamada
2020-08-22 0:35 ` Nick Desaulniers
2020-08-21 19:01 ` [PATCH v2 6/9] gen_compile_commands: move directory walk to a generator function Masahiro Yamada
2020-08-22 0:41 ` Nick Desaulniers
2020-08-22 4:35 ` Masahiro Yamada
2020-08-21 19:01 ` [PATCH v2 7/9] gen_compile_commands: support *.o, *.a, modules.order in positional argument Masahiro Yamada
2020-08-22 0:59 ` Nick Desaulniers
2020-08-22 3:11 ` Masahiro Yamada
2020-08-21 19:01 ` [PATCH v2 8/9] kbuild: wire up the build rule of compile_commands.json to Makefile Masahiro Yamada
2020-08-22 0:45 ` Nick Desaulniers
2020-08-21 19:01 ` [PATCH v2 9/9] Makefile: Add clang-tidy and static analyzer support to makefile Masahiro Yamada
2020-08-22 1:06 ` [PATCH v2 0/9] kbuild: clang-tidy Nick Desaulniers
2020-08-22 1:12 ` Sedat Dilek
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='CAKwvOdn0VyObYvoBqoXPGT4o8LPSPsvc=pNpvVtu6jRxxhOKiA@mail.gmail.com' \
--to=ndesaulniers@google.com \
--cc=clang-built-linux@googlegroups.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masahiroy@kernel.org \
--cc=nhuck@google.com \
--cc=tmroeder@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;
as well as URLs for NNTP newsgroup(s).