Meson 是否可以将文件内容读入数组或字符串?从这里可以将字符串拆分为数组,并且可以使用 循环数组foreach,但是我一直无法找到从文件中获取数据的方法。
从Meson 0.57.0开始,可以使用readFilesystem模块的功能:
fs = import('fs')
...
my_list = fs.read('list.txt').strip().split('\n')
foreach item : my_list
# Do something
endforeach
Run Code Online (Sandbox Code Playgroud)
要完成@TingPing 的回答,我通常会这样做:
files = run_command(
'cat', files('thefile.txt'),
).stdout().strip()
Run Code Online (Sandbox Code Playgroud)
该方法也可以用于类似的事情:
images = run_command('find',
meson.current_source_dir(),
'-type', 'f',
'-name', '*.png',
'-printf', '%f\n'
).stdout().strip().split('\n')
Run Code Online (Sandbox Code Playgroud)
不要忘记使用 Meson 的文件引用可能有点不精确,因此您需要使用其中之一:
files('thefilename')join_paths(meson.source_root(), meson.current_source_dir(), 'thefilename')编辑:对于更交叉兼容的解决方案,您可以使用 python 而不是cat:
files = run_command('python', '-c',
'[print(line, end="") for line in open("{0}")]'.format(myfile)
).stdout().strip()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
754 次 |
| 最近记录: |