Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
* [PATCH] gen_compile_commands: use raw string when replacing \#
@ 2023-09-29 19:04 Jeremy Cline
  2023-10-02 23:07 ` Nathan Chancellor
  0 siblings, 1 reply; 2+ messages in thread
From: Jeremy Cline @ 2023-09-29 19:04 UTC (permalink / raw)
  To: Nathan Chancellor, Nick Desaulniers
  Cc: Tom Rix, llvm, linux-kernel, Jeremy Cline

I noticed this since I'm running Python 3.12-rc3, which emits
"SyntaxWarning: invalid escape sequence '\#'" when running this script.
According to the Python 3.12 release notes this will eventually become a
SyntaxError.

Based on the comment in the code, I believe the intention was to match
the literal string "\#". Marking it as a raw string will stop Python
from trying to treat it as an escape sequence and behave as intended.

Signed-off-by: Jeremy Cline <jeremy@jcline.org>
---
 scripts/clang-tools/gen_compile_commands.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/clang-tools/gen_compile_commands.py b/scripts/clang-tools/gen_compile_commands.py
index a84cc5737c2c..bc005cac1944 100755
--- a/scripts/clang-tools/gen_compile_commands.py
+++ b/scripts/clang-tools/gen_compile_commands.py
@@ -170,7 +170,7 @@ def process_line(root_directory, command_prefix, file_path):
     # 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)', '#')
 
     # Use os.path.abspath() to normalize the path resolving '.' and '..' .
     abs_path = os.path.abspath(os.path.join(root_directory, file_path))
-- 
2.41.0


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

* Re: [PATCH] gen_compile_commands: use raw string when replacing \#
  2023-09-29 19:04 [PATCH] gen_compile_commands: use raw string when replacing \# Jeremy Cline
@ 2023-10-02 23:07 ` Nathan Chancellor
  0 siblings, 0 replies; 2+ messages in thread
From: Nathan Chancellor @ 2023-10-02 23:07 UTC (permalink / raw)
  To: Jeremy Cline
  Cc: Nick Desaulniers, Tom Rix, llvm, linux-kernel, Masahiro Yamada,
	linux-kbuild

Hi Jeremy,

On Fri, Sep 29, 2023 at 03:04:46PM -0400, Jeremy Cline wrote:
> I noticed this since I'm running Python 3.12-rc3, which emits
> "SyntaxWarning: invalid escape sequence '\#'" when running this script.
> According to the Python 3.12 release notes this will eventually become a
> SyntaxError.
> 
> Based on the comment in the code, I believe the intention was to match
> the literal string "\#". Marking it as a raw string will stop Python
> from trying to treat it as an escape sequence and behave as intended.
> 
> Signed-off-by: Jeremy Cline <jeremy@jcline.org>

Thanks for the patch, it looks good to me.

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

Just a heads up, you are not the first person to see this and send a
patch:

https://lore.kernel.org/20230912060801.95533-5-bgray@linux.ibm.com/

But as far as I can tell, there is no movement on that changeset, so if
Masahiro is able to pick this up, that would still be good. Masahiro,
the original change is available at
https://lore.kernel.org/all/20230929190446.113168-1-jeremy@jcline.org/,
if you are able to apply it that way.

> ---
>  scripts/clang-tools/gen_compile_commands.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/scripts/clang-tools/gen_compile_commands.py b/scripts/clang-tools/gen_compile_commands.py
> index a84cc5737c2c..bc005cac1944 100755
> --- a/scripts/clang-tools/gen_compile_commands.py
> +++ b/scripts/clang-tools/gen_compile_commands.py
> @@ -170,7 +170,7 @@ def process_line(root_directory, command_prefix, file_path):
>      # 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)', '#')
>  
>      # Use os.path.abspath() to normalize the path resolving '.' and '..' .
>      abs_path = os.path.abspath(os.path.join(root_directory, file_path))
> -- 
> 2.41.0
> 

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

end of thread, other threads:[~2023-10-02 23:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-29 19:04 [PATCH] gen_compile_commands: use raw string when replacing \# Jeremy Cline
2023-10-02 23:07 ` Nathan Chancellor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox