From nobody Wed Oct 1 21:27:58 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A6AC2E54DE; Wed, 1 Oct 2025 14:49:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759330199; cv=none; b=u3lbz6Ke6k9S6CPNz5lmZjB5izDqfi++fltYbJvjPQS/2enzbn6Q7FykefcvMmqgJu55qNvUWcv1OC4t5jScjGfuUY/fgDQa38uESiKc0wwDIpQbyVXNCbiaBSALr3Gn8CEqzigp1U1sIe4zhRhK4xUfUgrSokWhJRNR9RRlp1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759330199; c=relaxed/simple; bh=3CTScuwxC9ZYFhvKDygUTwinDqi3MU7C1ktyjxp78ZU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g0H3kbiGArCxvL6gqGXrto52KV6RsbkucwGvKMlDvkYDrXUxzLpr9DUup2MCe/wFkOoyJOfelXI81Ef712VeHohJMeGaIg2Ku/hrRfzvp/hEIn9yR4P5KxlM1OzWpEbTKG8tVfMANp/SffyAfQKXsx17/nTenJlX5/LbnMLnTgo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cGx6QR84; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cGx6QR84" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01FABC4CEFA; Wed, 1 Oct 2025 14:49:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1759330199; bh=3CTScuwxC9ZYFhvKDygUTwinDqi3MU7C1ktyjxp78ZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cGx6QR846NsCLlOPyb53nZiJLHRWcoYy+OtbF50kSnwmLr+Q1R4gmKtqhqVkXRl2F kcljejHtbGFUjAmSLE9o/FaKuXl5YlzDpOmNOypCktZCtOrCy7zs4B0QUbUC6lnSCm G1yC3hLO8G4SyJ4d4TIee0yjoNQNolhUcHjXMYVqLdtKSD/TUYUgXBb+29NzhzlY/a pWH/nr/OKcyRhM4EZ9ylewbmEmJ11wca6z3Kj82slzz5m8IbfTfDypwvhz6L5u2TZP v9mfZQk3FyCJSf7OGknzMS55DOMr237gMTZHb4vzxDWHcuwJT54wygDDXrCbCmtvHc H4pq0bWitWY+Q== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1v3y9V-0000000BLIJ-14t7; Wed, 01 Oct 2025 16:49:57 +0200 From: Mauro Carvalho Chehab To: "Jonathan Corbet" , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH 05/23] tools: docs: parse_data_structs: make process_exceptions two stages Date: Wed, 1 Oct 2025 16:49:28 +0200 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Mauro Carvalho Chehab Content-Type: text/plain; charset="utf-8" Split the logic which parses exceptions on two stages, preparing the exceptions file to have rules that will affect xref generation. For now, preserve the original API. Signed-off-by: Mauro Carvalho Chehab --- tools/docs/lib/parse_data_structs.py | 125 +++++++++++++++------------ 1 file changed, 71 insertions(+), 54 deletions(-) diff --git a/tools/docs/lib/parse_data_structs.py b/tools/docs/lib/parse_da= ta_structs.py index 9ad621712103..46535a05ea4a 100755 --- a/tools/docs/lib/parse_data_structs.py +++ b/tools/docs/lib/parse_data_structs.py @@ -140,9 +140,41 @@ class ParseDataStructs: =20 self.symbols =3D {} =20 + self.ignore =3D [] + self.replace =3D [] + for symbol_type in self.DEF_SYMBOL_TYPES: self.symbols[symbol_type] =3D {} =20 + def read_exceptions(self, fname: str): + if not fname: + return + + name =3D os.path.basename(fname) + + with open(fname, "r", encoding=3D"utf-8", errors=3D"backslashrepla= ce") as f: + for ln, line in enumerate(f): + ln +=3D 1 + line =3D line.strip() + if not line or line.startswith("#"): + continue + + # ignore rules + match =3D re.match(r"^ignore\s+(\w+)\s+(\S+)", line) + + if match: + self.ignore.append((ln, match.group(1), match.group(2)= )) + continue + + # replace rules + match =3D re.match(r"^replace\s+(\S+)\s+(\S+)\s+(\S+)", li= ne) + if match: + self.replace.append((ln, match.group(1), match.group(2= ), + match.group(3))) + continue + + sys.exit(f"{name}:{ln}: invalid line: {line}") + def store_type(self, ln, symbol_type: str, symbol: str, ref_name: str =3D None, replace_underscores: bool =3D T= rue): """ @@ -277,75 +309,60 @@ class ParseDataStructs: self.store_type(line_no, "struct", match.group(1)) break =20 - def process_exceptions(self, fname: str): + def apply_exceptions(self): """ Process exceptions file with rules to ignore or replace references. """ - if not fname: - return =20 - name =3D os.path.basename(fname) + # Handle ignore rules + for ln, c_type, symbol in self.ignore: + if c_type not in self.DEF_SYMBOL_TYPES: + sys.exit(f"{name}:{ln}: {c_type} is invalid") =20 - with open(fname, "r", encoding=3D"utf-8", errors=3D"backslashrepla= ce") as f: - for ln, line in enumerate(f): - ln +=3D 1 - line =3D line.strip() - if not line or line.startswith("#"): - continue + d =3D self.symbols[c_type] + if symbol in d: + del d[symbol] =20 - # Handle ignore rules - match =3D re.match(r"^ignore\s+(\w+)\s+(\S+)", line) - if match: - c_type =3D match.group(1) - symbol =3D match.group(2) - - if c_type not in self.DEF_SYMBOL_TYPES: - sys.exit(f"{name}:{ln}: {c_type} is invalid") - - d =3D self.symbols[c_type] - if symbol in d: - del d[symbol] - - continue - - # Handle replace rules - match =3D re.match(r"^replace\s+(\S+)\s+(\S+)\s+(\S+)", li= ne) - if not match: - sys.exit(f"{name}:{ln}: invalid line: {line}") - - c_type, old, new =3D match.groups() - - if c_type not in self.DEF_SYMBOL_TYPES: - sys.exit(f"{name}:{ln}: {c_type} is invalid") + # Handle replace rules + for ln, c_type, old, new in self.replace: + if c_type not in self.DEF_SYMBOL_TYPES: + sys.exit(f"{name}:{ln}: {c_type} is invalid") =20 - reftype =3D None + reftype =3D None =20 - # Parse reference type when the type is specified + # Parse reference type when the type is specified =20 - match =3D re.match(r"^\:c\:(data|func|macro|type)\:\`(.+)\= `", new) + match =3D re.match(r"^\:c\:(data|func|macro|type)\:\`(.+)\`", = new) + if match: + reftype =3D f":c:{match.group(1)}" + new =3D match.group(2) + else: + match =3D re.search(r"(\:ref)\:\`(.+)\`", new) if match: - reftype =3D f":c:{match.group(1)}" + reftype =3D match.group(1) new =3D match.group(2) - else: - match =3D re.search(r"(\:ref)\:\`(.+)\`", new) - if match: - reftype =3D match.group(1) - new =3D match.group(2) =20 - # If the replacement rule doesn't have a type, get default + # If the replacement rule doesn't have a type, get default + if not reftype: + reftype =3D self.DEF_SYMBOL_TYPES[c_type].get("ref_type") if not reftype: - reftype =3D self.DEF_SYMBOL_TYPES[c_type].get("ref_typ= e") - if not reftype: - reftype =3D self.DEF_SYMBOL_TYPES[c_type].get("rea= l_type") + reftype =3D self.DEF_SYMBOL_TYPES[c_type].get("real_ty= pe") =20 - new_ref =3D f"{reftype}:`{old} <{new}>`" + new_ref =3D f"{reftype}:`{old} <{new}>`" =20 - # Change self.symbols to use the replacement rule - if old in self.symbols[c_type]: - (_, ln) =3D self.symbols[c_type][old] - self.symbols[c_type][old] =3D (new_ref, ln) - else: - print(f"{name}:{ln}: Warning: can't find {old} {c_type= }") + # Change self.symbols to use the replacement rule + if old in self.symbols[c_type]: + (_, ln) =3D self.symbols[c_type][old] + self.symbols[c_type][old] =3D (new_ref, ln) + else: + print(f"{name}:{ln}: Warning: can't find {old} {c_type}") + + def process_exceptions(self, fname: str): + """ + Process exceptions file with rules to ignore or replace references. + """ + self.read_exceptions(fname) + self.apply_exceptions() =20 def debug_print(self): """ --=20 2.51.0