diff options
| author | ruki <[email protected]> | 2015-12-05 10:04:47 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-12-05 10:04:47 +0800 |
| commit | b753c9e182813b395dd4910476ff4fb3c5e26fd9 (patch) | |
| tree | e9233083762f24c2f988f4d31d7cec846d55bfb2 | |
| parent | 98a12249aff0eed41c11f31da54205dc876379bf (diff) | |
encode and decode string
| -rw-r--r-- | xmake/scripts/base/makefile.lua | 13 | ||||
| -rw-r--r-- | xmake/scripts/base/string.lua | 20 | ||||
| -rw-r--r-- | xmake/scripts/tools/dispatcher.lua | 6 | ||||
| -rw-r--r-- | xmake/scripts/tools/echo.lua | 2 | ||||
| -rw-r--r-- | xmake/scripts/tools/verbose.lua | 5 |
5 files changed, 34 insertions, 12 deletions
diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua index ec5557c23..3304d95f7 100644 --- a/xmake/scripts/base/makefile.lua +++ b/xmake/scripts/base/makefile.lua @@ -67,7 +67,7 @@ function makefile._make_object_for_object(file, target, srcfile, objfile) -- make body file:write(string.format("\t@echo inserting%s %s\n", mode, srcfile)) - file:write(string.format("\t@xmake l $(VERBOSE) verbose \"%s\"\n", cmd:gsub("[%s=\"]", function (w) return string.format("%%%x", w:byte()) end))) + file:write(string.format("\t@xmake l $(VERBOSE) verbose \"%s\"\n", cmd:encode())) file:write(string.format("\t@%s\n", cmd)) -- make tail @@ -112,7 +112,8 @@ function makefile._make_object_for_static(file, target, srcfile, objfile) end -- make command - local cmd = string.format("xmake l dispatcher \"%s\" \"%s\" extract %s %s > %s 2>&1", toolname, toolpath, srcfile, objfile, makefile._LOGFILE) + local cmd = string.format("xmake l dispatcher %s %s extract %s %s > %s 2>&1", toolname:encode(), toolpath:encode(), srcfile:encode(), objfile:encode(), makefile._LOGFILE) +-- local cmd = string.format("xmake l dispatcher %s %s extract %s %s", toolname:encode(), toolpath:encode(), srcfile:encode(), objfile:encode()) -- make head file:write(string.format("%s:", objfile)) @@ -122,7 +123,7 @@ function makefile._make_object_for_static(file, target, srcfile, objfile) -- make body file:write(string.format("\t@echo inserting%s %s\n", mode, srcfile)) - file:write(string.format("\t@xmake l $(VERBOSE) verbose \"%s\"\n", cmd:gsub("[%s=\"]", function (w) return string.format("%%%x", w:byte()) end))) + file:write(string.format("\t@xmake l $(VERBOSE) verbose \"%s\"\n", cmd:encode())) file:write(string.format("\t@xmake l rmdir %s\n", path.directory(objfile))) file:write(string.format("\t@%s\n", cmd)) @@ -178,7 +179,7 @@ function makefile._make_object(file, target, srcfile, objfile) -- make body file:write(string.format("\t@echo %scompiling%s %s\n", utils.ifelse(ccache, "ccache ", ""), mode, srcfile)) - file:write(string.format("\t@xmake l $(VERBOSE) verbose \"%s\"\n", cmd:gsub("[%s=\"]", function (w) return string.format("%%%x", w:byte()) end))) + file:write(string.format("\t@xmake l $(VERBOSE) verbose \"%s\"\n", cmd:encode())) file:write(string.format("\t@xmake l mkdir %s\n", path.directory(objfile))) file:write(string.format("\t@%s\n", cmd)) @@ -287,11 +288,11 @@ function makefile._make_target(file, name, target) local cmd = linker.make(l, target, objfiles, targetfile, makefile._LOGFILE) -- the verbose - local verbose = cmd:gsub("[%s=\"<]", function (w) return string.format("%%%x", w:byte()) end) + local verbose = cmd:encode() -- too long? if verbose and #verbose > 256 then verbose = linker.make(l, target, {rule.filename("*", "object")}, targetfile) - verbose = verbose:gsub("[%s=\"<]", function (w) return string.format("%%%x", w:byte()) end) + verbose = verbose:encode() end -- make body diff --git a/xmake/scripts/base/string.lua b/xmake/scripts/base/string.lua index 3abe68c05..d6f3bf748 100644 --- a/xmake/scripts/base/string.lua +++ b/xmake/scripts/base/string.lua @@ -89,6 +89,26 @@ function string.append(self, substr, separator) return s end +-- encode: ' ', '=', '\"', '<' +function string.encode(self) + + -- null? + if self == nil then return end + + -- done + return (self:gsub("[%s=\"<]", function (w) return string.format("%%%x", w:byte()) end)) +end + +-- decode: ' ', '=', '\"' +function string.decode(self) + + -- null? + if self == nil then return end + + -- done + return (self:gsub("%%(%x%x)", function (w) return string.char(tonumber(w, 16)) end)) +end + -- return module: string return string diff --git a/xmake/scripts/tools/dispatcher.lua b/xmake/scripts/tools/dispatcher.lua index 3e7425d66..768c03017 100644 --- a/xmake/scripts/tools/dispatcher.lua +++ b/xmake/scripts/tools/dispatcher.lua @@ -39,8 +39,8 @@ function dispatcher.main(self, ...) assert(#args >= 3) -- get toolpath - local toolname = args[1] - local toolpath = args[2] + local toolname = args[1]:decode() + local toolpath = args[2]:decode() local action_name = args[3] assert(toolname and toolpath and action_name) @@ -63,7 +63,7 @@ function dispatcher.main(self, ...) -- init arguments for action local action_args = {} for i = 4, #args do - table.insert(action_args, args[i]) + table.insert(action_args, args[i]:decode()) end -- done action diff --git a/xmake/scripts/tools/echo.lua b/xmake/scripts/tools/echo.lua index a4911dd10..dbfa67426 100644 --- a/xmake/scripts/tools/echo.lua +++ b/xmake/scripts/tools/echo.lua @@ -32,7 +32,7 @@ function echo.main(self, ...) -- echo all for _, v in ipairs(...) do - io.write(string.format("%s ", v:gsub("%%(%x%x)", function (w) return string.char(tonumber(w, 16)) end))) + io.write(string.format("%s ", v:decode())) end io.write("\n") diff --git a/xmake/scripts/tools/verbose.lua b/xmake/scripts/tools/verbose.lua index 9de33fdcd..b1168f29d 100644 --- a/xmake/scripts/tools/verbose.lua +++ b/xmake/scripts/tools/verbose.lua @@ -25,7 +25,8 @@ local verbose = verbose or {} -- load modules -local io = require("base/io") +local io = require("base/io") +local string = require("base/string") -- the main function function verbose.main(self, ...) @@ -33,7 +34,7 @@ function verbose.main(self, ...) -- verbose all if xmake._OPTIONS.verbose then for _, v in ipairs(...) do - io.write(string.format("%s ", v:gsub("%%(%x%x)", function (w) return string.char(tonumber(w, 16)) end))) + io.write(string.format("%s ", v:decode())) end io.write("\n") end |
