All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scripts/gen_compile_commands: update to Linux v6.7
@ 2024-01-22 18:45 Brandon Maier
  2024-02-07 15:44 ` Tom Rini
  0 siblings, 1 reply; 2+ messages in thread
From: Brandon Maier @ 2024-01-22 18:45 UTC (permalink / raw)
  To: u-boot; +Cc: Brandon Maier, Joao Marcos Costa, Tom Rini

Adds support for assembly files and updates the LINE_PATTERN so it
supports both "cmd" and "savedcmd", which allows reverting the U-Boot
modification in commit 97fbb2eb016b ("scripts/gen_compile_commands.py:
adapt _LINE_PATTERN").

Upstream commits:

- 880946158b011 gen_compile_commands.py: fix path resolve with symlinks in it
- 9e56d3be4bfd2 gen_compile_commands: Sort output compile commands by file name
- 52c15e7e79285 gen_compile_commands: Allow the line prefix to still be cmd_
- 1c67921444bf6 gen_compile_commands: add assembly files to compilation database

Signed-off-by: Brandon Maier <brandon.maier@collins.com>
Cc: Joao Marcos Costa <jmcosta944@gmail.com>
---

 scripts/gen_compile_commands.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/scripts/gen_compile_commands.py b/scripts/gen_compile_commands.py
index cdca85e6b07..fec513e5547 100755
--- a/scripts/gen_compile_commands.py
+++ b/scripts/gen_compile_commands.py
@@ -21,7 +21,7 @@ _DEFAULT_OUTPUT = 'compile_commands.json'
 _DEFAULT_LOG_LEVEL = 'WARNING'

 _FILENAME_PATTERN = r'^\..*\.cmd$'
-_LINE_PATTERN = r'^cmd_[^ ]*\.o := (.* )([^ ]*\.c) *(;|$)'
+_LINE_PATTERN = r'^(saved)?cmd_[^ ]*\.o := (?P<command_prefix>.* )(?P<file_path>[^ ]*\.[cS]) *(;|$)'
 _VALID_LOG_LEVELS = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
 # The tools/ directory adopts a different build system, and produces .cmd
 # files in a different format. Do not support it.
@@ -66,7 +66,7 @@ def parse_arguments():
     args = parser.parse_args()

     return (args.log_level,
-            os.path.abspath(args.directory),
+            os.path.realpath(args.directory),
             args.output,
             args.ar,
             args.paths if len(args.paths) > 0 else [args.directory])
@@ -174,8 +174,8 @@ def process_line(root_directory, command_prefix, file_path):
     # by Make, so this code replaces the escaped version with '#'.
     prefix = command_prefix.replace('\#', '#').replace('$(pound)', '#')

-    # Use os.path.abspath() to normalize the path resolving '.' and '..' .
-    abs_path = os.path.abspath(os.path.join(root_directory, file_path))
+    # Return the canonical path, eliminating any symbolic links encountered in the path.
+    abs_path = os.path.realpath(os.path.join(root_directory, file_path))
     if not os.path.exists(abs_path):
         raise ValueError('File %s not found' % abs_path)
     return {
@@ -215,15 +215,15 @@ def main():
                 result = line_matcher.match(f.readline())
                 if result:
                     try:
-                        entry = process_line(directory, result.group(1),
-                                             result.group(2))
+                        entry = process_line(directory, result.group('command_prefix'),
+                                             result.group('file_path'))
                         compile_commands.append(entry)
                     except ValueError as err:
                         logging.info('Could not add line from %s: %s',
                                      cmdfile, err)

     with open(output, 'wt') as f:
-        json.dump(compile_commands, f, indent=2, sort_keys=True)
+        json.dump(sorted(compile_commands, key=lambda x: x["file"]), f, indent=2, sort_keys=True)


 if __name__ == '__main__':
--
2.43.0

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

* Re: [PATCH] scripts/gen_compile_commands: update to Linux v6.7
  2024-01-22 18:45 [PATCH] scripts/gen_compile_commands: update to Linux v6.7 Brandon Maier
@ 2024-02-07 15:44 ` Tom Rini
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Rini @ 2024-02-07 15:44 UTC (permalink / raw)
  To: Brandon Maier; +Cc: u-boot, Joao Marcos Costa

[-- Attachment #1: Type: text/plain, Size: 827 bytes --]

On Mon, Jan 22, 2024 at 06:45:50PM +0000, Brandon Maier wrote:

> Adds support for assembly files and updates the LINE_PATTERN so it
> supports both "cmd" and "savedcmd", which allows reverting the U-Boot
> modification in commit 97fbb2eb016b ("scripts/gen_compile_commands.py:
> adapt _LINE_PATTERN").
> 
> Upstream commits:
> 
> - 880946158b011 gen_compile_commands.py: fix path resolve with symlinks in it
> - 9e56d3be4bfd2 gen_compile_commands: Sort output compile commands by file name
> - 52c15e7e79285 gen_compile_commands: Allow the line prefix to still be cmd_
> - 1c67921444bf6 gen_compile_commands: add assembly files to compilation database
> 
> Signed-off-by: Brandon Maier <brandon.maier@collins.com>
> Cc: Joao Marcos Costa <jmcosta944@gmail.com>

Applied to u-boot/master, thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

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

end of thread, other threads:[~2024-02-07 15:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-22 18:45 [PATCH] scripts/gen_compile_commands: update to Linux v6.7 Brandon Maier
2024-02-07 15:44 ` Tom Rini

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.