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,12 +572,29 @@ class Backend():
|
||||||
i = i.replace('@INPUT%d@' % j, src)
|
i = i.replace('@INPUT%d@' % j, src)
|
||||||
for (j, res) in enumerate(ofilenames):
|
for (j, res) in enumerate(ofilenames):
|
||||||
i = i.replace('@OUTPUT%d@' % j, res)
|
i = i.replace('@OUTPUT%d@' % j, res)
|
||||||
|
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@':
|
if i == '@INPUT@':
|
||||||
cmd += srcs
|
cmd += srcs
|
||||||
elif i == '@OUTPUT@':
|
continue
|
||||||
cmd += ofilenames
|
|
||||||
else:
|
else:
|
||||||
if '@OUTDIR@' in i:
|
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)
|
i = i.replace('@OUTDIR@', outdir)
|
||||||
elif '@DEPFILE@' in i:
|
elif '@DEPFILE@' in i:
|
||||||
if target.depfile is None:
|
if target.depfile is None:
|
||||||
|
|
|
@ -9,7 +9,7 @@ comp = '@0@/@1@'.format(meson.current_source_dir(), 'my_compiler.py')
|
||||||
mytarget = custom_target('bindat',
|
mytarget = custom_target('bindat',
|
||||||
output : 'data.dat',
|
output : 'data.dat',
|
||||||
input : 'data_source.txt',
|
input : 'data_source.txt',
|
||||||
command : [python, comp, '@INPUT@', '@OUTPUT@'],
|
command : [python, comp, '--input=@INPUT@', '--output=@OUTPUT@'],
|
||||||
install : true,
|
install : true,
|
||||||
install_dir : 'subdir'
|
install_dir : 'subdir'
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,13 +3,14 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) != 3:
|
if len(sys.argv) != 3 or not sys.argv[1].startswith('--input') or \
|
||||||
print(sys.argv[0], 'input_file output_file')
|
not sys.argv[2].startswith('--output'):
|
||||||
|
print(sys.argv[0], '--input=input_file --output=output_file')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
with open(sys.argv[1]) as f:
|
with open(sys.argv[1].split('=')[1]) as f:
|
||||||
ifile = f.read()
|
ifile = f.read()
|
||||||
if ifile != 'This is a text only input file.\n':
|
if ifile != 'This is a text only input file.\n':
|
||||||
print('Malformed input')
|
print('Malformed input')
|
||||||
sys.exit(1)
|
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')
|
ofile.write('This is a binary output file.\n')
|
||||||
|
|
Loading…
Reference in New Issue