aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2018-05-22 21:09:19 +0300
committerGitHub <noreply@github.com>2018-05-22 21:09:19 +0300
commit55a0831bc3d00d642197bc0755191c9fe1ef2ac7 (patch)
tree777e890608ff9422700c4679587c7e2dc0b7dc21 /mesonbuild
parent9ecd92c6fedd052f4115683726a5cc6ebaa33e85 (diff)
parent4b9393e165c4521351f6fdfd8179997016bd84a8 (diff)
downloadmeson-55a0831bc3d00d642197bc0755191c9fe1ef2ac7.zip
meson-55a0831bc3d00d642197bc0755191c9fe1ef2ac7.tar.gz
meson-55a0831bc3d00d642197bc0755191c9fe1ef2ac7.tar.bz2
Merge pull request #3383 from mesonbuild/nirbheek/configure-file-nodata
configure_file: Add a new action 'copy'
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/interpreter.py50
1 files changed, 39 insertions, 11 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index a63c143..64fc693 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -1671,7 +1671,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', 'install_dir', 'capture', 'install', 'format'},
+ 'configure_file': {'input', 'output', 'configuration', 'command', 'copy', 'install_dir', 'capture', 'install', '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'},
'declare_dependency': {'include_directories', 'link_with', 'sources', 'dependencies', 'compile_args', 'link_args', 'link_whole', 'version'},
@@ -3140,10 +3140,19 @@ root and issuing %s.
raise InterpreterException("configure_file takes only keyword arguments.")
if 'output' not in kwargs:
raise InterpreterException('Required keyword argument "output" not defined.')
- if 'configuration' in kwargs and 'command' in kwargs:
- raise InterpreterException('Must not specify both "configuration" '
- 'and "command" keyword arguments since '
- 'they are mutually exclusive.')
+ actions = set(['configuration', 'command', 'copy']).intersection(kwargs.keys())
+ if len(actions) == 0:
+ raise InterpreterException('Must specify an action with one of these '
+ 'keyword arguments: \'configuration\', '
+ '\'command\', or \'copy\'.')
+ elif len(actions) == 2:
+ raise InterpreterException('Must not specify both {!r} and {!r} '
+ 'keyword arguments since they are '
+ 'mutually exclusive.'.format(*actions))
+ elif len(actions) == 3:
+ raise InterpreterException('Must specify one of {!r}, {!r}, and '
+ '{!r} keyword arguments since they are '
+ 'mutually exclusive.'.format(*actions))
if 'capture' in kwargs:
if not isinstance(kwargs['capture'], bool):
raise InterpreterException('"capture" keyword must be a boolean.')
@@ -3151,13 +3160,13 @@ root and issuing %s.
raise InterpreterException('"capture" keyword requires "command" keyword.')
if 'format' in kwargs:
- format = kwargs['format']
- if not isinstance(format, str):
+ fmt = kwargs['format']
+ if not isinstance(fmt, str):
raise InterpreterException('"format" keyword must be a string.')
else:
- format = 'meson'
+ fmt = 'meson'
- if format not in ('meson', 'cmake', 'cmake@'):
+ if fmt not in ('meson', 'cmake', 'cmake@'):
raise InterpreterException('"format" possible values are "meson", "cmake" or "cmake@".')
# Validate input
@@ -3191,6 +3200,20 @@ root and issuing %s.
raise InterpreterException('Output file name must not contain a subdirectory.')
(ofile_path, ofile_fname) = os.path.split(os.path.join(self.subdir, output))
ofile_abs = os.path.join(self.environment.build_dir, ofile_path, ofile_fname)
+ # Optimize copies by not doing substitution if there's nothing to
+ # substitute, and warn about this legacy hack
+ if 'configuration' in kwargs:
+ conf = kwargs['configuration']
+ if not isinstance(conf, ConfigurationDataHolder):
+ raise InterpreterException('Argument "configuration" must be of type configuration_data')
+ if ifile_abs and not conf.keys():
+ del kwargs['configuration']
+ kwargs['copy'] = True
+ mlog.warning('Got an empty configuration_data() object: '
+ 'optimizing copy automatically; if you want to '
+ 'copy a file to the build dir, use the \'copy:\' '
+ 'keyword argument added in 0.46.0', location=node)
+ # Perform the appropriate action
if 'configuration' in kwargs:
conf = kwargs['configuration']
if not isinstance(conf, ConfigurationDataHolder):
@@ -3199,7 +3222,7 @@ root and issuing %s.
if inputfile is not None:
os.makedirs(os.path.join(self.environment.build_dir, self.subdir), exist_ok=True)
missing_variables = mesonlib.do_conf_file(ifile_abs, ofile_abs,
- conf.held_object, format)
+ conf.held_object, fmt)
if missing_variables:
var_list = ", ".join(map(repr, sorted(missing_variables)))
mlog.warning(
@@ -3231,8 +3254,13 @@ root and issuing %s.
if ifile_abs:
shutil.copymode(ifile_abs, dst_tmp)
mesonlib.replace_if_different(ofile_abs, dst_tmp)
+ elif 'copy' in kwargs:
+ os.makedirs(os.path.join(self.environment.build_dir, self.subdir), exist_ok=True)
+ shutil.copyfile(ifile_abs, ofile_abs)
+ shutil.copymode(ifile_abs, ofile_abs)
else:
- raise InterpreterException('Configure_file must have either "configuration" or "command".')
+ # Not reachable
+ raise AssertionError
# If the input is a source file, add it to the list of files that we
# need to reconfigure on when they change. FIXME: Do the same for
# files() objects in the command: kwarg.