freedreno/registers: Generate copyright comment blurb

Similar to headergen2, the output matches as closely as is reasonable.
The time format and file listing ends up being slightly different but
those would be part of the diffstat when we next update kernel headers
regardless.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27124>
This commit is contained in:
Rob Clark
2024-01-17 12:00:23 -08:00
committed by Marge Bot
parent 8eca68d2de
commit ab64afc109

View File

@@ -5,6 +5,8 @@ import sys
import os
import collections
import argparse
import time
import datetime
class Error(Exception):
def __init__(self, message):
@@ -336,6 +338,9 @@ class Parser(object):
self.variants = set()
self.file = []
self.xml_files = []
self.copyright_year = None
self.authors = []
self.license = None
def error(self, message):
parser, filename = self.stack[-1]
@@ -470,6 +475,8 @@ class Parser(object):
self.stack.append((parser, filename))
parser.StartElementHandler = self.start_element
parser.EndElementHandler = self.end_element
parser.CharacterDataHandler = self.character_data
parser.buffer_text = True
parser.ParseFile(file)
self.stack.pop()
file.close()
@@ -516,6 +523,7 @@ class Parser(object):
self.add_all_usages(self.current_reg, usages)
def start_element(self, name, attrs):
self.cdata = ""
if name == "import":
filename = attrs["file"]
self.do_parse(os.path.join(self.path, filename))
@@ -564,6 +572,10 @@ class Parser(object):
self.parse_field(attrs["name"], attrs)
elif name == "database":
self.do_validate(attrs["xsi:schemaLocation"])
elif name == "copyright":
self.copyright_year = attrs["year"]
elif name == "author":
self.authors.append(attrs["name"] + " <" + attrs["email"] + "> " + attrs["name"])
def end_element(self, name):
if name == "domain":
@@ -580,6 +592,11 @@ class Parser(object):
self.current_array = None
elif name == "enum":
self.current_enum = None
elif name == "license":
self.license = self.cdata
def character_data(self, data):
self.cdata += data
def dump_reg_usages(self):
d = collections.defaultdict(list)
@@ -737,6 +754,33 @@ def dump_c(args, guard, func):
print("#ifndef %s\n#define %s\n" % (guard, guard))
print("""/* Autogenerated file, DO NOT EDIT manually!
This file was generated by the rules-ng-ng gen_header.py tool in this git repository:
http://gitlab.freedesktop.org/mesa/mesa/
git clone https://gitlab.freedesktop.org/mesa/mesa.git
The rules-ng-ng source files this header was generated from are:
""")
maxlen = 0
for filepath in p.xml_files:
maxlen = max(maxlen, len(filepath))
for filepath in p.xml_files:
pad = " " * (maxlen - len(filepath))
filesize = str(os.path.getsize(filepath))
filesize = " " * (7 - len(filesize)) + filesize
filetime = time.ctime(os.path.getmtime(filepath))
print("- " + filepath + pad + " (" + filesize + " bytes, from " + filetime + ")")
if p.copyright_year:
current_year = str(datetime.date.today().year)
print()
print("Copyright (C) %s-%s by the following authors:" % (p.copyright_year, current_year))
for author in p.authors:
print("- " + author)
if p.license:
print(p.license)
print("*/")
print()
print("#include <assert.h>")
print()