diff options
| author | OpportunityLiu <[email protected]> | 2019-07-17 15:35:54 +0800 |
|---|---|---|
| committer | OpportunityLiu <[email protected]> | 2019-07-19 11:48:32 +0800 |
| commit | 8a976c88c7b9da0a306fbbeac22870a7b00b4682 (patch) | |
| tree | d7ee13d18dc973b1ca28cd028e33592948f99b18 | |
| parent | e98bcd58485a636dc897946f652be9067d37a9e0 (diff) | |
fix escape
| -rw-r--r-- | xmake/plugins/project/vsxmake/getinfo.lua | 69 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/vsxmake.lua | 31 |
2 files changed, 58 insertions, 42 deletions
diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index ceb955b46..1f9760f1a 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -31,6 +31,30 @@ import("lib.detect.find_tool") import("actions.config.configheader", {alias = "generate_configheader", rootdir = os.programdir()}) import("actions.config.configfiles", {alias = "generate_configfiles", rootdir = os.programdir()}) +-- escape special chars in msbuild file +function _escape(str) + if not str then + return nil + end + + local map = + { ["%"] = "%25" -- Referencing metadata + ,["$"] = "%24" -- Referencing properties + ,["@"] = "%40" -- Referencing item lists + ,["'"] = "%27" -- Conditions and other expressions + ,[";"] = "%3B" -- List separator + ,["?"] = "%3F" -- Wildcard character for file names in Include and Exclude attributes + ,["*"] = "%2A" -- Wildcard character for use in file names in Include and Exclude attributes + -- html entities + ,["\""] = """ + ,["<"] = "<" + ,[">"] = ">" + ,["&"] = "&" + } + + return (string.gsub(str, "[%%%$@';%?%*\"<>&]", function (c) return assert(map[c]) end)) +end + function _make_dirs(dir) if dir == nil then return "" @@ -42,18 +66,33 @@ function _make_dirs(dir) end if path.is_absolute(dir) then if dir:startswith(project.directory()) then - return path.join("$(XmakeProjectDir)", path.relative(dir, project.directory())) + return path.join("$(XmakeProjectDir)", _escape(path.relative(dir, project.directory()))) end - return dir + return _escape(dir) end - return path.join("$(XmakeProjectDir)", dir) + return path.join("$(XmakeProjectDir)", _escape(dir)) end local r = {} for k, v in ipairs(dir) do r[k] = _make_dirs(v) end r = table.unique(r) - return path.joinenv(r) + return table.concat(r, ";") +end + +function _make_arrs(arr) + if arr == nil then + return "" + end + if type(arr) == "string" then + return _escape(arr) + end + local r = {} + for k, v in ipairs(arr) do + r[k] = _make_arrs(v) + end + r = table.unique(r) + return table.concat(r, ";") end function _get_values(target, name) @@ -71,7 +110,13 @@ end function _make_targetinfo(mode, arch, target) -- init target info - local targetinfo = { mode = mode, arch = arch, plat = config.get("plat"), vsarch = (arch == "x86" and "Win32" or arch) } + local targetinfo = + { + mode = mode + , arch = arch + , plat = config.get("plat") + , vsarch = (arch == "x86" and "Win32" or arch) + } -- write only if not default -- use target:get("xxx") rather than target:xxx() @@ -80,8 +125,8 @@ function _make_targetinfo(mode, arch, target) targetinfo.kind = target:get("kind") -- save target file - targetinfo.basename = target:get("basename") - targetinfo.filename = target:get("filename") + targetinfo.basename = _escape(target:get("basename")) + targetinfo.filename = _escape(target:get("filename")) -- save dirs targetinfo.targetdir = _make_dirs(target:get("targetdir")) @@ -93,8 +138,8 @@ function _make_targetinfo(mode, arch, target) targetinfo.linkdirs = _make_dirs(_get_values(target, "linkdirs")) -- save defines - targetinfo.defines = table.concat(_get_values(target, "defines"), ";") - targetinfo.languages = table.concat(_get_values(target, "languages"), ";") + targetinfo.defines = _make_arrs(_get_values(target, "defines")) + targetinfo.languages = _make_arrs(_get_values(target, "languages")) -- save runenvs local runenvs = {} @@ -272,14 +317,14 @@ function main(outputdir, vsinfo) local dir = path.directory(f) target._sub2[f] = { - path = f, - dir = dir + path = _escape(f), + dir = _escape(dir) } while dir ~= "." do if not dirs[dir] then dirs[dir] = { - dir = dir, + dir = _escape(dir), dir_id = hash.uuid(dir) } end diff --git a/xmake/plugins/project/vsxmake/vsxmake.lua b/xmake/plugins/project/vsxmake/vsxmake.lua index a3235f060..cf91eb40e 100644 --- a/xmake/plugins/project/vsxmake/vsxmake.lua +++ b/xmake/plugins/project/vsxmake/vsxmake.lua @@ -45,35 +45,6 @@ function _filter_files(files, exts) return f end --- escape special chars in msbuild file -function _escape(str) - if not str then - return nil - end - - local map = - { ["%"] = "%25" -- Referencing metadata - ,["$"] = "%24" -- Referencing properties - ,["@"] = "%40" -- Referencing item lists - ,["'"] = "%27" -- Conditions and other expressions - ,[";"] = "%3B" -- List separator - ,["?"] = "%3F" -- Wildcard character for file names in Include and Exclude attributes - ,["*"] = "%2A" -- Wildcard character for use in file names in Include and Exclude attributes - } - - local has_prefix = false - if str:startswith("$(XmakeProjectDir)") then - has_prefix = true - str = str:sub(#("$(XmakeProjectDir)") + 1) - end - - str = (string.gsub(str, "[%%%$@';%?%*]", function (c) return assert(map[c]) end)) - if has_prefix then - str = "$(XmakeProjectDir)" .. str - end - return str -end - function _buildparams(info, target, default) local function getprop(match, opt) @@ -91,7 +62,7 @@ function _buildparams(info, target, default) r = i[match] or r end - return _escape(r) or default + return r or default end local function listconfig(args) |
