diff mbox series

scripts: gen_compile_commands: fix invalid escape sequence warning

Message ID 20240503152000.2819669-1-caleb.connolly@linaro.org
State New
Headers show
Series scripts: gen_compile_commands: fix invalid escape sequence warning | expand

Commit Message

Caleb Connolly May 3, 2024, 3:18 p.m. UTC
Since Python 3.12 unrecognised escape sequences trigger a SyntaxWarning.
Convert the '\#' string to a raw string so the backslash is correctly
used as a literal.

Ported from Linux commit dae4a0171e25 ("gen_compile_commands: fix invalid
escape sequence warning").

This updates the script to be in-line with Linux 6.9-rc6.

Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
---
 scripts/gen_compile_commands.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

João Marcos Costa May 3, 2024, 4:03 p.m. UTC | #1
Hello,
thanks for this fix!

Em sex., 3 de mai. de 2024 às 15:20, Caleb Connolly <
caleb.connolly@linaro.org> escreveu:

> Since Python 3.12 unrecognised escape sequences trigger a SyntaxWarning.
> Convert the '\#' string to a raw string so the backslash is correctly
> used as a literal.
>
> Ported from Linux commit dae4a0171e25 ("gen_compile_commands: fix invalid
> escape sequence warning").
>
> This updates the script to be in-line with Linux 6.9-rc6.
>
> Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
> ---
>  scripts/gen_compile_commands.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/gen_compile_commands.py
> b/scripts/gen_compile_commands.py
> index fec513e55474..e746adddd929 100755
> --- a/scripts/gen_compile_commands.py
> +++ b/scripts/gen_compile_commands.py
> @@ -171,9 +171,9 @@ def process_line(root_directory, command_prefix,
> file_path):
>      # The .cmd files are intended to be included directly by Make, so they
>      # escape the pound sign '#', either as '\#' or '$(pound)' (depending
> on the
>      # kernel version). The compile_commands.json file is not interepreted
>      # by Make, so this code replaces the escaped version with '#'.
> -    prefix = command_prefix.replace('\#', '#').replace('$(pound)', '#')
> +    prefix = command_prefix.replace(r'\#', '#').replace('$(pound)', '#')
>
>      # 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):
> --
> 2.45.0
>
>
Reviewed-by: João Marcos Costa <jmcosta944@gmail.com>
Tom Rini May 14, 2024, 4:15 p.m. UTC | #2
On Fri, May 03, 2024 at 05:18:36PM +0200, Caleb Connolly wrote:

> Since Python 3.12 unrecognised escape sequences trigger a SyntaxWarning.
> Convert the '\#' string to a raw string so the backslash is correctly
> used as a literal.
> 
> Ported from Linux commit dae4a0171e25 ("gen_compile_commands: fix invalid
> escape sequence warning").
> 
> This updates the script to be in-line with Linux 6.9-rc6.
> 
> Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
> Reviewed-by: João Marcos Costa <jmcosta944@gmail.com>

Applied to u-boot/next, thanks!
diff mbox series

Patch

diff --git a/scripts/gen_compile_commands.py b/scripts/gen_compile_commands.py
index fec513e55474..e746adddd929 100755
--- a/scripts/gen_compile_commands.py
+++ b/scripts/gen_compile_commands.py
@@ -171,9 +171,9 @@  def process_line(root_directory, command_prefix, file_path):
     # The .cmd files are intended to be included directly by Make, so they
     # escape the pound sign '#', either as '\#' or '$(pound)' (depending on the
     # kernel version). The compile_commands.json file is not interepreted
     # by Make, so this code replaces the escaped version with '#'.
-    prefix = command_prefix.replace('\#', '#').replace('$(pound)', '#')
+    prefix = command_prefix.replace(r'\#', '#').replace('$(pound)', '#')
 
     # 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):