scripts/kernel-doc.py: properly handle KBUILD_BUILD_TIMESTAMP

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>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/ffc70a1b741b010365ed82f31611018f24f91ce7.1744106242.git.mchehab+huawei@kernel.org
This commit is contained in:
Mauro Carvalho Chehab
2025-04-08 18:09:29 +08:00
committed by Jonathan Corbet
parent 2ab867a494
commit 91d00bd54f
2 changed files with 21 additions and 16 deletions

View File

@@ -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")