summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-01-23 16:31:19 +0800
committerruki <[email protected]>2016-02-15 19:10:25 +0800
commitfb773468c1293a6196f890c9a2fd70b6844bf3f2 (patch)
tree16b303c28067a7c9d8442f1b0b754235a0460015
parentc323661dd1a8c08ad20468b02da5c49b90be44dc (diff)
fix scope bug for interpreter
-rw-r--r--xmake/core/base/interpreter.lua53
-rw-r--r--xmake/core/base/project.lua26
2 files changed, 77 insertions, 2 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index e29d6b5bd..8866b01cd 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -28,6 +28,7 @@ local os = require("base/os")
local path = require("base/path")
local table = require("base/table")
local utils = require("base/utils")
+local string = require("base/string")
-- traceback
function interpreter._traceback(errors)
@@ -117,6 +118,11 @@ function interpreter._api_register_xxx_values(self, scope_kind, action, prefix,
local root = scopes._ROOT[scope_kind] or {}
scopes._ROOT[scope_kind] = root
+ -- clear the current scope if be not belong to the current scope kind
+ if scopes._CURRENT and scopes._CURRENT_KIND ~= scope_kind then
+ scopes._CURRENT = nil
+ end
+
-- the current scope
local scope = scopes._CURRENT or root
assert(scope)
@@ -391,7 +397,11 @@ function interpreter.init(rootdir)
interp:api_register_builtin("print", print)
interp:api_register_builtin("pairs", pairs)
interp:api_register_builtin("ipairs", ipairs)
- interp:api_register_builtin("format", string.format)
+
+ -- register the builtin modules for lua
+ interp:api_register_builtin("path", path)
+ interp:api_register_builtin("table", table)
+ interp:api_register_builtin("string", string)
-- ok?
return interp
@@ -538,6 +548,9 @@ function interpreter.api_register_set_scope(self, ...)
-- save the current scope
scopes._CURRENT = scope_for_kind[scope_name]
+ -- update the current scope kind
+ scopes._CURRENT_KIND = scope_kind
+
end
-- register implementation
@@ -570,6 +583,9 @@ function interpreter.api_register_add_scope(self, ...)
-- save the current scope
scopes._CURRENT = scope_for_kind[scope_name]
+ -- update the current scope kind
+ scopes._CURRENT_KIND = scope_kind
+
end
-- register implementation
@@ -723,5 +739,40 @@ function interpreter.api_call(self, apiname, ...)
return apifunc(...)
end
+-- save the current scope
+function interpreter.scope_save(self)
+
+ -- check
+ assert(self and self._PRIVATE)
+
+ -- the scopes
+ local scopes = self._PRIVATE._SCOPES
+ assert(scopes)
+
+ -- the current scope
+ local scope = {}
+ scope._CURRENT = scopes._CURRENT
+ scope._CURRENT_KIND = scopes._CURRENT_KIND
+
+ -- ok?
+ return scope
+end
+
+-- restore the current scope
+function interpreter.scope_restore(self, scope)
+
+ -- check
+ assert(self and self._PRIVATE and scope)
+
+ -- the scopes
+ local scopes = self._PRIVATE._SCOPES
+ assert(scopes)
+
+ -- restore it
+ scopes._CURRENT = scope._CURRENT
+ scopes._CURRENT_KIND = scope._CURRENT_KIND
+
+end
+
-- return module: interpreter
return interpreter
diff --git a/xmake/core/base/project.lua b/xmake/core/base/project.lua
index 3981de2c0..dad2d98c0 100644
--- a/xmake/core/base/project.lua
+++ b/xmake/core/base/project.lua
@@ -151,6 +151,9 @@ function project._api_add_cfunc(interp, module, alias, links, includes, cfunc)
define = string.format("$(prefix)_HAVE_%s", utils.ifelse(alias, alias, cfunc:upper()))
end
+ -- save the current scope
+ local scope = interp:scope_save()
+
-- make option
interp:api_call("add_option", name)
interp:api_call("set_option_category", "cfuncs")
@@ -159,7 +162,10 @@ function project._api_add_cfunc(interp, module, alias, links, includes, cfunc)
if includes then interp:api_call("add_option_cincludes", includes) end
interp:api_call("add_option_defines_h_if_ok", define)
- -- add this option
+ -- restore the current scope
+ interp:scope_restore(scope)
+
+ -- add this option to the current scope
interp:api_call("add_options", name)
end
@@ -191,6 +197,9 @@ function project._api_add_cfuncs(interp, module, links, includes, ...)
define = string.format("$(prefix)_HAVE_%s", cfunc:upper())
end
+ -- save the current scope
+ local scope = interp:scope_save()
+
-- make option
interp:api_call("add_option", name)
interp:api_call("set_option_category", "cfuncs")
@@ -199,6 +208,9 @@ function project._api_add_cfuncs(interp, module, links, includes, ...)
if includes then interp:api_call("add_option_cincludes", includes) end
interp:api_call("add_option_defines_h_if_ok", define)
+ -- restore the current scope
+ interp:scope_restore(scope)
+
-- add this option
interp:api_call("add_options", name)
end
@@ -226,6 +238,9 @@ function project._api_add_cxxfunc(interp, module, alias, links, includes, cxxfun
define = string.format("$(prefix)_HAVE_%s", utils.ifelse(alias, alias, cxxfunc:upper()))
end
+ -- save the current scope
+ local scope = interp:scope_save()
+
-- make option
interp:api_call("add_option", name)
interp:api_call("set_option_category", "cxxfuncs")
@@ -234,6 +249,9 @@ function project._api_add_cxxfunc(interp, module, alias, links, includes, cxxfun
if includes then interp:api_call("add_option_cxxincludes", includes) end
interp:api_call("add_option_defines_h_if_ok", define)
+ -- restore the current scope
+ interp:scope_restore(scope)
+
-- add this option
interp:api_call("add_options", name)
end
@@ -266,6 +284,9 @@ function project._api_add_cxxfuncs(interp, module, links, includes, ...)
define = string.format("$(prefix)_HAVE_%s", cxxfunc:upper())
end
+ -- save the current scope
+ local scope = interp:scope_save()
+
-- make option
interp:api_call("add_option", name)
interp:api_call("set_option_category", "cxxfuncs")
@@ -274,6 +295,9 @@ function project._api_add_cxxfuncs(interp, module, links, includes, ...)
if includes then interp:api_call("add_option_cxxincludes", includes) end
interp:api_call("add_option_defines_h_if_ok", define)
+ -- restore the current scope
+ interp:scope_restore(scope)
+
-- add this option
interp:api_call("add_options", name)
end