From 698ba0673743e5d260882432b8ba1aff8193c2ed Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 1 Sep 2016 14:39:35 +0800 Subject: fix curdir bug for xmake.lua --- xmake/core/base/interpreter.lua | 9 +++++++++ xmake/core/base/os.lua | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 8fb1d8afd..7b2cc9e2c 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -242,12 +242,21 @@ function interpreter:_api_builtin_add_subdirfiles(isdirs, ...) -- clear the current scope, force to enter root scope scopes._CURRENT = nil + -- save the current directory + local olddir = os.curdir() + + -- enter the script directory + os.cd(path.directory(file)) + -- done interpreter local ok, errors = xpcall(script, interpreter._traceback) if not ok then os.raise(errors) end + -- leave the script directory + os.cd(olddir) + -- restore the previous scope kind scopes._CURRENT_KIND = scope_kind_prev diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 0389fb75a..bebf04fc7 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -224,7 +224,7 @@ function os.cd(dir) return false, string.format("not found the previous directory %s", os.strerror()) end end - + -- is directory? if os.isdir(dir) then -- cgit v1.3.1