Pie*_*tro 3 shell command file-copying meson-build
如何cp从 Meson 构建脚本运行 shell 命令(例如,复制)?
我尝试使用以下代码:
r = run_command('cp', 'test.txt', 'test2.txt')
if r.returncode() != 0
warning('Command failed')
endif
Run Code Online (Sandbox Code Playgroud)
但它什么也没做。
run_command运行成功(返回 0),但未复制文件。
如果我cp用替换cp3,我会从 Meson 收到一条错误消息,进程终止,甚至不会到达下一行。
如果我替换test.txt为test0.txt,我会从脚本中收到一条错误消息。
因此该脚本行为正确,但该命令在文件系统上没有留下任何痕迹。
是run_command从 Meson 运行 shell 命令的唯一方法吗?我究竟做错了什么?
参考: https: //mesonbuild.com/External-commands.html
该命令是从未指定的目录运行的,因此,请尝试指定完整的文件名,例如:
source = join_paths(meson.source_root(), 'test.txt')
dest = join_paths(meson.build_root(), 'test2.txt')
message('copying @0@ to @1@ ...'.format(source, dest))
r = run_command('cp', source, dest)
Run Code Online (Sandbox Code Playgroud)