All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] gen_compile_command: Add support for separate KBUILD_OUTPUT directory
@ 2019-06-24 16:31 Matthias Kaehlcke
  2019-07-04  5:08 ` Masahiro Yamada
  0 siblings, 1 reply; 3+ messages in thread
From: Matthias Kaehlcke @ 2019-06-24 16:31 UTC (permalink / raw)
  To: Tom Roeder, Masahiro Yamada
  Cc: linux-kernel, Raul E Rangel, Nick Desaulniers, Tom Hughes,
	Douglas Anderson, Ryan Case, Yu Liu, Nathan Chancellor,
	Matthias Kaehlcke

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 this the kbuild output directory. If the
option is not set the kernel source directory is used.

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
Reviewed-by: Tom Roeder <tmroeder@google.com>
Tested-by: Tom Roeder <tmroeder@google.com>
Acked-by: Nick Desaulniers <ndesaulniers@google.com>
---
Changes in v2:
- added trailing space to help strings
- added tags from Tom and Nick
---
 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..47f37db6bd3a 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] gen_compile_command: Add support for separate KBUILD_OUTPUT directory
  2019-06-24 16:31 [PATCH v2] gen_compile_command: Add support for separate KBUILD_OUTPUT directory Matthias Kaehlcke
@ 2019-07-04  5:08 ` Masahiro Yamada
  2019-07-10 22:01   ` Matthias Kaehlcke
  0 siblings, 1 reply; 3+ messages in thread
From: Masahiro Yamada @ 2019-07-04  5:08 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Tom Roeder, Linux Kernel Mailing List, Raul E Rangel,
	Nick Desaulniers, Tom Hughes, Douglas Anderson, Ryan Case,
	Yu Liu, Nathan Chancellor

On Tue, Jun 25, 2019 at 1:31 AM Matthias Kaehlcke <mka@chromium.org> wrote:
>
> 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 this the kbuild output directory. If the
> option is not set the kernel source directory is used.

I do not understand this patch.

In my understanding, this tool already provides
-d, --directory option, which is supposed to point to
the kbuild output directory, not a source directory.


This works except under tools/.



> -                        entry = process_line(directory, dirpath,
> +                        entry = process_line(source_directory, dirpath,
>                                               result.group(1), result.group(2))

This is wrong.

result.group(2) returns the relative path to the output tree
instead of the source tree.
(or absolute path).


[Example of breakage]

$ make -j8 O=foo defconfig all
$ scripts/gen_compile_commands.py  -d .  -k foo
WARNING: Found 0 entries. Have you compiled the kernel?






-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] gen_compile_command: Add support for separate KBUILD_OUTPUT directory
  2019-07-04  5:08 ` Masahiro Yamada
@ 2019-07-10 22:01   ` Matthias Kaehlcke
  0 siblings, 0 replies; 3+ messages in thread
From: Matthias Kaehlcke @ 2019-07-10 22:01 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Tom Roeder, Linux Kernel Mailing List, Raul E Rangel,
	Nick Desaulniers, Tom Hughes, Douglas Anderson, Ryan Case,
	Yu Liu, Nathan Chancellor

On Thu, Jul 04, 2019 at 02:08:27PM +0900, Masahiro Yamada wrote:
> On Tue, Jun 25, 2019 at 1:31 AM Matthias Kaehlcke <mka@chromium.org> wrote:
> >
> > 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 this the kbuild output directory. If the
> > option is not set the kernel source directory is used.
> 
> I do not understand this patch.
> 
> In my understanding, this tool already provides
> -d, --directory option, which is supposed to point to
> the kbuild output directory, not a source directory.

You are right specifying the output path with -d works.

The help string claims the directory passed to -d is the kernel
*source* directory though:

    -d DIRECTORY, --directory DIRECTORY
                        Path to the kernel source directory to search
                        (defaults to the working directory)

I recall getting plenty of errors of files not being found (possibly
after adding debug logs). Chrome OS builds the kernel inside a chroot,
I guess I ran the script from outside the chroot and got the errors
because the (chroot) file paths in the .cmd files don't exist outside
the chroot, but drew wrong conclusions.

Please disregard this patch.

Matthias

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-07-10 22:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-24 16:31 [PATCH v2] gen_compile_command: Add support for separate KBUILD_OUTPUT directory Matthias Kaehlcke
2019-07-04  5:08 ` Masahiro Yamada
2019-07-10 22:01   ` Matthias Kaehlcke

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.