Can generate config headers without an input file. Closes #549.

pull/579/head
Jussi Pakkanen 9 years ago
parent 0482635c12
commit 177e286b3c
  1. 24
      mesonbuild/interpreter.py
  2. 21
      mesonbuild/mesonlib.py
  3. 33
      test cases/common/16 configure file/dumpprog.c
  4. 15
      test cases/common/16 configure file/meson.build

@ -1887,13 +1887,11 @@ class Interpreter():
def func_configure_file(self, node, args, kwargs):
if len(args) > 0:
raise InterpreterException("configure_file takes only keyword arguments.")
if not 'input' in kwargs:
raise InterpreterException('Required keyword argument "input" not defined.')
if not 'output' in kwargs:
raise InterpreterException('Required keyword argument "output" not defined.')
inputfile = kwargs['input']
inputfile = kwargs.get('input', None)
output = kwargs['output']
if not isinstance(inputfile, str):
if not isinstance(inputfile, (str, type(None))):
raise InterpreterException('Input must be a string.')
if not isinstance(output, str):
raise InterpreterException('Output must be a string.')
@ -1903,16 +1901,20 @@ class Interpreter():
conf = kwargs['configuration']
if not isinstance(conf, ConfigurationDataHolder):
raise InterpreterException('Argument "configuration" is not of type configuration_data')
conffile = os.path.join(self.subdir, inputfile)
if conffile not in self.build_def_files:
self.build_def_files.append(conffile)
os.makedirs(os.path.join(self.environment.build_dir, self.subdir), exist_ok=True)
ifile_abs = os.path.join(self.environment.source_dir, self.subdir, inputfile)
ofile_abs = os.path.join(self.environment.build_dir, self.subdir, output)
mesonlib.do_conf_file(ifile_abs, ofile_abs, conf.held_object)
if inputfile is not None:
conffile = os.path.join(self.subdir, inputfile)
if conffile not in self.build_def_files:
self.build_def_files.append(conffile)
os.makedirs(os.path.join(self.environment.build_dir, self.subdir), exist_ok=True)
ifile_abs = os.path.join(self.environment.source_dir, self.subdir, inputfile)
mesonlib.do_conf_file(ifile_abs, ofile_abs, conf.held_object)
else:
mesonlib.dump_conf_header(ofile_abs, conf.held_object)
conf.mark_used()
elif 'command' in kwargs:
if 'input' not in kwargs:
raise InterpreterException('Required keyword input missing.')
res = self.func_run_command(node, kwargs['command'], {})
if res.returncode != 0:
raise InterpreterException('Running configure command failed.\n%s\n%s' %

@ -267,6 +267,27 @@ def do_conf_file(src, dst, confdata):
shutil.copymode(src, dst_tmp)
replace_if_different(dst, dst_tmp)
def dump_conf_header(ofilename, cdata):
with open(ofilename, 'w') as ofile:
ofile.write('''/*
* Autogenerated by the Meson build system.
* Do not edit, your changes will be lost.
*/
#pragma once
''')
for k in sorted(cdata.keys()):
v = cdata.get(k)
if isinstance(v, bool):
if v:
ofile.write('#define %s\n\n' % k)
else:
ofile.write('#undef %s\n\n' % k)
elif isinstance(v, (int, str)):
ofile.write('#define %s %s\n\n' % (k, v))
else:
raise MesonException('Unknown data type in configuration file entry: ' + k)
def replace_if_different(dst, dst_tmp):
# If contents are identical, don't touch the file to prevent

@ -0,0 +1,33 @@
#define SHOULD_BE_UNDEFINED 1
#include"config3.h"
#include<string.h>
#include<stdio.h>
#ifdef SHOULD_BE_UNDEFINED
#error Token did not get undefined.
#endif
#ifndef SHOULD_BE_DEFINED
#error Token did not get defined
#endif
int main(int argc, char **argv) {
if(strcmp(SHOULD_BE_STRING, "string") != 0) {
printf("String token defined wrong.\n");
return 1;
}
if(SHOULD_BE_ONE != 1) {
printf("One defined incorrectly.\n");
return 1;
}
if(SHOULD_BE_ZERO != 0) {
printf("Zero defined incorrectly.\n");
return 1;
}
if(strcmp(SHOULD_BE_QUOTED_ONE, "1") != 0) {
printf("Quoted number defined incorrectly.\n");
return 1;
}
SHOULD_BE_RETURN 0;
}

@ -30,3 +30,18 @@ command : [genprog, scriptfile, ifile, ofile],
install_dir : 'share/appdir')
test('inctest2', executable('prog2', 'prog2.c'))
# Generate a conf file without an input file.
dump = configuration_data()
dump.set('SHOULD_BE_STRING', '"string"')
dump.set('SHOULD_BE_RETURN', 'return')
dump.set('SHOULD_BE_DEFINED', true)
dump.set('SHOULD_BE_UNDEFINED', false)
dump.set('SHOULD_BE_ONE', 1)
dump.set('SHOULD_BE_ZERO', 0)
dump.set('SHOULD_BE_QUOTED_ONE', '"1"')
configure_file(output : 'config3.h',
configuration : dump)
test('Configless.', executable('dumpprog', 'dumpprog.c'))

Loading…
Cancel
Save