From eecb073d6ca8b04168ebd829d04a7fc340731d1d Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 22 Jun 2016 19:42:00 +0800 Subject: fix add_subdirs scope bug --- xmake/core/base/interpreter.lua | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 -- cgit v1.3.1