如何从 Meson 脚本 运行 shell 命令?

How to run a shell command from a Meson script?

如何从 Meson 构建脚本中 运行 shell 命令(例如 cp,即复制)?

我试过这个代码:

r = run_command('cp', 'test.txt', 'test2.txt')

if r.returncode() != 0
  warning('Command failed')
endif

但它什么也没做。
run_command 运行s 成功(返回 0),但未复制文件。
如果我用 cp3 替换 cp,我会收到来自 Meson 的错误消息,进程终止并且它甚至不会到达下一行。
如果我用 test0.txt 替换 test.txt,我会从脚本中收到一条错误消息。

所以脚本运行正确,但命令在文件系统上没有留下任何痕迹。

run_command 是 运行 来自 Meson 的 shell 命令的唯一途径吗?我做错了什么?


参考:https://mesonbuild.com/External-commands.html

命令是来自 unspecified 目录的 运行,因此,请尝试指定完整的文件名,例如:

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)