【问题标题】:meson: copy script to build directory介子:将脚本复制到构建目录
【发布时间】:2021-08-05 03:39:44
【问题描述】:

我有 C 和 shell 源文件作为测试。 Meson unit tests 预计将从构建目录运行。从我的 C 源编译的二进制文件我会自动复制到构建目录(指定为 executable()),如何复制那里的 shell 脚本?

或者我应该从源目录运行/获取它们,例如

test = join_paths(meson.source_root(), 'tests/run.sh')
run_command(test, "--foo", "bar")

或者使用find_program()

test = find_program('run.sh')
run_command(test, "--foo", "bar")

【问题讨论】:

    标签: shell command file-copying meson-build


    【解决方案1】:

    更规范的做法是使用“dummy”custom_target

    scipt_name = 'run.sh'
    custom_target('copy script',
      input : script_name,
      output :  script_name,
      command : ['cp', '@INPUT@', '@OUTPUT@'],
      install : false,
      build_by_default : true)
    

    这更好,因为它会被执行,即在更新时复制;如果您将其添加到 tests 文件夹中的 meson.build - 无需进行路径操作。

    【讨论】:

      【解决方案2】:

      好的,find_program() 在系统中搜索PATH,因此不适合。可能将文件复制到构建目录会更好:

      src = join_paths(meson.source_root(), 'tests/run.sh')
      dest = join_paths(meson.build_root(), 'tests')
      message('copying @0@ to @1@ ...'.format(src, dest))
      run_command('cp', src, dest)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-08-05
        • 1970-01-01
        • 2014-11-22
        • 2011-11-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多