From 116c0f260725e26ae5de6207698e94cfaee7c5d5 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Mon, 26 Aug 2019 17:00:08 +0800 Subject: fix XMAKE_CONFIGDIR --- xmake/core/base/serialize.lua | 53 +++++++++++++++------- xmake/plugins/project/vsxmake/vsproj/Xmake.props | 2 +- xmake/plugins/project/vsxmake/vsproj/Xmake.targets | 7 +++ 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/xmake/core/base/serialize.lua b/xmake/core/base/serialize.lua index 9dd9888e5..7c5c2200c 100644 --- a/xmake/core/base/serialize.lua +++ b/xmake/core/base/serialize.lua @@ -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 @@ -206,11 +212,11 @@ function serialize._resolveref(root, fenv, ...) 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" + return nil, "path segments should be string or number" end if type(pos) ~= "table" then - table.insert(path, 1, "") - return nil, "unable to resolve path: " .. table.concat(path, ".", 1, i) .. " is " .. tostring(pos) + local vpre = serialize._make(v, {}) + return nil, string.format("unable to resolve [%s] in /%s, which is %s", vpre, table.concat(path, "/", 1, i - 1), pos) end pos = pos[v] 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) +-- path path key for current item +function serialize._resolvestub(object, root, fenv, path) 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 end - return nil, errors or result or "unspecified error" + + -- resolve & concat path only if error occurs + local pathseg = {} + 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(pathseg, 1, p) + level = level + 1 + end + -- 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(pathseg, "/"), 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, "") end else -- error 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 @@ $(XmakeBuilDir)\$(XmakePlat)\$(XmakeArch)\$(XmakeMode) $(XMAKE_CONFIGDIR) - $(XmakeProjectDir)\.xmake + $(XmakeProjectDir) $(XmakeTargetDir) 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 Condition="$(XmakeDiagnosis)"> + $(_XmakeEnv) + echo XMAKE_CONFIGDIR=%25XMAKE_CONFIGDIR%25 + echo XMAKE_PROGRAM_DIR=%25XMAKE_PROGRAM_DIR%25 + echo CD=%25CD%25 + chcp + -- cgit v1.3.1 From 4c7f077a102f35428766bb3fddb8a93e30313cc1 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Mon, 26 Aug 2019 17:12:12 +0800 Subject: fix --- xmake/core/base/serialize.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xmake/core/base/serialize.lua b/xmake/core/base/serialize.lua index 7c5c2200c..5ffb6b818 100644 --- a/xmake/core/base/serialize.lua +++ b/xmake/core/base/serialize.lua @@ -216,7 +216,9 @@ function serialize._resolveref(root, fenv, ...) end if type(pos) ~= "table" then local vpre = serialize._make(v, {}) - return nil, string.format("unable to resolve [%s] in /%s, which is %s", vpre, table.concat(path, "/", 1, i - 1), pos) + table.insert(path, 1, "") + local pathstr = table.concat(path, "/", 1, i) + return nil, string.format("unable to resolve [%s] in %s, which is %s", vpre, pathstr, pos) end pos = pos[v] end @@ -335,7 +337,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 -- cgit v1.3.1 From 172076db9fa929c5b6dd20a733d15cf28ef092aa Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Mon, 26 Aug 2019 18:24:26 +0800 Subject: rename params --- xmake/core/base/dump.lua | 1 + xmake/core/base/serialize.lua | 50 +++++++++++----------- xmake/core/base/utils.lua | 2 - .../modules/import/core/sandbox/sandbox.lua | 2 - 4 files changed, 25 insertions(+), 30 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 5ffb6b818..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) @@ -191,36 +191,34 @@ function serialize._resolvefunction(root, fenv, bytecode) 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("", ...) 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 + 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 - local vpre = serialize._make(v, {}) - table.insert(path, 1, "") - local pathstr = table.concat(path, "/", 1, i) + 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 @@ -355,8 +353,8 @@ end -- @param object object to search stubs -- root root object -- fenv fenv of deserialzer caller --- path path key for current item -function serialize._resolvestub(object, root, fenv, path) +-- pathseg path key for current item +function serialize._resolvestub(object, root, fenv, pathseg) if type(object) ~= "table" then return object end @@ -364,23 +362,23 @@ function serialize._resolvestub(object, root, fenv, path) if object.isstub == stub.isstub then 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 pathseg = {} + 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(pathseg, 1, p) + table.insert(pathsegs, 1, p) level = level + 1 end -- 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(pathseg, "/"), errmsg) + 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 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 -- cgit v1.3.1