diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua index 789eada094..3e53fe3884 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 57655ee0e5..b102f44239 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 017f707f4e..9cc4ec18b8 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