summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-05-23 00:46:44 +0800
committerruki <[email protected]>2019-05-22 22:40:27 +0800
commit744ce235235533e695430daa1f96cbd35c69ac01 (patch)
tree8ed3e616bbc31655eb6d8a369c5eafcba187a528
parentb91f9e89bed5bf3db0f7a0e78b6c69666eab21eb (diff)
add ndk_stdcxx option for ndk
-rw-r--r--xmake/core/base/interpreter.lua2
-rw-r--r--xmake/core/base/os.lua9
-rw-r--r--xmake/core/base/utils.lua30
-rw-r--r--xmake/core/sandbox/modules/import/core/sandbox/module.lua2
-rw-r--r--xmake/core/sandbox/modules/try.lua2
-rw-r--r--xmake/core/sandbox/sandbox.lua4
-rw-r--r--xmake/core/ui/application.lua3
-rw-r--r--xmake/modules/detect/sdks/find_ndk.lua2
-rw-r--r--xmake/platforms/android/load.lua2
-rw-r--r--xmake/platforms/android/xmake.lua1
10 files changed, 48 insertions, 9 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index 098e0ab2f..bcf60dd5b 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -658,7 +658,7 @@ function interpreter.new()
if script then
-- load module
- local ok, results = xpcall(script, debug.traceback)
+ local ok, results = utils.trycall(script)
if not ok then
os.raise(results)
end
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 3daebd280..09274450d 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -711,8 +711,15 @@ function os.raise(msg, ...)
io.flush()
-- raise it
- if msg then
+ if type(msg) == "string" then
error(string.tryformat(msg, ...))
+ elseif type(msg) == "table" then
+ local errobjstr, errors = string.serialize(msg, true)
+ if errobjstr then
+ error("[@encode(error)]: " .. errobjstr)
+ else
+ error(errors)
+ end
else
error()
end
diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua
index 6f0f71f5c..c8743a58f 100644
--- a/xmake/core/base/utils.lua
+++ b/xmake/core/base/utils.lua
@@ -179,5 +179,35 @@ function utils.ifelse(a, b, c)
if a then return b else return c end
end
+-- try to call script
+function utils.trycall(script, traceback, ...)
+ return xpcall(script, function (errors)
+
+ -- get traceback
+ traceback = traceback or debug.traceback
+
+ -- decode it if errors is encoded table string
+ if errors then
+ local _, pos = errors:find("[@encode(error)]: ", 1, true)
+ if pos then
+ local deserrs
+ local rawerrs = errors:sub(pos + 1)
+ errors, deserrs = rawerrs:deserialize()
+ if not errors then
+ errors = deserrs
+ end
+ if type(errors) == "table" then
+ setmetatable(errors, { __tostring = function (self)
+ return rawerrs
+ end
+ })
+ end
+ return errors
+ end
+ end
+ return traceback(errors)
+ end, ...)
+end
+
-- return module
return utils
diff --git a/xmake/core/sandbox/modules/import/core/sandbox/module.lua b/xmake/core/sandbox/modules/import/core/sandbox/module.lua
index a4915f1aa..996efd0f5 100644
--- a/xmake/core/sandbox/modules/import/core/sandbox/module.lua
+++ b/xmake/core/sandbox/modules/import/core/sandbox/module.lua
@@ -89,7 +89,7 @@ function core_sandbox_module._loadfile(filepath, instance)
end
-- load module without sandbox
- local ok, result = xpcall(script, debug.traceback)
+ local ok, result = utils.trycall(script)
if not ok then
return nil, result
end
diff --git a/xmake/core/sandbox/modules/try.lua b/xmake/core/sandbox/modules/try.lua
index 01c39f656..cf0098375 100644
--- a/xmake/core/sandbox/modules/try.lua
+++ b/xmake/core/sandbox/modules/try.lua
@@ -97,7 +97,7 @@ function sandbox_try.try(block)
local funcs = table.join(block[2] or {}, block[3] or {})
-- try to call it
- local ok, errors_or_r1, r2, r3, r4, r5, r6 = xpcall(try, sandbox_try._traceback)
+ local ok, errors_or_r1, r2, r3, r4, r5, r6 = utils.trycall(try, sandbox_try._traceback)
if not ok then
-- run the catch function
diff --git a/xmake/core/sandbox/sandbox.lua b/xmake/core/sandbox/sandbox.lua
index 92f729076..7f564f053 100644
--- a/xmake/core/sandbox/sandbox.lua
+++ b/xmake/core/sandbox/sandbox.lua
@@ -121,7 +121,7 @@ function sandbox._new()
if script then
-- load module
- local ok, results = xpcall(script, debug.traceback)
+ local ok, results = utils.trycall(script)
if not ok then
os.raise(results)
end
@@ -177,7 +177,7 @@ end
-- load script in the sandbox
function sandbox.load(script, ...)
- return xpcall(script, sandbox._traceback, ...)
+ return utils.trycall(script, sandbox._traceback, ...)
end
-- bind self instance to the given script or envirnoment
diff --git a/xmake/core/ui/application.lua b/xmake/core/ui/application.lua
index ab484a4d4..0c15b87d6 100644
--- a/xmake/core/ui/application.lua
+++ b/xmake/core/ui/application.lua
@@ -20,6 +20,7 @@
-- load modules
local os = require("base/os")
+local utils = require("base/utils")
local log = require("ui/log")
local rect = require("ui/rect")
local event = require("ui/event")
@@ -104,7 +105,7 @@ function application:run(...)
end
-- run application
- local ok, errors = xpcall(runner, debug.traceback)
+ local ok, errors = utils.trycall(runner)
-- exit curses
if not ok then
diff --git a/xmake/modules/detect/sdks/find_ndk.lua b/xmake/modules/detect/sdks/find_ndk.lua
index 16631fe89..81269cc37 100644
--- a/xmake/modules/detect/sdks/find_ndk.lua
+++ b/xmake/modules/detect/sdks/find_ndk.lua
@@ -38,7 +38,7 @@ function _find_ndkdir(sdkdir)
-- get ndk directory
if sdkdir and os.isdir(sdkdir) then
- return sdkdir
+ return path.translate(sdkdir)
end
end
diff --git a/xmake/platforms/android/load.lua b/xmake/platforms/android/load.lua
index 475315b72..a5259ee02 100644
--- a/xmake/platforms/android/load.lua
+++ b/xmake/platforms/android/load.lua
@@ -159,7 +159,7 @@ function main(platform)
end
-- only for c++ stl
- if cxxstl_sdkdir and os.isdir(cxxstl_sdkdir) then
+ if config.get("ndk_stdcxx") and cxxstl_sdkdir and os.isdir(cxxstl_sdkdir) then
-- the toolchains archs
local toolchains_archs =
diff --git a/xmake/platforms/android/xmake.lua b/xmake/platforms/android/xmake.lua
index 87345da94..2ea1f9a89 100644
--- a/xmake/platforms/android/xmake.lua
+++ b/xmake/platforms/android/xmake.lua
@@ -48,6 +48,7 @@ platform("android")
, {nil, "ndk_sdkver", "kv", "auto", "The SDK Version for NDK" }
, {nil, "android_sdk", "kv", nil, "The Android SDK Directory" }
, {nil, "build_toolver", "kv", nil, "The Build Tool Version of Android SDK" }
+ , {nil, "ndk_stdcxx", "kv", true, "Use stdc++ library for NDK" }
}
, global =