gpt4 book ai didi

meson-build - 如何将 Meson 中的文件复制到子目录

转载 作者:行者123 更新时间:2023-12-03 23:48:17 29 4
gpt4 key购买 nike

我的应用程序使用 Glade 文件并将数据缓存在 JSON 文件中。当我执行以下操作时,只要用户使用 ninja install 安装应用程序,一切都会正常运行。

    #Install cached JSON file
install_data(
join_paths('data', 'dataCache.json'),
install_dir: join_paths('myapp', 'resources')
)
#Install the user interface glade file
install_data(
join_paths('src', 'MainWindow.glade'),
install_dir: join_paths('myapp', 'resources')
)

缺点是用户需要安装应用程序。我希望用户能够使用 ninja 构建应用程序如果他们不想在他们的系统上安装它,则运行它而不安装它。问题是当我做
    #Copy the cached JSON file to the build output directory
configure_file(input : join_paths('data', 'dataCache.json'),
output : join_paths('myapp', 'resources', 'dataCache.json'),
copy: true
)

#Copy the Glade file to the build output directory
configure_file(input : join_paths('src', 'MainWindow.glade'),
output : join_paths('myapp', 'resources', 'MainWindow.glade'),
copy: true
)

我收到 错误:输出文件名不得包含子目录。

有没有办法运行 ninja并让它创建目录 myapp/resources在 build 文件夹中,然后将 Glade 和 JSON 文件复制到那里用作资源?比如让用户运行应用程序而不必做 ninja install ?

最佳答案

您可以通过编写脚本并从 Meson 调用来实现。

例如,在文件 copy.py 中将相对输入和输出路径作为参数:

#!/usr/bin/env python3 

import os, sys, shutil

# get absolute input and output paths
input_path = os.path.join(
os.getenv('MESON_SOURCE_ROOT'),
os.getenv('MESON_SUBDIR'),
sys.argv[1])

output_path = os.path.join(
os.getenv('MESON_BUILD_ROOT'),
os.getenv('MESON_SUBDIR'),
sys.argv[2])

# make sure destination directory exists
os.makedirs(os.path.dirname(output_path), exist_ok=True)

# and finally copy the file
shutil.copyfile(input_path, output_path)

然后在您的 meson.build文件:
copy = find_program('copy.py')

run_command(
copy,
join_paths('src', 'dataCache.json'),
join_paths('myapp', 'resources', 'dataCache.json')
)
run_command(
copy,
join_paths('src', 'MainWindow.glade'),
join_paths('myapp', 'resources', 'MainWindow.glade')
)

关于meson-build - 如何将 Meson 中的文件复制到子目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61103042/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com