diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2016-06-01 20:25:14 +0300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2016-06-01 20:25:14 +0300 |
commit | 177e286b3c761f461ac55ede934b941384b4bb97 (patch) | |
tree | 367e49025a633bb7f5f212769ca3ee5c57cf4510 /mesonbuild | |
parent | 0482635c1293ecc1148da8236f6b77cd4f21e130 (diff) | |
download | meson-177e286b3c761f461ac55ede934b941384b4bb97.zip meson-177e286b3c761f461ac55ede934b941384b4bb97.tar.gz meson-177e286b3c761f461ac55ede934b941384b4bb97.tar.bz2 |
Can generate config headers without an input file. Closes #549.
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/interpreter.py | 24 | ||||
-rw-r--r-- | mesonbuild/mesonlib.py | 21 |
2 files changed, 34 insertions, 11 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 47f9c7e..ba943e3 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -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' % diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index fe831bd..584b3b2 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -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 |