aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorMathieu Duponchelle <MathieuDuponchelle@users.noreply.github.com>2018-06-01 19:53:07 +0200
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2018-06-01 17:53:07 +0000
commit14750b50ea9c9f53237bed59a79365e1ebbdacda (patch)
tree9497bd107cc4889bdb6daf60094bf650c1315e82 /mesonbuild
parent17cb364046661c2d72193b4d8691070fd0fb276b (diff)
downloadmeson-14750b50ea9c9f53237bed59a79365e1ebbdacda.zip
meson-14750b50ea9c9f53237bed59a79365e1ebbdacda.tar.gz
meson-14750b50ea9c9f53237bed59a79365e1ebbdacda.tar.bz2
configure_file: Add output_format kwarg (#3636)
* configure_file: Add output_format kwarg * docs: Reference-manual.md output_format was added in 0.47 [skip ci]
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/interpreter.py14
-rw-r--r--mesonbuild/mesonlib.py36
2 files changed, 39 insertions, 11 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 4f2d45e..d2238d7 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -1697,7 +1697,7 @@ permitted_kwargs = {'add_global_arguments': {'language'},
'add_test_setup': {'exe_wrapper', 'gdb', 'timeout_multiplier', 'env'},
'benchmark': {'args', 'env', 'should_fail', 'timeout', 'workdir', 'suite'},
'build_target': known_build_target_kwargs,
- 'configure_file': {'input', 'output', 'configuration', 'command', 'copy', 'install_dir', 'capture', 'install', 'format'},
+ 'configure_file': {'input', 'output', 'configuration', 'command', 'copy', 'install_dir', 'capture', 'install', 'format', 'output_format'},
'custom_target': {'input', 'output', 'command', 'install', 'install_dir', 'build_always', 'capture', 'depends', 'depend_files', 'depfile', 'build_by_default'},
'dependency': {'default_options', 'fallback', 'language', 'main', 'method', 'modules', 'optional_modules', 'native', 'required', 'static', 'version', 'private_headers'},
'declare_dependency': {'include_directories', 'link_with', 'sources', 'dependencies', 'compile_args', 'link_args', 'link_whole', 'version'},
@@ -3196,6 +3196,16 @@ root and issuing %s.
if fmt not in ('meson', 'cmake', 'cmake@'):
raise InterpreterException('"format" possible values are "meson", "cmake" or "cmake@".')
+ if 'output_format' in kwargs:
+ output_format = kwargs['output_format']
+ if not isinstance(output_format, str):
+ raise InterpreterException('"output_format" keyword must be a string.')
+ else:
+ output_format = 'c'
+
+ if output_format not in ('c', 'nasm'):
+ raise InterpreterException('"format" possible values are "c" or "nasm".')
+
# Validate input
inputfile = None
ifile_abs = None
@@ -3258,7 +3268,7 @@ root and issuing %s.
"present in the given configuration data." % (
var_list, inputfile), location=node)
else:
- mesonlib.dump_conf_header(ofile_abs, conf.held_object)
+ mesonlib.dump_conf_header(ofile_abs, conf.held_object, output_format)
conf.mark_used()
elif 'command' in kwargs:
# We use absolute paths for input and output here because the cwd
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index fe426c5..6a38479 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -634,28 +634,46 @@ def do_conf_file(src, dst, confdata, format):
replace_if_different(dst, dst_tmp)
return missing_variables
-def dump_conf_header(ofilename, cdata):
- ofilename_tmp = ofilename + '~'
- with open(ofilename_tmp, 'w', encoding='utf-8') as ofile:
- ofile.write('''/*
+CONF_C_PRELUDE = '''/*
* Autogenerated by the Meson build system.
* Do not edit, your changes will be lost.
*/
#pragma once
-''')
+'''
+
+CONF_NASM_PRELUDE = '''; Autogenerated by the Meson build system.
+; Do not edit, your changes will be lost.
+
+'''
+
+def dump_conf_header(ofilename, cdata, output_format):
+ if output_format == 'c':
+ prelude = CONF_C_PRELUDE
+ prefix = '#'
+ elif output_format == 'nasm':
+ prelude = CONF_NASM_PRELUDE
+ prefix = '%'
+
+ 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:
- ofile.write('/* %s */\n' % 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('#define %s\n\n' % k)
+ ofile.write('%sdefine %s\n\n' % (prefix, k))
else:
- ofile.write('#undef %s\n\n' % k)
+ ofile.write('%sundef %s\n\n' % (prefix, k))
elif isinstance(v, (int, str)):
- ofile.write('#define %s %s\n\n' % (k, v))
+ ofile.write('%sdefine %s %s\n\n' % (prefix, k, v))
else:
raise MesonException('Unknown data type in configuration file entry: ' + k)
replace_if_different(ofilename, ofilename_tmp)