|
|
|
@ -32,6 +32,7 @@ import textwrap |
|
|
|
|
import copy |
|
|
|
|
import pickle |
|
|
|
|
import errno |
|
|
|
|
import json |
|
|
|
|
|
|
|
|
|
from mesonbuild import mlog |
|
|
|
|
from .core import MesonException, HoldableObject |
|
|
|
@ -1361,34 +1362,43 @@ CONF_NASM_PRELUDE = '''; Autogenerated by the Meson build system. |
|
|
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
|
|
def dump_conf_header(ofilename: str, cdata: 'ConfigurationData', output_format: Literal['c', 'nasm']) -> None: |
|
|
|
|
def _dump_c_header(ofile: T.TextIO, cdata: ConfigurationData, output_format: Literal['c', 'nasm']) -> None: |
|
|
|
|
format_desc: T.Callable[[str], str] |
|
|
|
|
if output_format == 'c': |
|
|
|
|
prelude = CONF_C_PRELUDE |
|
|
|
|
prefix = '#' |
|
|
|
|
else: |
|
|
|
|
format_desc = lambda desc: f'/* {desc} */\n' |
|
|
|
|
else: # nasm |
|
|
|
|
prelude = CONF_NASM_PRELUDE |
|
|
|
|
prefix = '%' |
|
|
|
|
format_desc = lambda desc: '; ' + '\n; '.join(desc.splitlines()) + '\n' |
|
|
|
|
|
|
|
|
|
ofile.write(prelude) |
|
|
|
|
for k in sorted(cdata.keys()): |
|
|
|
|
(v, desc) = cdata.get(k) |
|
|
|
|
if desc: |
|
|
|
|
ofile.write(format_desc(desc)) |
|
|
|
|
if isinstance(v, bool): |
|
|
|
|
if v: |
|
|
|
|
ofile.write(f'{prefix}define {k}\n\n') |
|
|
|
|
else: |
|
|
|
|
ofile.write(f'{prefix}undef {k}\n\n') |
|
|
|
|
elif isinstance(v, (int, str)): |
|
|
|
|
ofile.write(f'{prefix}define {k} {v}\n\n') |
|
|
|
|
else: |
|
|
|
|
raise MesonException('Unknown data type in configuration file entry: ' + k) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def dump_conf_header(ofilename: str, cdata: ConfigurationData, |
|
|
|
|
output_format: Literal['c', 'nasm', 'json']) -> None: |
|
|
|
|
ofilename_tmp = ofilename + '~' |
|
|
|
|
with open(ofilename_tmp, 'w', encoding='utf-8') as ofile: |
|
|
|
|
ofile.write(prelude) |
|
|
|
|
for k in sorted(cdata.keys()): |
|
|
|
|
(v, desc) = cdata.get(k) |
|
|
|
|
if desc: |
|
|
|
|
if output_format == 'c': |
|
|
|
|
ofile.write('/* %s */\n' % desc) |
|
|
|
|
elif output_format == 'nasm': |
|
|
|
|
for line in desc.split('\n'): |
|
|
|
|
ofile.write('; %s\n' % line) |
|
|
|
|
if isinstance(v, bool): |
|
|
|
|
if v: |
|
|
|
|
ofile.write(f'{prefix}define {k}\n\n') |
|
|
|
|
else: |
|
|
|
|
ofile.write(f'{prefix}undef {k}\n\n') |
|
|
|
|
elif isinstance(v, (int, str)): |
|
|
|
|
ofile.write(f'{prefix}define {k} {v}\n\n') |
|
|
|
|
else: |
|
|
|
|
raise MesonException('Unknown data type in configuration file entry: ' + k) |
|
|
|
|
if output_format == 'json': |
|
|
|
|
data = {k: v[0] for k, v in cdata.values.items()} |
|
|
|
|
json.dump(data, ofile, sort_keys=True) |
|
|
|
|
else: # c, nasm |
|
|
|
|
_dump_c_header(ofile, cdata, output_format) |
|
|
|
|
|
|
|
|
|
replace_if_different(ofilename, ofilename_tmp) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|