Skip to contentSkip to conversation

gen_compile_commands: add missing sys import

PATCH In review [email protected] 3 participants 4 messages Sep 14, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gen_compile_commands: add missing sys import

From: Andreas Rammhold <[email protected]>

The sys.exit was being used at multiple locations within the script but never imported. This lead to the script exiting with a error instead of with the nicely formatted (useful) error output.

---
 scripts/clang-tools/gen_compile_commands.py | 1 +
 1 file changed, 1 insertion(+)
scripts/clang-tools/gen_compile_commands.py +1 -0
index 0033eedce003e..1d1bde1fd45eb 100755
@@ -13,6 +13,7 @@ import logging
 import os
 import re
 import subprocess
+import sys
 
 _DEFAULT_OUTPUT = 'compile_commands.json'
 _DEFAULT_LOG_LEVEL = 'WARNING'
Signature · 1 line
2.32.0
#1 lore raw

Hi Andreas,

Quoted 17 lines · On 9/14/2021 8:44 AM, [email protected] wrote:

From: Andreas Rammhold <[email protected]>

The sys.exit was being used at multiple locations within the script but never imported. This lead to the script exiting with a error instead of with the nicely formatted (useful) error output.

---
  scripts/clang-tools/gen_compile_commands.py | 1 +
  1 file changed, 1 insertion(+)
scripts/clang-tools/gen_compile_commands.py +0 -0
index 0033eedce003e..1d1bde1fd45eb 100755

scripts/clang-tools/gen_compile_commands.py import logging · line 19

Quoted 7 lines
scripts/clang-tools/gen_compile_commands.py +1 -0
@@ -13,6 +13,7 @@ import logging
  import os
  import re
  import subprocess
+import sys
 
  _DEFAULT_OUTPUT = 'compile_commands.json'
  _DEFAULT_LOG_LEVEL = 'WARNING'

Thank you for the patch! Someone else submitted the exact same fix and it is now pending in the kbuild tree:

https://git.kernel.org/masahiroy/linux-kbuild/c/776f04ca2c29f13d483a3effc0c27404fe901143

I am curious, how did you discover this? Did you hit one of those error paths?

Cheers,
Nathan

#2 lore raw
Quoted 30 lines · Nathan Chancellor

Hi Andreas,

Quoted 16 lines · On 9/14/2021 8:44 AM, [email protected] wrote:

From: Andreas Rammhold <[email protected]>

The sys.exit was being used at multiple locations within the script but never imported. This lead to the script exiting with a error instead of with the nicely formatted (useful) error output.

---
  scripts/clang-tools/gen_compile_commands.py | 1 +
  1 file changed, 1 insertion(+)
scripts/clang-tools/gen_compile_commands.py +0 -0
index 0033eedce003e..1d1bde1fd45eb 100755

scripts/clang-tools/gen_compile_commands.py import logging · line 19

Quoted 7 lines
scripts/clang-tools/gen_compile_commands.py +1 -0
@@ -13,6 +13,7 @@ import logging
  import os
  import re
  import subprocess
+import sys
  _DEFAULT_OUTPUT = 'compile_commands.json'
  _DEFAULT_LOG_LEVEL = 'WARNING'
 

Thank you for the patch! Someone else submitted the exact same fix and it is now pending in the kbuild tree:

Quoted 1 line

https://git.kernel.org/masahiroy/linux-kbuild/c/776f04ca2c29f13d483a3effc0c27404fe901143

Oh! I should have send the patch when I originally comitted it.. Good that it is fixed now. :-)

Quoted 2 lines

I am curious, how did you discover this? Did you hit one of those error paths?

I can't recall the exact story anymore. I was looking into why the keyring didn't offer the TPM backend on my new device. I did a fresh checkout of the source tree on the device and set out to get clangd working in the source tree with my neovim.

At first I tried to call the script without compiling the kernel. That failed with some obvious error.

It could have been that I ended up in one of the error paths. Naturally I digged into how this whole machinery works and that lead to opening the file. Neovim, being setup for Python development, showed me that there was an undefined symbol / missing import. I verified that and then added the import.

As far as I can remeber I did end up compiling the kernel and/or then running make compile_commands.json. Ever since then it just worked!

Thank you for working on this! :-)

#3 lore raw
In reply to [email protected]
Quoted 8 lines · On Tue, Sep 14, 2021 at 8:44 AM <[email protected]> wrote:

From: Andreas Rammhold <[email protected]>

The sys.exit was being used at multiple locations within the script but never imported. This lead to the script exiting with a error instead of with the nicely formatted (useful) error output.

Hi Andreas,
Thanks for the patch. Someone beat you to the punch though:
https://lore.kernel.org/lkml/[email protected]/.

This is good; it means folks are playing with this. :)

Quoted 19 lines
---
 scripts/clang-tools/gen_compile_commands.py | 1 +
 1 file changed, 1 insertion(+)
scripts/clang-tools/gen_compile_commands.py +1 -1
index 0033eedce003e..1d1bde1fd45eb 100755
@@ -13,6 +13,7 @@ import logging
 import os
 import re
 import subprocess
+import sys
 
 _DEFAULT_OUTPUT = 'compile_commands.json'
 _DEFAULT_LOG_LEVEL = 'WARNING'
--

2.32.0

Signature · 2 lines
Thanks,
~Nick Desaulniers