[clang] [include-mapping] Python fixes (PR #65401)

via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 11 15:31:20 PDT 2023


llvmbot wrote:

@llvm/pr-subscribers-clang

<details>
<summary>Changes</summary>

I had to regenerate the include mapping while resolving a downstream merge conflict, and ran into two issue on my machine. These shouldn't change anything, just make things work on my config.

- Move the `multiprocessing.Pool` initializer to a top-level function, it was previously causing a pickle failure with my machine's python, specifically complaining about having to pickle the lambda or a local function. Works fine with a top-level function.
- Change the `env python` to `env python3` for convenience. The interpreter is installed as python3 on macOS.

It looks like about 2/3 of the scripts in `clang/tools/` are using `env python3` over `env python` so the latter seems a reasonable change to make.
--
Full diff: https://github.com/llvm/llvm-project/pull/65401.diff

2 Files Affected:

- (modified) clang/tools/include-mapping/cppreference_parser.py (+6-4) 
- (modified) clang/tools/include-mapping/gen_std.py (+1-1) 


<pre>
diff --git a/clang/tools/include-mapping/cppreference_parser.py b/clang/tools/include-mapping/cppreference_parser.py
index cefdbeaf334e1c4..f2ea55384fac80c 100644
--- a/clang/tools/include-mapping/cppreference_parser.py
+++ b/clang/tools/include-mapping/cppreference_parser.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # ===- cppreference_parser.py -  ------------------------------*- python -*--===#
 #
 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -176,6 +176,10 @@ def _GetSymbols(pool, root_dir, index_page_name, namespace, variants_to_accept):
     return symbols
 
 
+def signal_ignore_initializer():
+    return signal.signal(signal.SIGINT, signal.SIG_IGN)
+
+
 def GetSymbols(parse_pages):
     """Get all symbols by parsing the given pages.
 
@@ -192,9 +196,7 @@ def GetSymbols(parse_pages):
     symbols = []
     # Run many workers to process individual symbol pages under the symbol index.
     # Don't allow workers to capture Ctrl-C.
-    pool = multiprocessing.Pool(
-        initializer=lambda: signal.signal(signal.SIGINT, signal.SIG_IGN)
-    )
+    pool = multiprocessing.Pool(initializer=signal_ignore_initializer)
     try:
         for root_dir, page_name, namespace in parse_pages:
             symbols.extend(
diff --git a/clang/tools/include-mapping/gen_std.py b/clang/tools/include-mapping/gen_std.py
index 57a5a6772ba894a..fcd3bd0d843ea16 100755
--- a/clang/tools/include-mapping/gen_std.py
+++ b/clang/tools/include-mapping/gen_std.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # ===- gen_std.py -  ------------------------------------------*- python -*--===#
 #
 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
</pre>

</details>

https://github.com/llvm/llvm-project/pull/65401


More information about the cfe-commits mailing list