mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-25 23:21:33 +03:00
8f04a1ca2b
GIT_VERSION is not available as a config.h variable, because it's rendered into version.h during builds. Let's rework jinja2 rendering to also parse version.h. No functional change, the new variable is so far unused. I guess this will make partial rebuilds a bit slower, but it's useful to be able to use the full version string.
38 lines
983 B
Python
Executable File
38 lines
983 B
Python
Executable File
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
import ast
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
import jinja2
|
|
|
|
def parse_config_h(filename):
|
|
# Parse config.h file generated by meson.
|
|
ans = {}
|
|
for line in open(filename):
|
|
m = re.match(r'#define\s+(\w+)\s+(.*)', line)
|
|
if not m:
|
|
continue
|
|
a, b = m.groups()
|
|
if b and b[0] in '0123456789"':
|
|
b = ast.literal_eval(b)
|
|
ans[a] = b
|
|
return ans
|
|
|
|
def render(filename, defines):
|
|
text = open(filename).read()
|
|
template = jinja2.Template(text, trim_blocks=True, undefined=jinja2.StrictUndefined)
|
|
return template.render(defines)
|
|
|
|
if __name__ == '__main__':
|
|
defines = parse_config_h(sys.argv[1])
|
|
defines.update(parse_config_h(sys.argv[2]))
|
|
output = render(sys.argv[3], defines)
|
|
with open(sys.argv[4], 'w') as f:
|
|
f.write(output)
|
|
f.write('\n')
|
|
info = os.stat(sys.argv[3])
|
|
os.chmod(sys.argv[4], info.st_mode)
|