summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxq114 <[email protected]>2022-02-25 22:06:12 +0800
committerxq114 <[email protected]>2022-02-25 22:06:12 +0800
commitfebb2851d49aafb5d54ae98cb81bae2bac852329 (patch)
treec52191cf00a85e6963c2aca7948f8ff5d138ae93
parente90177703284893d16d277fb5f25e619c7e6ec5a (diff)
add vsutils.lua
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x.lua32
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua46
-rw-r--r--xmake/plugins/project/vstudio/impl/vsutils.lua44
3 files changed, 59 insertions, 63 deletions
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua
index 4983387ae..fa0240c4e 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x.lua
@@ -30,6 +30,7 @@ import("core.tool.toolchain")
import("vs201x_solution")
import("vs201x_vcxproj")
import("vs201x_vcxproj_filters")
+import("vsutils")
import("core.cache.memcache")
import("core.cache.localcache")
import("private.action.require.install", {alias = "install_requires"})
@@ -38,31 +39,6 @@ import("actions.config.configfiles", {alias = "generate_configfiles", rootdir =
import("actions.config.configheader", {alias = "generate_configheader", rootdir = os.programdir()})
import("private.utils.batchcmds")
--- 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
- , ["\""] = "&quot;"
- , ["<"] = "&lt;"
- , [">"] = "&gt;"
- , ["&"] = "&amp;"
- }
-
- return (string.gsub(str, "[%%%$@';%?%*\"<>&]", function (c) return assert(map[c]) end))
-end
-
function _make_dirs(dir, vcxprojdir)
if dir == nil then
return ""
@@ -74,11 +50,11 @@ function _make_dirs(dir, vcxprojdir)
end
if path.is_absolute(dir) then
if dir:startswith(project.directory()) then
- return _escape(path.relative(dir, vcxprojdir))
+ return vsutils.escape(path.relative(dir, vcxprojdir))
end
- return _escape(dir)
+ return vsutils.escape(dir)
else
- return _escape(path.relative(path.absolute(dir), vcxprojdir))
+ return vsutils.escape(path.relative(path.absolute(dir), vcxprojdir))
end
end
local r = {}
diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
index a92ec0f01..0a83e982b 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
@@ -28,31 +28,7 @@ import("core.tool.toolchain")
import("private.utils.batchcmds")
import("detect.sdks.find_cuda")
import("vsfile")
-
--- 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
- , ["\""] = "&quot;"
- , ["<"] = "&lt;"
- , [">"] = "&gt;"
- , ["&"] = "&amp;"
- }
-
- return (string.gsub(str, "[%%%$@';%?%*\"<>&]", function (c) return assert(map[c]) end))
-end
+import("vsutils")
function _make_dirs(dir, vcxprojdir)
dir = dir:trim()
@@ -148,7 +124,7 @@ function _exclude_flags(flags, excludes)
end
end
if not excluded then
- table.insert(newflags, _escape(flag))
+ table.insert(newflags, vsutils.escape(flag))
end
end
return newflags
@@ -440,7 +416,7 @@ function _make_source_options_cl(vcxprojfile, flags, condition)
for _, flag in ipairs(flags) do
flag:gsub("[%-/]D(.*)",
function (def)
- defstr = defstr .. _escape(def) .. ";"
+ defstr = defstr .. vsutils.escape(def) .. ";"
end
)
end
@@ -481,7 +457,7 @@ function _make_source_options_cl(vcxprojfile, flags, condition)
if flagstr:find("[%-/]I") then
local dirs = {}
for _, flag in ipairs(flags) do
- flag:gsub("[%-/]I(.*)", function (dir) table.insert(dirs, _escape(dir)) end)
+ flag:gsub("[%-/]I(.*)", function (dir) table.insert(dirs, vsutils.escape(dir)) end)
end
if #dirs > 0 then
vcxprojfile:print("<AdditionalIncludeDirectories%s>%s</AdditionalIncludeDirectories>", condition, table.concat(dirs, ";"))
@@ -543,7 +519,7 @@ function _make_source_options_cuda(vcxprojfile, flags, opt)
for _, flag in ipairs(flags) do
flag:gsub("%-D(.*)",
function (def)
- defstr = defstr .. _escape(def) .. ";"
+ defstr = defstr .. vsutils.escape(def) .. ";"
end
)
end
@@ -554,7 +530,7 @@ function _make_source_options_cuda(vcxprojfile, flags, opt)
if flagstr:find("%-I") then
local dirs = {}
for _, flag in ipairs(flags) do
- flag:gsub("%-I(.*)", function (dir) table.insert(dirs, _escape(dir)) end)
+ flag:gsub("%-I(.*)", function (dir) table.insert(dirs, vsutils.escape(dir)) end)
end
if #dirs > 0 then
vcxprojfile:print("<Include%s>%s</Include>", condition, table.concat(dirs, ";"))
@@ -732,7 +708,7 @@ function _make_common_item(vcxprojfile, vsinfo, target, targetinfo)
subsystem = "Windows"
elseif flag_lower:find("[%-/]libpath") then
-- link dir
- flag:gsub("[%-/]libpath:(.*)", function (dir) table.insert(libdirs, _escape(dir)) end)
+ flag:gsub("[%-/]libpath:(.*)", function (dir) table.insert(libdirs, vsutils.escape(dir)) end)
elseif flag_lower:find("[^%-/].+%.lib") then
-- link file
table.insert(links, flag)
@@ -764,7 +740,7 @@ function _make_common_item(vcxprojfile, vsinfo, target, targetinfo)
-- make AdditionalOptions
if #flags > 0 then
flags = os.args(flags)
- vcxprojfile:print("<AdditionalOptions>%s %%(AdditionalOptions)</AdditionalOptions>", _escape(flags))
+ vcxprojfile:print("<AdditionalOptions>%s %%(AdditionalOptions)</AdditionalOptions>", vsutils.escape(flags))
end
-- generate debug infomation?
@@ -849,12 +825,12 @@ function _make_common_item(vcxprojfile, vsinfo, target, targetinfo)
-- make precompiled header and outputfile
vcxprojfile:print("<PrecompiledHeader>Use</PrecompiledHeader>")
- vcxprojfile:print("<PrecompiledHeaderFile>%s</PrecompiledHeaderFile>", _escape(path.filename(pcheader)))
+ vcxprojfile:print("<PrecompiledHeaderFile>%s</PrecompiledHeaderFile>", vsutils.escape(path.filename(pcheader)))
local pcoutputfile = targetinfo.pcxxoutputfile or targetinfo.pcoutputfile
if pcoutputfile then
- vcxprojfile:print("<PrecompiledHeaderOutputFile>%s</PrecompiledHeaderOutputFile>", _escape(path.relative(path.absolute(pcoutputfile), target.project_dir)))
+ vcxprojfile:print("<PrecompiledHeaderOutputFile>%s</PrecompiledHeaderOutputFile>", vsutils.escape(path.relative(path.absolute(pcoutputfile), target.project_dir)))
end
- vcxprojfile:print("<ForcedIncludeFiles>%s;%%(ForcedIncludeFiles)</ForcedIncludeFiles>", _escape(path.filename(pcheader)))
+ vcxprojfile:print("<ForcedIncludeFiles>%s;%%(ForcedIncludeFiles)</ForcedIncludeFiles>", vsutils.escape(path.filename(pcheader)))
end
vcxprojfile:leave("</ClCompile>")
diff --git a/xmake/plugins/project/vstudio/impl/vsutils.lua b/xmake/plugins/project/vstudio/impl/vsutils.lua
new file mode 100644
index 000000000..b4de1717b
--- /dev/null
+++ b/xmake/plugins/project/vstudio/impl/vsutils.lua
@@ -0,0 +1,44 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author xq114
+-- @file vsutils.lua
+--
+
+-- 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
+ , ["\""] = "&quot;"
+ , ["<"] = "&lt;"
+ , [">"] = "&gt;"
+ , ["&"] = "&amp;"
+ }
+
+ return (string.gsub(str, "[%%%$@';%?%*\"<>&]", function (c) return assert(map[c]) end))
+end