Skip to content

Commit 7704ae0

Browse files
committed
meson: hook up update-constants helper
$ 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.
1 parent 32ca47f commit 7704ae0

File tree

4 files changed

+58
-16
lines changed

4 files changed

+58
-16
lines changed

Makefile

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,6 @@ BUILD_DIR = build
1111

1212
all: build
1313

14-
.PHONY: update-constants
15-
update-constants: update-constants.py $(INCLUDE_DIR)/systemd/sd-messages.h
16-
$(PYTHON) $+ src/systemd/id128-defines.h | \
17-
sort -u | \
18-
tee src/systemd/id128-defines.h.tmp | \
19-
$(SED) -n -r 's/,//g; s/#define (SD_MESSAGE_[A-Z0-9_]+)\s.*/add_id(m, "\1", \1) JOINER/p' | \
20-
sort -u > src/systemd/id128-constants.h.tmp
21-
mv src/systemd/id128-defines.h{.tmp,}
22-
mv src/systemd/id128-constants.h{.tmp,}
23-
($(SED) 9q <docs/id128.rst && \
24-
sed -n -r 's/#define (SD_MESSAGE_[A-Z0-9_]+) .*/ .. autoattribute:: systemd.id128.\1/p' \
25-
src/systemd/id128-defines.h) >docs/id128.rst.tmp
26-
mv docs/id128.rst{.tmp,}
27-
2814
build:
2915
$(PYTHON) -m build -Cbuild-dir=$(BUILD_DIR)
3016

meson.build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ common_c_args = [
2020
'-DLIBSYSTEMD_VERSION=@0@'.format(libsystemd_dep.version()),
2121
]
2222

23+
update_constants_py = files('update-constants.py')
24+
2325
subdir('src/systemd')
26+
27+
alias_target('update-constants', update_constants)

src/systemd/meson.build

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,15 @@ python.install_sources(
6666
'test/test_id128.py',
6767
subdir: 'systemd/test',
6868
)
69+
70+
include_dir = libsystemd_dep.get_variable(pkgconfig: 'includedir')
71+
72+
update_constants = custom_target(
73+
output: 'update-constants-impl',
74+
command: [
75+
update_constants_py,
76+
meson.current_source_dir() / 'id128-constants.h',
77+
meson.project_source_root() / 'docs/id128.rst',
78+
meson.current_source_dir() / 'id128-defines.h',
79+
include_dir / 'systemd/sd-messages.h',
80+
])

update-constants.py

100644100755
Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,51 @@
1+
#!/usr/bin/env python3
12
# SPDX-License-Identifier: LGPL-2.1-or-later
23

34
import sys
45

5-
for file in sys.argv[1:]:
6+
def defines(file):
67
lines = iter(open(file).read().splitlines())
78
for line in lines:
89
if line.startswith('#define SD_MESSAGE') and '_STR ' not in line:
910
if line.endswith('\\'):
1011
line = line[:-1] + next(lines)
11-
print(' '.join(line.split()))
12+
_, name, value = line.split()
13+
assert 'SD_' in name
14+
assert 'SD_ID128_MAKE' in value
15+
yield name, value
16+
17+
18+
def process(includefile, docfile, *headers):
19+
# Collects all messages from all headers and saves the sorted list back to
20+
# headers[0]. Writes includefile (C) and docfile (rst).
21+
22+
# Collect all messages into a single sorted, deduplicated list
23+
defs = sum((list(defines(file)) for file in headers), start=[])
24+
defs = sorted(set(defs))
25+
26+
with open(includefile, 'wt') as out:
27+
print(f'Writing {out.name}…')
28+
for name, value in defs:
29+
print(f'add_id(m, "{name}", {name}) JOINER', file=out)
30+
31+
with open(headers[0], 'wt') as out:
32+
print(f'Writing {out.name}…')
33+
for name, value in defs:
34+
print(f'#define {name} {value}', file=out)
35+
36+
old = open(docfile).read().splitlines()
37+
38+
with open(docfile, 'wt') as out:
39+
print(f'Writing {out.name}…')
40+
for line in old:
41+
print(line, file=out)
42+
if 'autogenerated' in line:
43+
break
44+
for name, value in defs:
45+
print(f' .. autoattribute:: systemd.id128.{name}', file=out)
46+
47+
if __name__ == '__main__':
48+
includefile = sys.argv[1]
49+
docfile = sys.argv[2]
50+
headers = sys.argv[3:]
51+
process(includefile, docfile, *headers)

0 commit comments

Comments
 (0)