diff options
| author | ruki <[email protected]> | 2025-01-09 00:44:44 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-01-09 00:44:44 +0800 |
| commit | a74774a809de30e6e473157233aa47bbabb272d4 (patch) | |
| tree | 772dce6b904c7693c1c19695b172eee1a43df2f8 | |
| parent | 672112971ac26e4ed5bc5789938a82e8dbc22c86 (diff) | |
improve has_config
| -rw-r--r-- | xmake/core/base/interpreter.lua | 5 | ||||
| -rw-r--r-- | xmake/core/project/config.lua | 15 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 2 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/has_config.lua | 6 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/base/process.lua | 4 | ||||
| -rw-r--r-- | xmake/core/sandbox/sandbox.lua | 11 |
6 files changed, 24 insertions, 19 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index f09f544fc..72886e0d2 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -820,6 +820,11 @@ function interpreter:mtimes() return self._PRIVATE._MTIMES end +-- get current namespace +function interpreter:namespace() + return self._PRIVATE._NAMESPACE_STR +end + -- get namespaces function interpreter:namespaces() local namespaces = self._PRIVATE._NAMESPACES diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua index 650bbc4a6..d4d510c09 100644 --- a/xmake/core/project/config.lua +++ b/xmake/core/project/config.lua @@ -297,10 +297,17 @@ function config.is_value(name, ...) end -- has the given configs? -function config.has(...) - for _, name in ipairs(table.pack(...)) do - if name and type(name) == "string" and config.get(name) then - return true +function config.has(names, opt) + opt = opt or {} + for _, name in ipairs(names) do + if name and type(name) == "string" then + local value = config.get(name) + if value == nil and opt.namespace then + value = config.get(opt.namespace .. "::" .. name) + end + if value then + return true + end end end return false diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index a41ecc0cf..61c1361db 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -113,7 +113,7 @@ end -- some configs are enabled? function project._api_has_config(interp, ...) - return config.has(...) + return config.has(table.pack(...), {namespace = interp:namespace()}) end -- some packages are enabled? diff --git a/xmake/core/sandbox/modules/has_config.lua b/xmake/core/sandbox/modules/has_config.lua index c6b68fc9e..1dc36278a 100644 --- a/xmake/core/sandbox/modules/has_config.lua +++ b/xmake/core/sandbox/modules/has_config.lua @@ -19,5 +19,9 @@ -- -- return module -return require("project/config").has +local config = require("project/config") + +return function (...) + return config.has(table.pack(...)) +end diff --git a/xmake/core/sandbox/modules/import/core/base/process.lua b/xmake/core/sandbox/modules/import/core/base/process.lua index 884ae9ebe..531ae0bd6 100644 --- a/xmake/core/sandbox/modules/import/core/base/process.lua +++ b/xmake/core/sandbox/modules/import/core/base/process.lua @@ -25,8 +25,8 @@ local raise = require("sandbox/modules/raise") local vformat = require("sandbox/modules/vformat") -- define module -local sandbox_core_base_process = sandbox_core_base_process or {} -local sandbox_core_base_instance = sandbox_core_base_instance or {} +local sandbox_core_base_process = sandbox_core_base_process or {} +local sandbox_core_base_instance = sandbox_core_base_instance or {} sandbox_core_base_process._subprocess = sandbox_core_base_process._subprocess or process._subprocess -- wait subprocess diff --git a/xmake/core/sandbox/sandbox.lua b/xmake/core/sandbox/sandbox.lua index 1e0817a4e..9bad3eb9f 100644 --- a/xmake/core/sandbox/sandbox.lua +++ b/xmake/core/sandbox/sandbox.lua @@ -79,12 +79,8 @@ function sandbox._traceback(errors) else results = results .. string.format(" [%s:%d]:\n", info.short_src, info.currentline) end - - -- next level = level + 1 end - - -- ok? return results end @@ -118,20 +114,13 @@ end -- new a sandbox instance with the given script function sandbox.new(script, filter, rootdir) - - -- check assert(script) -- new instance local self = sandbox._new() - - -- check assert(self and self._PUBLIC and self._PRIVATE) - -- save filter self._PRIVATE._FILTER = filter - - -- save root directory self._PRIVATE._ROOTDIR = rootdir -- invalid script? |
