diff options
| author | ruki <[email protected]> | 2025-01-09 00:54:55 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-01-09 00:54:55 +0800 |
| commit | 7a4c72e8385d63e1588f8a1cd8b482cf8825d5fb (patch) | |
| tree | bce56e9961f650138c111d09a029961154faeaf4 | |
| parent | 279b1f07740e235a0a5fddcf46937b829fd160d2 (diff) | |
improve is_config
| -rw-r--r-- | xmake/core/project/config.lua | 35 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 7 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/is_config.lua | 17 |
3 files changed, 38 insertions, 21 deletions
diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua index 789eada09..3e53fe388 100644 --- a/xmake/core/project/config.lua +++ b/xmake/core/project/config.lua @@ -52,6 +52,23 @@ function config._use_workingdir() return use_workingdir end +-- the current config is belong to the given config values? +function config._is_value(value, ...) + if value == nil then + return false + end + + value = tostring(value) + for _, v in ipairs(table.pack(...)) do + -- escape '-' + v = tostring(v) + if value == v or value:find("^" .. v:gsub("%-", "%%-") .. "$") then + return true + end + end + return false +end + -- get the current given configuration function config.get(name) local value = nil @@ -278,24 +295,6 @@ function config.is_cross() return is_cross(config.plat(), config.arch()) end --- the current config is belong to the given config values? -function config.is_value(name, ...) - local value = config.get(name) - if value == nil then - return false - end - - value = tostring(value) - for _, v in ipairs(table.pack(...)) do - -- escape '-' - v = tostring(v) - if value == v or value:find("^" .. v:gsub("%-", "%%-") .. "$") then - return true - end - end - return false -end - -- dump the configure function config.dump() if not option.get("quiet") then diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 57655ee0e..b102f4423 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -108,7 +108,12 @@ end -- the current config is belong to the given config values? function project._api_is_config(interp, name, ...) - return config.is_value(name, ...) + local value = config.get(name) + local namespace = interp:namespace() + if value == nil and namespace then + value = config.get(namespace .. "::" .. name) + end + return config._is_value(value, ...) end -- some configs are enabled? diff --git a/xmake/core/sandbox/modules/is_config.lua b/xmake/core/sandbox/modules/is_config.lua index 017f707f4..9cc4ec18b 100644 --- a/xmake/core/sandbox/modules/is_config.lua +++ b/xmake/core/sandbox/modules/is_config.lua @@ -18,6 +18,19 @@ -- @file is_config.lua -- --- return module -return require("project/config").is_value +local config = require("project/config") +local sandbox = require("sandbox/sandbox") + +return function (name, ...) + local namespace + local instance = sandbox.instance() + if instance then + namespace = instance:namespace() + end + local value = config.get(name) + if value == nil and namespace then + value = config.get(namespace .. "::" .. name) + end + return config._is_value(value, ...) +end |
