[libc-commits] [libc] [libc][docs] Generate docs for signal.h & optimized is_implemented func (PR #88028)

Xu Zhang via libc-commits libc-commits at lists.llvm.org
Mon Apr 8 18:50:59 PDT 2024


https://github.com/simonzgx updated https://github.com/llvm/llvm-project/pull/88028

>From 185d820c3b5339ff812a8aa9dcd43e61dc66c12b Mon Sep 17 00:00:00 2001
From: Xu Zhang <simonzgx at gmail.com>
Date: Tue, 9 Apr 2024 03:25:38 +0800
Subject: [PATCH 1/3] [libc][docs] Generate docs for signal.h & optimized
 docgen.py's is_implemented func. (#87835)

---
 libc/docs/signal.rst          | 41 +++++++++++++++++++++++++++++++++++
 libc/utils/docgen/docgen.py   | 17 +++++++++++----
 libc/utils/docgen/signal.json | 29 +++++++++++++++++++++++++
 3 files changed, 83 insertions(+), 4 deletions(-)
 create mode 100644 libc/docs/signal.rst
 create mode 100644 libc/utils/docgen/signal.json

diff --git a/libc/docs/signal.rst b/libc/docs/signal.rst
new file mode 100644
index 00000000000000..a994645ce3c260
--- /dev/null
+++ b/libc/docs/signal.rst
@@ -0,0 +1,41 @@
+signal.h Functions
+==================
+
+.. list-table::
+  :widths: auto
+  :align: center
+  :header-rows: 1
+
+  * - Function
+    - Implemented
+    - Standard
+  * - kill
+    - |check|
+    -
+  * - raise
+    - |check|
+    - 7.14.2.1
+  * - sigaction
+    - |check|
+    -
+  * - sigaddset
+    - |check|
+    -
+  * - sigaltstack
+    - |check|
+    -
+  * - sigdelset
+    - |check|
+    -
+  * - sigemptyset
+    - |check|
+    -
+  * - sigfillset
+    - |check|
+    -
+  * - signal
+    - |check|
+    - 7.14.1.1
+  * - sigprocmask
+    - |check|
+    -
diff --git a/libc/utils/docgen/docgen.py b/libc/utils/docgen/docgen.py
index 7411b4506f082f..213ed7e6cc5ec8 100755
--- a/libc/utils/docgen/docgen.py
+++ b/libc/utils/docgen/docgen.py
@@ -23,12 +23,21 @@ def load_api(hname: str) -> Dict:
 # TODO: we may need to get more sophisticated for less generic implementations.
 # Does libc/src/{hname minus .h suffix}/{fname}.cpp exist?
 def is_implemented(hname: str, fname: str) -> bool:
-    return Path(
+    path = Path(
         Path(__file__).parent.parent.parent,
         "src",
-        hname.rstrip(".h"),
-        fname + ".cpp",
-    ).exists()
+        hname.rstrip(".h")
+    )
+    source_file_name = fname + ".cpp"
+    if path.joinpath(source_file_name).exists():
+        return True
+    
+    # Attempt to search in the subfolders with 1-depth.
+    for sub_dir in path.iterdir():
+        if (sub_dir.joinpath(source_file_name)).exists():
+            return True
+
+    return False
 
 
 def print_functions(header: str, functions: Dict):
diff --git a/libc/utils/docgen/signal.json b/libc/utils/docgen/signal.json
new file mode 100644
index 00000000000000..d7e73fc29fcd56
--- /dev/null
+++ b/libc/utils/docgen/signal.json
@@ -0,0 +1,29 @@
+{
+  "macros": [
+    "SIG_DFL",
+    "SIG_ERR",
+    "SIG_IGN",
+    "SIGABRT",
+    "SIGFPE",
+    "SIGILL",
+    "SIGINT",
+    "SIGSEGV",
+    "SIGTERM"
+  ],
+  "functions": {
+    "kill": null,
+    "sigaction": null,
+    "sigaddset": null,
+    "sigaltstack": null,
+    "sigdelset": null,
+    "sigemptyset": null,
+    "sigfillset": null,
+    "sigprocmask": null,
+    "signal": {
+      "defined": "7.14.1.1"
+    },
+    "raise": {
+      "defined": "7.14.2.1"
+    }
+  }
+}
\ No newline at end of file

>From 08d94803d5ad4ad7801a726c73e452b39f54492c Mon Sep 17 00:00:00 2001
From: Xu Zhang <simonzgx at gmail.com>
Date: Tue, 9 Apr 2024 03:46:40 +0800
Subject: [PATCH 2/3] [libc][docs] Generate docs for signal.h & optimized
 docgen.py's is_implemented func. (#87835)

---
 libc/utils/docgen/docgen.py | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/libc/utils/docgen/docgen.py b/libc/utils/docgen/docgen.py
index 213ed7e6cc5ec8..20edadf7621ca5 100755
--- a/libc/utils/docgen/docgen.py
+++ b/libc/utils/docgen/docgen.py
@@ -29,12 +29,10 @@ def is_implemented(hname: str, fname: str) -> bool:
         hname.rstrip(".h")
     )
     source_file_name = fname + ".cpp"
-    if path.joinpath(source_file_name).exists():
-        return True
-    
-    # Attempt to search in the subfolders with 1-depth.
-    for sub_dir in path.iterdir():
-        if (sub_dir.joinpath(source_file_name)).exists():
+    # Recursively search for the target source file in the subdirectories under
+    # libc/src/{hname}.
+    for sub_dir in path.glob("**"):
+        if sub_dir.joinpath(source_file_name).exists():
             return True
 
     return False

>From d02a2a8dfc1f5b52456230445a4bbd6e75dde436 Mon Sep 17 00:00:00 2001
From: Xu Zhang <simonzgx at gmail.com>
Date: Tue, 9 Apr 2024 09:50:41 +0800
Subject: [PATCH 3/3] fix missing include in signal.rst and amend
 is_implemented func

---
 libc/docs/signal.rst          |  2 ++
 libc/utils/docgen/docgen.py   | 10 ++++++----
 libc/utils/docgen/signal.json |  2 +-
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/libc/docs/signal.rst b/libc/docs/signal.rst
index a994645ce3c260..7903bb439cb337 100644
--- a/libc/docs/signal.rst
+++ b/libc/docs/signal.rst
@@ -1,3 +1,5 @@
+.. include:: check.rst
+
 signal.h Functions
 ==================
 
diff --git a/libc/utils/docgen/docgen.py b/libc/utils/docgen/docgen.py
index 20edadf7621ca5..bd916b04f04725 100755
--- a/libc/utils/docgen/docgen.py
+++ b/libc/utils/docgen/docgen.py
@@ -1,3 +1,7 @@
+'''
+Copyright (c) 2024 by Tencent Inc, All Rights Reserved. 
+Author: Xu Zhang <simonzgx at gmail.com> simonzgx at gmail.com
+'''
 #!/usr/bin/env python
 #
 # ====- Generate documentation for libc functions  ------------*- python -*--==#
@@ -28,12 +32,10 @@ def is_implemented(hname: str, fname: str) -> bool:
         "src",
         hname.rstrip(".h")
     )
-    source_file_name = fname + ".cpp"
     # Recursively search for the target source file in the subdirectories under
     # libc/src/{hname}.
-    for sub_dir in path.glob("**"):
-        if sub_dir.joinpath(source_file_name).exists():
-            return True
+    for _ in path.glob("**/" + fname + ".cpp"):
+        return True
 
     return False
 
diff --git a/libc/utils/docgen/signal.json b/libc/utils/docgen/signal.json
index d7e73fc29fcd56..976021a803a672 100644
--- a/libc/utils/docgen/signal.json
+++ b/libc/utils/docgen/signal.json
@@ -26,4 +26,4 @@
       "defined": "7.14.2.1"
     }
   }
-}
\ No newline at end of file
+}



More information about the libc-commits mailing list