diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-11-08 18:55:15 +0530 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2016-11-09 11:30:09 -0500 |
commit | 5fdac48250c0e4a7ad6e9b92041ab7b4d1bd02ec (patch) | |
tree | 5fe297ef6c3c52cbeeb28fac43786d2a4d5126db | |
parent | 4d8e3be08f5d6a426f64fb6a1f71c9f52b249311 (diff) | |
download | meson-5fdac48250c0e4a7ad6e9b92041ab7b4d1bd02ec.zip meson-5fdac48250c0e4a7ad6e9b92041ab7b4d1bd02ec.tar.gz meson-5fdac48250c0e4a7ad6e9b92041ab7b4d1bd02ec.tar.bz2 |
custom_target: Substitute @OUTPUT@ and @INPUT properly
They weren't being substituted if they were a part of a command
argument, ala --output=@OUTPUT@, etc.
Closes https://github.com/mesonbuild/meson/issues/824
-rw-r--r-- | mesonbuild/backend/backends.py | 69 | ||||
-rw-r--r-- | test cases/common/56 custom target/meson.build | 2 | ||||
-rwxr-xr-x | test cases/common/56 custom target/my_compiler.py | 9 |
3 files changed, 49 insertions, 31 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index bd75fdb..5cc2442 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -572,32 +572,49 @@ class Backend(): i = i.replace('@INPUT%d@' % j, src) for (j, res) in enumerate(ofilenames): i = i.replace('@OUTPUT%d@' % j, res) - if i == '@INPUT@': - cmd += srcs - elif i == '@OUTPUT@': - cmd += ofilenames - else: - if '@OUTDIR@' in i: - i = i.replace('@OUTDIR@', outdir) - elif '@DEPFILE@' in i: - if target.depfile is None: - raise MesonException('Custom target %s has @DEPFILE@ but no depfile keyword argument.' % target.name) - if absolute_paths: - dfilename = os.path.join(self.get_target_private_dir_abs(target), target.depfile) - else: - dfilename = os.path.join(self.get_target_private_dir(target), target.depfile) - i = i.replace('@DEPFILE@', dfilename) - elif '@PRIVATE_OUTDIR_' in i: - match = re.search('@PRIVATE_OUTDIR_(ABS_)?([-a-zA-Z0-9.@:]*)@', i) - source = match.group(0) - if match.group(1) is None and not absolute_paths: - lead_dir = '' - else: - lead_dir = self.environment.get_build_dir() - i = i.replace(source, - os.path.join(lead_dir, - outdir)) - cmd.append(i) + if '@INPUT@' in i: + msg = 'Custom target {} has @INPUT@ in the command, but'.format(target.name) + if len(srcs) == 0: + raise MesonException(msg + ' no input files') + if i == '@INPUT@': + cmd += srcs + continue + else: + if len(srcs) > 1: + raise MesonException(msg + ' more than one input file') + i = i.replace('@INPUT@', srcs[0]) + elif '@OUTPUT@' in i: + msg = 'Custom target {} has @OUTPUT@ in the command, but'.format(target.name) + if len(ofilenames) == 0: + raise MesonException(msg + ' no output files') + if i == '@OUTPUT@': + cmd += ofilenames + continue + else: + if len(ofilenames) > 1: + raise MesonException(msg + ' more than one output file') + i = i.replace('@OUTPUT@', ofilenames[0]) + elif '@OUTDIR@' in i: + i = i.replace('@OUTDIR@', outdir) + elif '@DEPFILE@' in i: + if target.depfile is None: + raise MesonException('Custom target %s has @DEPFILE@ but no depfile keyword argument.' % target.name) + if absolute_paths: + dfilename = os.path.join(self.get_target_private_dir_abs(target), target.depfile) + else: + dfilename = os.path.join(self.get_target_private_dir(target), target.depfile) + i = i.replace('@DEPFILE@', dfilename) + elif '@PRIVATE_OUTDIR_' in i: + match = re.search('@PRIVATE_OUTDIR_(ABS_)?([-a-zA-Z0-9.@:]*)@', i) + source = match.group(0) + if match.group(1) is None and not absolute_paths: + lead_dir = '' + else: + lead_dir = self.environment.get_build_dir() + i = i.replace(source, + os.path.join(lead_dir, + outdir)) + cmd.append(i) # This should not be necessary but removing it breaks # building GStreamer on Windows. The underlying issue # is problems with quoting backslashes on Windows diff --git a/test cases/common/56 custom target/meson.build b/test cases/common/56 custom target/meson.build index e216bae..feaa762 100644 --- a/test cases/common/56 custom target/meson.build +++ b/test cases/common/56 custom target/meson.build @@ -9,7 +9,7 @@ comp = '@0@/@1@'.format(meson.current_source_dir(), 'my_compiler.py') mytarget = custom_target('bindat', output : 'data.dat', input : 'data_source.txt', -command : [python, comp, '@INPUT@', '@OUTPUT@'], +command : [python, comp, '--input=@INPUT@', '--output=@OUTPUT@'], install : true, install_dir : 'subdir' ) diff --git a/test cases/common/56 custom target/my_compiler.py b/test cases/common/56 custom target/my_compiler.py index d99029b..4ba2da6 100755 --- a/test cases/common/56 custom target/my_compiler.py +++ b/test cases/common/56 custom target/my_compiler.py @@ -3,13 +3,14 @@ import sys if __name__ == '__main__': - if len(sys.argv) != 3: - print(sys.argv[0], 'input_file output_file') + if len(sys.argv) != 3 or not sys.argv[1].startswith('--input') or \ + not sys.argv[2].startswith('--output'): + print(sys.argv[0], '--input=input_file --output=output_file') sys.exit(1) - with open(sys.argv[1]) as f: + with open(sys.argv[1].split('=')[1]) as f: ifile = f.read() if ifile != 'This is a text only input file.\n': print('Malformed input') sys.exit(1) - with open(sys.argv[2], 'w') as ofile: + with open(sys.argv[2].split('=')[1], 'w') as ofile: ofile.write('This is a binary output file.\n') |