summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xmake/core/base/interpreter.lua18
1 files changed, 17 insertions, 1 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index 1152aee97..2c13e811a 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -194,6 +194,10 @@ function interpreter:_api_builtin_add_subdirfiles(isdirs, ...)
local curfile = self._PRIVATE._CURFILE
assert(curfile)
+ -- the scopes
+ local scopes = self._PRIVATE._SCOPES
+ assert(scopes)
+
-- get all subpathes
local subpathes = self:_api_translate_pathes(...)
@@ -229,8 +233,14 @@ function interpreter:_api_builtin_add_subdirfiles(isdirs, ...)
-- bind public scope
setfenv(script, self._PUBLIC)
+ -- save the previous scope
+ local scope_prev = scopes._CURRENT
+
+ -- save the previous scope kind
+ local scope_kind_prev = scopes._CURRENT_KIND
+
-- clear the current scope, force to enter root scope
- self._PRIVATE._SCOPES._CURRENT = nil
+ scopes._CURRENT = nil
-- done interpreter
local ok, errors = xpcall(script, interpreter._traceback)
@@ -238,6 +248,12 @@ function interpreter:_api_builtin_add_subdirfiles(isdirs, ...)
os.raise(errors)
end
+ -- restore the previous scope kind
+ scopes._CURRENT_KIND = scope_kind_prev
+
+ -- restore the previous scope
+ scopes._CURRENT = scope_prev
+
-- get mtime of the file
self._PRIVATE._MTIMES[path.relative(file, self._PRIVATE._ROOTDIR)] = os.mtime(file)
else