mirror of
https://github.com/systemd/python-systemd.git
synced 2026-07-06 22:33:19 -04:00
$ ninja -C build update-constants -v ninja: Entering directory `build' [1/1] /home/zbyszek/src/python-systemd/update-constants.py /home/zbyszek/src/python-systemd/src/systemd/id128-constants.h /home/zbyszek/src/python-systemd/docs/id128.rst /home/zbyszek/src/python-systemd/src/systemd/id128-defines.h /usr/include/systemd/sd-messages.h Writing /home/zbyszek/src/python-systemd/src/systemd/id128-constants.h… Writing /home/zbyszek/src/python-systemd/src/systemd/id128-defines.h… Writing /home/zbyszek/src/python-systemd/docs/id128.rst… The helper is updated to do the everything in the python script. The wrapper in Makefile is dropped. It wasn't working properly anyway, and I think the version in meson is enough.
51 lines
1.6 KiB
Python
Executable file
51 lines
1.6 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
import sys
|
|
|
|
def defines(file):
|
|
lines = iter(open(file).read().splitlines())
|
|
for line in lines:
|
|
if line.startswith('#define SD_MESSAGE') and '_STR ' not in line:
|
|
if line.endswith('\\'):
|
|
line = line[:-1] + next(lines)
|
|
_, name, value = line.split()
|
|
assert 'SD_' in name
|
|
assert 'SD_ID128_MAKE' in value
|
|
yield name, value
|
|
|
|
|
|
def process(includefile, docfile, *headers):
|
|
# Collects all messages from all headers and saves the sorted list back to
|
|
# headers[0]. Writes includefile (C) and docfile (rst).
|
|
|
|
# Collect all messages into a single sorted, deduplicated list
|
|
defs = sum((list(defines(file)) for file in headers), start=[])
|
|
defs = sorted(set(defs))
|
|
|
|
with open(includefile, 'wt') as out:
|
|
print(f'Writing {out.name}…')
|
|
for name, value in defs:
|
|
print(f'add_id(m, "{name}", {name}) JOINER', file=out)
|
|
|
|
with open(headers[0], 'wt') as out:
|
|
print(f'Writing {out.name}…')
|
|
for name, value in defs:
|
|
print(f'#define {name} {value}', file=out)
|
|
|
|
old = open(docfile).read().splitlines()
|
|
|
|
with open(docfile, 'wt') as out:
|
|
print(f'Writing {out.name}…')
|
|
for line in old:
|
|
print(line, file=out)
|
|
if 'autogenerated' in line:
|
|
break
|
|
for name, value in defs:
|
|
print(f' .. autoattribute:: systemd.id128.{name}', file=out)
|
|
|
|
if __name__ == '__main__':
|
|
includefile = sys.argv[1]
|
|
docfile = sys.argv[2]
|
|
headers = sys.argv[3:]
|
|
process(includefile, docfile, *headers)
|