diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 72886e0d2e..4e5aaf8c79 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -647,7 +647,7 @@ function interpreter:_script(script) end -- make sandbox instance with the given script - local instance, errors = sandbox.new(script, self:filter(), self:scriptdir()) + local instance, errors = sandbox.new(script, {filter = self:filter(), rootdir = self:scriptdir(), namespace = self:namespace()}) if not instance then return nil, errors end diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua index 7258aeb211..a3fde19138 100644 --- a/xmake/core/base/task.lua +++ b/xmake/core/base/task.lua @@ -221,17 +221,12 @@ end -- bind script with a sandbox instance function task._bind_script(interp, script) - - -- make sandbox instance with the given script - local instance, errors = sandbox.new(script, interp:filter(), interp:rootdir()) + local instance, errors = sandbox.new(script, { + filter = interp:filter(), rootdir = interp:rootdir(), namespace = interp:namespace()}) if not instance then return nil, errors end - - -- check assert(instance:script()) - - -- update option script return instance:script() end diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index bb12282e1e..741ca318c7 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -2945,7 +2945,7 @@ function package.load_from_system(packagename) end -- make sandbox instance with the given script - instance, errors = sandbox.new(on_install, interp:filter()) + instance, errors = sandbox.new(on_install, {filter = interp:filter(), namespace = interp:namespace()}) if not instance then return nil, errors end diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 61c1361dbd..ee2b55a636 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -979,8 +979,16 @@ function project.ordertargets() end -- get the given option -function project.option(name) - return project.options()[name] +function project.option(name, opt) + opt = opt or {} + local options = project.options() + if options then + local o = options[name] + if not o and opt.namespace then + o = options[opt.namespace .. "::" .. name] + end + return o + end end -- get options diff --git a/xmake/core/sandbox/modules/has_config.lua b/xmake/core/sandbox/modules/has_config.lua index 1dc36278ac..2cf5a86d03 100644 --- a/xmake/core/sandbox/modules/has_config.lua +++ b/xmake/core/sandbox/modules/has_config.lua @@ -20,8 +20,14 @@ -- return module local config = require("project/config") +local sandbox = require("sandbox/sandbox") return function (...) - return config.has(table.pack(...)) + local namespace + local instance = sandbox.instance() + if instance then + namespace = instance:namespace() + end + return config.has(table.pack(...), {namespace = namespace}) end diff --git a/xmake/core/sandbox/sandbox.lua b/xmake/core/sandbox/sandbox.lua index 9bad3eb9f1..2d624da988 100644 --- a/xmake/core/sandbox/sandbox.lua +++ b/xmake/core/sandbox/sandbox.lua @@ -107,21 +107,20 @@ function sandbox._new() -- bind instance to the public script envirnoment instance:bind(instance._PUBLIC) - - -- ok? return instance end -- new a sandbox instance with the given script -function sandbox.new(script, filter, rootdir) - assert(script) +function sandbox.new(script, opt) + opt = opt or {} -- new instance local self = sandbox._new() assert(self and self._PUBLIC and self._PRIVATE) - self._PRIVATE._FILTER = filter - self._PRIVATE._ROOTDIR = rootdir + self._PRIVATE._FILTER = opt.filter + self._PRIVATE._ROOTDIR = opt.rootdir + self._PRIVATE._NAMESPACE = opt.namespace -- invalid script? if type(script) ~= "function" then @@ -178,23 +177,17 @@ function sandbox:fork(script, rootdir) -- init a new sandbox instance local instance = sandbox._new() - - -- check assert(instance and instance._PUBLIC and instance._PRIVATE) - -- inherit the filter instance._PRIVATE._FILTER = self:filter() - - -- inherit the root directory instance._PRIVATE._ROOTDIR = rootdir or self:rootdir() + instance._PRIVATE._NAMESPACE = self:namespace() -- bind public scope if script then setfenv(script, instance._PUBLIC) instance._PRIVATE._SCRIPT = script end - - -- ok? return instance end @@ -246,6 +239,12 @@ function sandbox:rootdir() return self._PRIVATE._ROOTDIR end +-- get current namespace +function sandbox:namespace() + assert(self and self._PRIVATE) + return self._PRIVATE._NAMESPACE +end + -- get current instance in the sandbox modules function sandbox.instance(script)