summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-16 16:28:02 +0800
committerruki <[email protected]>2020-02-16 16:28:02 +0800
commit8368581d63ff27a0edc3928a8a391b2cf3e1e4bc (patch)
treeded2dcd7677beeee210237e6261002e1e3c20c38
parent5b53e98c61bda63722bffd82dad88778a886a6e1 (diff)
improve 'require --extra'
-rw-r--r--xmake/actions/require/install.lua10
-rw-r--r--xmake/actions/require/xmake.lua2
-rw-r--r--xmake/plugins/lua/main.lua11
3 files changed, 15 insertions, 8 deletions
diff --git a/xmake/actions/require/install.lua b/xmake/actions/require/install.lua
index 01b43b014..26c624b8f 100644
--- a/xmake/actions/require/install.lua
+++ b/xmake/actions/require/install.lua
@@ -152,10 +152,12 @@ function main(requires)
local extra = option.get("extra")
local extrainfo = nil
if extra then
- local tmpfile = os.tmpfile() .. ".lua"
- io.writefile(tmpfile, "{" .. extra .. "}")
- extrainfo = io.load(tmpfile)
- os.tryrm(tmpfile)
+ local v, err = string.deserialize(extra)
+ if err then
+ raise(err)
+ else
+ extrainfo = v
+ end
end
-- force to use the given requires extra info
diff --git a/xmake/actions/require/xmake.lua b/xmake/actions/require/xmake.lua
index d3c7956d8..bdd4e40bd 100644
--- a/xmake/actions/require/xmake.lua
+++ b/xmake/actions/require/xmake.lua
@@ -70,6 +70,6 @@ task("require")
"e.g.",
" $ xmake require zlib tbox",
" $ xmake require \"zlib >=1.2.11\" \"tbox master\"",
- " $ xmake require --extra=\"debug=true,system=false\" tbox" }
+ " $ xmake require --extra=\"{debug=true,configs={xxx=true}}\" tbox"}
}
}
diff --git a/xmake/plugins/lua/main.lua b/xmake/plugins/lua/main.lua
index aa6cab807..2fae8a0c6 100644
--- a/xmake/plugins/lua/main.lua
+++ b/xmake/plugins/lua/main.lua
@@ -41,6 +41,7 @@ function _list()
end
end
+-- print verbose log
function _print_vlog(script_type, script_name, args)
if not option.get("verbose") then return end
cprintf("running %s ${underline}%s${reset}", script_type, script_name)
@@ -103,7 +104,10 @@ function _run_script(script, args)
printresult = true
end
+ -- print verbose log
_print_vlog(script_type or "script", script_name or "", args)
+
+ -- dump result
local result = table.pack(func(table.unpack(args, 1, args.n)))
if printresult and result and result.n ~= 0 then
utils.dump(unpack(result, 1, result.n))
@@ -112,19 +116,20 @@ end
function _get_args()
+ -- get arguments
local args = option.get("arguments") or {}
args.n = #args
+ -- get deserialize tag
local deserialize = option.get("deserialize")
if not deserialize then
return args
end
-
deserialize = tostring(deserialize)
+ -- deserialize prefixed arguments
for i, value in ipairs(args) do
if value:startswith(deserialize) then
- -- deserialize prefixed arg
local v, err = string.deserialize(value:sub(#deserialize + 1))
if err then
raise(err)
@@ -133,12 +138,12 @@ function _get_args()
end
end
end
-
return args
end
function main()
+ -- list builtin scripts
if option.get("list") then
return _list()
end