mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 1/4] docs: kernel-doc: pass transforms when parsing export files
@ 2026-11-14  9:06 闲逛
  0 siblings, 0 replies; only message in thread
From: 闲逛 @ 2026-11-14  9:06 UTC (permalink / raw)
  To: corbet, mchehab; +Cc: wy, linux-doc, skhan, rdunlap, linux-kernel

From: yuehua-meng <2368492046@qq.com>

A separate -export-file reaches a KernelDoc constructor call that
does not pass the required xforms argument, raising TypeError.

Pass the configured transforms just as parse_file() does. Add a
regression with declarations in a header and an export in a
separate source file; only the exported declaration is emitted.

Fixes: d842057c4a20 ("docs: kdoc_parser: move transform lists to a separate file")

Signed-off-by: yuehua-meng <2368492046@qq.com>
---
Changes in v2:
Rebase onto docs-next. Place the parser fix and shared CLI helper
before the combined-export regression tests.

 tools/lib/python/kdoc/kdoc_files.py      |  2 +-
 tools/unittests/kdoc_cli_helper.py       | 34 ++++++++++++++++++++++++
 tools/unittests/test_kdoc_export_file.py | 19 +++++++++++++
 3 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 tools/unittests/kdoc_cli_helper.py
 create mode 100644 tools/unittests/test_kdoc_export_file.py

diff --git a/tools/lib/python/kdoc/kdoc_files.py b/tools/lib/python/kdoc/kdoc_files.py
index ed82b6e6a..d39b15edd 100644
--- a/tools/lib/python/kdoc/kdoc_files.py
+++ b/tools/lib/python/kdoc/kdoc_files.py
@@ -212,7 +212,7 @@ class KernelFiles():
         if fname in self.export_files:
             return
 
-        doc = KernelDoc(self.config, fname)
+        doc = KernelDoc(self.config, fname, self.xforms)
         export_table = doc.parse_export()
 
         if not export_table:
diff --git a/tools/unittests/kdoc_cli_helper.py b/tools/unittests/kdoc_cli_helper.py
new file mode 100644
index 000000000..e15b7f00e
--- /dev/null
+++ b/tools/unittests/kdoc_cli_helper.py
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: GPL-2.0
+"""Helpers for running kernel-doc against temporary source files."""
+
+import os
+from pathlib import Path
+import subprocess
+import sys
+import tempfile
+import unittest
+
+
+class KernelDocCliTest(unittest.TestCase):
+    def setUp(self):
+        temporary = tempfile.TemporaryDirectory()
+        self.addCleanup(temporary.cleanup)
+        self.directory = Path(temporary.name)
+        self.command = Path(__file__).resolve().parent.parent / "docs/kernel-doc"
+
+    def source(self, name, content):
+        path = self.directory / name
+        path.write_text(content, encoding="utf-8")
+        return path
+
+    def run_kdoc(self, *args, environment=None, no_site=False, cwd=None):
+        env = os.environ.copy()
+        for key in ("KCFLAGS", "KDOC_WERROR", "KBUILD_VERBOSE", "SRCTREE"):
+            env.pop(key, None)
+        env.update(environment or {})
+        command = [sys.executable, "-B"]
+        if no_site:
+            command.extend(["-I", "-S"])
+        command.extend([str(self.command), *map(str, args)])
+        return subprocess.run(command, env=env, cwd=cwd, capture_output=True,
+                              text=True, encoding="utf-8", timeout=30)
diff --git a/tools/unittests/test_kdoc_export_file.py b/tools/unittests/test_kdoc_export_file.py
new file mode 100644
index 000000000..9d2790780
--- /dev/null
+++ b/tools/unittests/test_kdoc_export_file.py
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: GPL-2.0
+"""Regression test for a separate kernel-doc export source file."""
+
+from kdoc_cli_helper import KernelDocCliTest
+
+
+class TestKernelDocExportFile(KernelDocCliTest):
+    def test_explicit_export_file(self):
+        source = self.source("example.h", (
+            "/**\n * alpha - internal function\n */\n"
+            "void alpha(void);\n"
+            "/**\n * beta - exported function\n */\n"
+            "void beta(void);\n"
+        ))
+        exports = self.source("exports.c", "EXPORT_SYMBOL(beta);\n")
+        result = self.run_kdoc("-export", "-export-file", exports, source)
+        self.assertEqual(result.returncode, 0, result.stderr)
+        self.assertNotIn("void alpha", result.stdout)
+        self.assertIn("void beta", result.stdout)
-- 
2.53.0.windows.2


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-14  9:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-14  9:06 [PATCH v2 1/4] docs: kernel-doc: pass transforms when parsing export files 闲逛

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

all inboxes | Powered by JetHome®