[PATCH v3 26/33] scripts/kernel-doc.py: properly handle KBUILD_BUILD_TIMESTAMP

Mauro Carvalho Chehab
2025-04-08T10:09:56Z

The logic that handles KBUILD_BUILD_TIMESTAMP is wrong, and adds
a dependency of a third party module (dateutil).

Fix it.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
scripts/lib/kdoc/kdoc_files.py | 9 ---------
scripts/lib/kdoc/kdoc_output.py | 28 +++++++++++++++++++++-------
2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/scripts/lib/kdoc/kdoc_files.py b/scripts/lib/kdoc/kdoc_files.py
index 5a6e92e34d05..e52a6d05237e 100644
--- a/scripts/lib/kdoc/kdoc_files.py
+++ b/scripts/lib/kdoc/kdoc_files.py
@@ -13,9 +13,6 @@ import logging
import os
import re
import sys
-from datetime import datetime
-
-from dateutil import tz

from kdoc_parser import KernelDoc
from kdoc_output import OutputFormat
@@ -137,12 +134,6 @@ class KernelFiles():
if out_style is None:
out_style = OutputFormat()

- dt = datetime.now()
- if os.environ.get("KBUILD_BUILD_TIMESTAMP", None):
- # use UTC TZ
- to_zone = tz.gettz('UTC')
- dt = dt.astimezone(to_zone)
-
if not werror:
kcflags = os.environ.get("KCFLAGS", None)
if kcflags:
diff --git a/scripts/lib/kdoc/kdoc_output.py b/scripts/lib/kdoc/kdoc_output.py
index 8be69245c0d0..eb013075da84 100755
--- a/scripts/lib/kdoc/kdoc_output.py
+++ b/scripts/lib/kdoc/kdoc_output.py
@@ -19,8 +19,6 @@ import os
import re
from datetime import datetime

-from dateutil import tz
-
from kdoc_parser import KernelDoc, type_param
from kdoc_re import Re

@@ -586,6 +584,15 @@ class ManFormat(OutputFormat):
)
blankline = ""

+ date_formats = [
+ "%a %b %d %H:%M:%S %Z %Y",
+ "%a %b %d %H:%M:%S %Y",
+ "%Y-%m-%d",
+ "%b %d %Y",
+ "%B %d %Y",
+ "%m %d %Y",
+ ]
+
def __init__(self, modulename):
"""
Creates class variables.
@@ -597,11 +604,18 @@ class ManFormat(OutputFormat):
super().__init__()
self.modulename = modulename

- dt = datetime.now()
- if os.environ.get("KBUILD_BUILD_TIMESTAMP", None):
- # use UTC TZ
- to_zone = tz.gettz('UTC')
- dt = dt.astimezone(to_zone)
+ dt = None
+ tstamp = os.environ.get("KBUILD_BUILD_TIMESTAMP")
+ if tstamp:
+ for fmt in self.date_formats:
+ try:
+ dt = datetime.strptime(tstamp, fmt)
+ break
+ except ValueError:
+ pass
+
+ if not dt:
+ dt = datetime.now()

self.man_date = dt.strftime("%B %Y")

--
2.49.0