From 4d8f21ac73053661c26aac2db376517ae0890340 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 19 Oct 2024 00:53:50 +0800 Subject: [PATCH] improve add_requires #5727 --- .../private/action/require/impl/package.lua | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 5fc10ee0ed..86df86bfb7 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -85,6 +85,10 @@ end -- -- {build = true}: always build packages, we do not use the precompiled artifacts -- +-- simply configs as string: +-- add_requires("boost[iostreams,system,thread,key=value] >=1.78.0") +-- add_requires("boost[iostreams,thread=n] >=1.78.0") +-- function _parse_require(require_str) -- split package and version info @@ -144,6 +148,30 @@ function _load_require(require_str, requires_extra, parentinfo) require_extra = requires_extra[require_str] or {} end + -- parse configs from package name + -- @see https://github.com/xmake-io/xmake/issues/5727#issuecomment-2421040107 + -- + -- e.g. + -- add_requires("boost[iostreams,system,thread,key=value] >=1.78.0") + -- + local packagename_raw, configs_str = packagename:match("(.+)%[(.+)%]") + if packagename_raw and configs_str then + packagename = packagename_raw + local splitinfo = configs_str:split(",", {plain = true}) + for _, v in ipairs(splitinfo) do + local parts = v:split("=", {plain = true}) + local k = parts[1] + v = parts[2] + require_extra.configs = require_extra.configs or {} + local configs = require_extra.configs + if v then + configs[k] = option.boolean(v) + else + configs[k] = true + end + end + end + -- get required building configurations -- we need to clone a new configs object, because the whole requireinfo will be modified later. -- @see https://github.com/xmake-io/xmake-repo/pull/2067