Skip to content

Commit

Permalink
improve add_requires #5727
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Oct 18, 2024
1 parent 86627f2 commit 4d8f21a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions xmake/modules/private/action/require/impl/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4d8f21a

Please sign in to comment.