summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-08-26 19:17:08 +0800
committerGitHub <[email protected]>2019-08-26 19:17:08 +0800
commitf9fcf32c39743f6df0766ab2de2bdac4ed8948e7 (patch)
treedd72605248ad7b57179dbe3d34ecdb33faba933e
parent9dab7e4739cb4e1d9b51117fbf1932a4b83635cc (diff)
parent172076db9fa929c5b6dd20a733d15cf28ef092aa (diff)
Merge pull request #550 from OpportunityLiu/dev
fix XMAKE_CONFIGDIR
-rw-r--r--xmake/core/base/dump.lua1
-rw-r--r--xmake/core/base/serialize.lua91
-rw-r--r--xmake/core/base/utils.lua2
-rw-r--r--xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua2
-rw-r--r--xmake/plugins/project/vsxmake/vsproj/Xmake.props2
-rw-r--r--xmake/plugins/project/vsxmake/vsproj/Xmake.targets7
6 files changed, 65 insertions, 40 deletions
diff --git a/xmake/core/base/dump.lua b/xmake/core/base/dump.lua
index cac43ebf3..987f5491f 100644
--- a/xmake/core/base/dump.lua
+++ b/xmake/core/base/dump.lua
@@ -362,6 +362,7 @@ function dump._print(value, indent, verbose)
io.write(indent)
dump._print_scalar(value)
end
+ io.write("\n")
end
return dump._print
diff --git a/xmake/core/base/serialize.lua b/xmake/core/base/serialize.lua
index 9dd9888e5..423c9dc45 100644
--- a/xmake/core/base/serialize.lua
+++ b/xmake/core/base/serialize.lua
@@ -48,12 +48,12 @@ function serialize._makedefault(val, opt)
return tostring(val)
end
-function serialize._maketable(object, opt, level, path, reftab)
+function serialize._maketable(object, opt, level, pathsegs, reftab)
level = level or 0
reftab = reftab or {}
- path = path or {}
- reftab[object] = table.copy(path)
+ pathsegs = pathsegs or {}
+ reftab[object] = table.copy(pathsegs)
-- serialize child items
local childlevel = level + 1
@@ -85,9 +85,9 @@ function serialize._maketable(object, opt, level, path, reftab)
if reftab[v] then
sval, err = serialize._makeref(reftab[v], opt)
else
- table.insert(path, k)
- sval, err = serialize._maketable(v, opt, childlevel, path, reftab)
- table.remove(path)
+ table.insert(pathsegs, k)
+ sval, err = serialize._maketable(v, opt, childlevel, pathsegs, reftab)
+ table.remove(pathsegs)
end
else
sval, err = serialize._make(v, opt)
@@ -153,22 +153,28 @@ function serialize._maketable(object, opt, level, path, reftab)
end
function serialize._makefunction(func, opt)
- local ok, funccode = pcall(serialize._dump, func, opt.strip)
+ local ok, bytecode = pcall(serialize._dump, func, opt.strip)
if not ok then
- return nil, string.format("%s: <%s>", funccode, func)
+ return nil, string.format("%s: <%s>", bytecode, func)
end
- return string.format("func%q", funccode)
+ return string.format("func%q", bytecode)
end
-function serialize._resolvefunction(root, fenv, funccode)
+function serialize._resolvefunction(root, fenv, bytecode)
-- check
- if type(funccode) ~= "string" then
- return nil, "func should called with a string"
+ if type(bytecode) ~= "string" then
+ return nil, string.format("invalid bytecode (string expected, got %s)", type(bytecode))
+ end
+ if not bytecode:startswith("\27LJ") then
+ return nil, "cannot load incompatible bytecode"
end
-- resolve funccode
- local func, err = load(funccode, "=(deserialized code)", "b", fenv)
+ local func, err = load(bytecode, "=(func)", "b", fenv)
if err ~= nil then
+ if err:startswith("(func): ") then
+ err = err:sub(#"(func): " + 1)
+ end
return nil, err
end
@@ -185,34 +191,34 @@ function serialize._resolvefunction(root, fenv, funccode)
return func
end
-function serialize._makeref(path, opt)
+function serialize._makeref(pathsegs, opt)
-- root reference
- if path[1] == nil then
+ if pathsegs[1] == nil then
return "ref()"
end
- local ppath = {}
- for i, v in ipairs(path) do
- ppath[i] = serialize._make(v, opt)
+ for i, v in ipairs(pathsegs) do
+ pathsegs[i] = serialize._make(v, opt)
end
- return "ref(" .. table.concat(ppath, opt.indentstr and ", " or ",") .. ")"
+ return "ref(" .. table.concat(pathsegs, opt.indentstr and ", " or ",") .. ")"
end
function serialize._resolveref(root, fenv, ...)
+ local pathsegs = table.pack("<root>", ...)
local pos = root
- local path = table.pack(...)
- for i = 1, path.n do
- local v = path[i]
- if type(v) ~= "string" and type(v) ~= "number" then
- return nil, "path segments in ref should be string or number"
+ for i = 2, pathsegs.n do
+ local pathseg = pathsegs[i]
+ if type(pathseg) ~= "string" and type(pathseg) ~= "number" then
+ return nil, "path segments should be string or number"
end
if type(pos) ~= "table" then
- table.insert(path, 1, "<root>")
- return nil, "unable to resolve path: " .. table.concat(path, ".", 1, i) .. " is " .. tostring(pos)
+ local vpre = serialize._make(pathseg, {})
+ local pathstr = table.concat(pathsegs, "/", 1, i)
+ return nil, string.format("unable to resolve [%s] in %s, which is %s", vpre, pathstr, pos)
end
- pos = pos[v]
+ pos = pos[pathseg]
end
return pos
end
@@ -329,7 +335,7 @@ end
function stub:__tostring()
local fparams = {}
for i = 1, self.params.n do
- fparams[i] = serialize._make(self.params[i])
+ fparams[i] = serialize._make(self.params[i], {})
end
return string.format("%s(%s)", self.name, table.concat(fparams, ", "))
end
@@ -347,21 +353,36 @@ end
-- @param object object to search stubs
-- root root object
-- fenv fenv of deserialzer caller
-function serialize._resolvestub(object, root, fenv)
+-- pathseg path key for current item
+function serialize._resolvestub(object, root, fenv, pathseg)
if type(object) ~= "table" then
return object
end
if object.isstub == stub.isstub then
- local ok, result, errors = pcall(object, root, fenv)
+ local ok, result_or_errors, errors = pcall(object, root, fenv)
if ok and errors == nil then
- return result
+ return result_or_errors
+ end
+
+ -- resolve & concat path only if error occurs
+ local pathsegs = {}
+ local level = 1
+ while true do
+ if debug.getinfo(level, "f").func ~= serialize._resolvestub then
+ break
+ end
+ local _, p = debug.getlocal(level, 4)
+ table.insert(pathsegs, 1, p)
+ level = level + 1
end
- return nil, errors or result or "unspecified error"
+ -- make error message
+ local errmsg = (ok and errors) or result_or_errors or "unspecified error"
+ return nil, string.format("failed to resolve stub '%s' at %s: %s", object.name, table.concat(pathsegs, "/"), errmsg)
end
for k, v in pairs(object) do
- local result, errors = serialize._resolvestub(v, root, fenv)
+ local result, errors = serialize._resolvestub(v, root, fenv, k)
if errors ~= nil then
return nil, errors
end
@@ -404,7 +425,7 @@ function serialize._load(str)
-- load string
local env = serialize._createenv()
- local script, errors = load(str, "=(deserializing data)", binary and "b" or "t", env)
+ local script, errors = load(str, binary and "=(b)" or "=(t)", binary and "b" or "t", env)
if script then
-- load object
local ok, object = pcall(script)
@@ -412,7 +433,7 @@ function serialize._load(str)
result = object
if env.has_stub then
local fenv = debug.getfenv(debug.getinfo(3, "f").func)
- result, errors = serialize._resolvestub(result, result, fenv)
+ result, errors = serialize._resolvestub(result, result, fenv, "<root>")
end
else
-- error
diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua
index 584af7eb7..58721cc1e 100644
--- a/xmake/core/base/utils.lua
+++ b/xmake/core/base/utils.lua
@@ -61,11 +61,9 @@ function utils.dump(...)
if values_count == 1 then
dump(values[1], indent or "", diagnosis)
- io.write("\n")
else
for i = 1, values_count do
dump(values[i], indent or string.format("%2d: ", i), diagnosis)
- io.write("\n")
end
end
diff --git a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
index a6f19f93d..1ae8a1728 100644
--- a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
+++ b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
@@ -40,7 +40,6 @@ function sandbox_core_sandbox._interactive_dump(...)
local n = values.n
if n <= 1 then
dump(values[1], "< ", diagnosis)
- io.write("\n")
else
local fmt = "< %d: "
if n >= 1000 then
@@ -53,7 +52,6 @@ function sandbox_core_sandbox._interactive_dump(...)
end
for i = 1, n do
dump(values[i], string.format(fmt, i), diagnosis)
- io.write("\n")
end
end
end
diff --git a/xmake/plugins/project/vsxmake/vsproj/Xmake.props b/xmake/plugins/project/vsxmake/vsproj/Xmake.props
index ddec0f57d..873644f52 100644
--- a/xmake/plugins/project/vsxmake/vsproj/Xmake.props
+++ b/xmake/plugins/project/vsxmake/vsproj/Xmake.props
@@ -34,7 +34,7 @@
<XmakeConfigFileDir Condition="'$(XmakeConfigFileDir)' == ''">$(XmakeBuilDir)\$(XmakePlat)\$(XmakeArch)\$(XmakeMode)</XmakeConfigFileDir>
<XmakeConfigDir Condition="'$(XmakeConfigDir)' == ''">$(XMAKE_CONFIGDIR)</XmakeConfigDir>
- <XmakeConfigDir Condition="'$(XmakeConfigDir)' == ''">$(XmakeProjectDir)\.xmake</XmakeConfigDir>
+ <XmakeConfigDir Condition="'$(XmakeConfigDir)' == ''">$(XmakeProjectDir)</XmakeConfigDir>
<XmakeRunDir Condition="'$(XmakeRunDir)' == ''">$(XmakeTargetDir)</XmakeRunDir>
</PropertyGroup>
diff --git a/xmake/plugins/project/vsxmake/vsproj/Xmake.targets b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets
index 62639139d..2c3a89293 100644
--- a/xmake/plugins/project/vsxmake/vsproj/Xmake.targets
+++ b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets
@@ -70,6 +70,13 @@
set XMAKE_CONFIGDIR=$(XmakeConfigDirResolved.TrimEnd('/\'.ToCharArray()))
set XMAKE_PROGRAM_DIR=$(XmakeProgramDirResolved.TrimEnd('/\'.ToCharArray()))
</_XmakeEnv>
+ <_XmakeEnv Condition="$(XmakeDiagnosis)">
+ $(_XmakeEnv)
+ echo XMAKE_CONFIGDIR=%25XMAKE_CONFIGDIR%25
+ echo XMAKE_PROGRAM_DIR=%25XMAKE_PROGRAM_DIR%25
+ echo CD=%25CD%25
+ chcp
+ </_XmakeEnv>
</PropertyGroup>
<Target Name="_XmakeProjCheck">