如何从 meson_options.txt 获取所有选项

问题描述 投票:0回答:1

是否有任何工具(cli、在线等)可以从一个

meson_options.txt
文件获取所有使用默认值填充的选项?

例如

$ meson_get_all_options
CMD -Doption=true -Doption2=42
meson-build
1个回答
0
投票
  1. 运行
    meson setup
    创建默认构建配置
  2. 运行
    meson introspect --buildoptions
    以 JSON 格式转储所有选项
  3. 解析 JSON 输出
  4. 使用
    section=user
  5. 过滤记录

Lua 中的示例代码:

-- some JSON decoder required
local json = require"json"

local projdir = "/path/to/project"
local tempdir = "/tmp/build"

assert(os.execute(string.format("meson setup %s %s >/dev/null", tempdir, projdir)))

local handle = io.popen(string.format("meson introspect %s --buildoptions", tempdir))
local data = json.decode(handle:read("*all"))
handle:close()

for i, v in ipairs(data) do
    if v.section == "user" then
        io.write(string.format("-D%s=%s ", v.name, v.value))
    end
end

os.execute(string.format("rm -r %s", tempdir))


© www.soinside.com 2019 - 2024. All rights reserved.