在介子中,您可以测试项目中是否存在目录吗?

In meson can you test for presence of a directory in your project?

使用介子构建,是否可以测试我的项目中是否存在目录?

例如,我通常将验收测试放在我的单元测试旁边,文件夹结构如下:

library/
        header.hp
        src/
            lib.cpp
        tests/
              acceptance_test/
              unit_test/ 

我并不总是进行验收测试,如果没有必要,我想避免在其中放置 meson.build 文件。如果目录 acceptance_test/ 存在,我宁愿有一个条件 subdir('acceptance_test')

查看 reference manual,我没有看到任何对此的直接支持。

您可以使用 run_command,做类似

的事情
if run_command('[', '-d', dirname, ']').returncode() == 0
    message('directory exists')
endif

但是,当然,这有不能跨平台工作的缺点。

更新: 从Meson v0.53.0开始,可以使用Filesystem模块:

fs = import('fs')
if fs.is_dir('<dirname>')
  message('directory exists')
endif

这是可移植的,不依赖于 shell。