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
This commit is contained in:
parent
4d8e3be08f
commit
5fdac48250
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
)
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue