summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-22 21:45:47 +0800
committerGitHub <[email protected]>2022-05-22 21:45:47 +0800
commit95f4151df4642aba94f927c82d480d65162a4687 (patch)
treee5f29310f8deb5bb6d857ca2f66001892474ad07
parent34a0c28d63953f48ab4d9e552a46dd70b787d069 (diff)
parent029710a592452e79883ec01205162836908fc45d (diff)
Merge pull request #2373 from xmake-io/newpath
improve path for cmake/vs
-rw-r--r--core/src/xmake/os/args.c2
-rw-r--r--core/src/xmake/process/openv.c2
-rw-r--r--xmake/core/base/path.lua61
-rw-r--r--xmake/core/base/table.lua4
-rw-r--r--xmake/modules/private/utils/batchcmds.lua26
-rw-r--r--xmake/plugins/project/cmake/cmakelists.lua73
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x.lua15
-rw-r--r--xmake/rules/asn1c/xmake.lua2
-rw-r--r--xmake/rules/capnproto/capnp.lua10
-rw-r--r--xmake/rules/lex_yacc/lex/xmake.lua2
-rw-r--r--xmake/rules/lex_yacc/yacc/xmake.lua7
-rw-r--r--xmake/rules/platform/linux/bpf/xmake.lua2
-rw-r--r--xmake/rules/protobuf/proto.lua6
-rw-r--r--xmake/rules/qt/moc/xmake.lua18
-rw-r--r--xmake/rules/qt/qrc/xmake.lua6
-rw-r--r--xmake/rules/qt/ui/xmake.lua2
-rw-r--r--xmake/rules/utils/bin2c/xmake.lua2
-rw-r--r--xmake/rules/utils/glsl2spv/xmake.lua6
-rw-r--r--xmake/rules/vala/xmake.lua14
-rw-r--r--xmake/rules/xcode/metal/xmake.lua10
20 files changed, 203 insertions, 67 deletions
diff --git a/core/src/xmake/os/args.c b/core/src/xmake/os/args.c
index 362b0c9bb..49a459248 100644
--- a/core/src/xmake/os/args.c
+++ b/core/src/xmake/os/args.c
@@ -119,7 +119,7 @@ tb_int_t xm_os_args(lua_State* lua)
lua_rawget(lua, 1);
if (lua_istable(lua, -1)) // is path instance?
{
- lua_pushstring(lua, "_PATH");
+ lua_pushstring(lua, "_STR");
lua_gettable(lua, -2);
size_t size = 0;
tb_char_t const* cstr = luaL_checklstring(lua, -1, &size);
diff --git a/core/src/xmake/process/openv.c b/core/src/xmake/process/openv.c
index a6b3dfa08..5114e263c 100644
--- a/core/src/xmake/process/openv.c
+++ b/core/src/xmake/process/openv.c
@@ -85,7 +85,7 @@ tb_int_t xm_process_openv(lua_State* lua)
// is path instance?
else if (lua_istable(lua, -1))
{
- lua_pushstring(lua, "_PATH");
+ lua_pushstring(lua, "_STR");
lua_gettable(lua, -2);
argv[1 + argi] = lua_tostring(lua, -1);
lua_pop(lua, 1);
diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua
index edc6daa24..df99ef30e 100644
--- a/xmake/core/base/path.lua
+++ b/xmake/core/base/path.lua
@@ -26,34 +26,48 @@ local string = require("base/string")
local table = require("base/table")
local _instance = _instance or {}
+-- save original interfaces
+path._absolute = path._absolute or path.absolute
+path._relative = path._relative or path.relative
+
-- new a path
function _instance.new(p, transform)
local instance = table.inherit(_instance)
- instance._PATH = p
+ instance._RAWSTR = p
instance._TRANSFORM = transform
setmetatable(instance, _instance)
+ table.wraplock(instance)
+ instance:_update()
return instance
end
-function _instance:str()
+-- update path string
+function _instance:_update()
local transform = self._TRANSFORM
if transform then
- return transform(self:rawstr())
+ self._STR = transform(self:rawstr())
+ else
+ self._STR = self:rawstr()
end
- return self:rawstr()
+end
+
+function _instance:str()
+ return self._STR
end
function _instance:rawstr()
- return self._PATH
+ return self._RAWSTR
end
function _instance:set(p)
- self._PATH = tostring(p)
+ self._RAWSTR = tostring(p)
+ self:_update()
return self
end
function _instance:transform_set(transform)
self._TRANSFORM = transform
+ self:_update()
return self
end
@@ -85,6 +99,14 @@ function _instance:directory()
return path.new(path.directory(self:str()), self._TRANSFORM)
end
+function _instance:absolute(rootdir)
+ return path.new(path.absolute(self:str(), rootdir), self._TRANSFORM)
+end
+
+function _instance:relative(rootdir)
+ return path.new(path.relative(self:str(), rootdir), self._TRANSFORM)
+end
+
function _instance:join(...)
local items = {self:str()}
for _, item in ipairs(table.pack(...)) do
@@ -131,12 +153,14 @@ end
-- - reduce "/xxx/.." => "/"
--
function path.normalize(p)
+ p = tostring(p)
return path.translate(p, {normalize = true})
end
-- get the directory of the path, compatible with lower version core binary
if not path.directory then
function path.directory(p, sep)
+ p = tostring(p)
local i = 0
if sep then
-- if the path has been normalized, we can quickly find it with a unique path separator prompt
@@ -153,8 +177,25 @@ if not path.directory then
end
end
+-- get absolute path
+function path.absolute(p, rootdir)
+ if rootdir then
+ rootdir = tostring(rootdir)
+ end
+ return path._absolute(tostring(p), rootdir)
+end
+
+-- get relative path
+function path.relative(p, rootdir)
+ if rootdir then
+ rootdir = tostring(rootdir)
+ end
+ return path._relative(tostring(p), rootdir)
+end
+
-- get the filename of the path
function path.filename(p, sep)
+ p = tostring(p)
local i = 0
if sep then
-- if the path has been normalized, we can quickly find it with a unique path separator prompt
@@ -171,6 +212,7 @@ end
-- get the basename of the path
function path.basename(p)
+ p = tostring(p)
local name = path.filename(p)
local i = name:lastof(".", true)
if i then
@@ -182,6 +224,7 @@ end
-- get the file extension of the path: .xxx
function path.extension(p, level)
+ p = tostring(p)
local i = p:lastof(".", true)
if i then
local ext = p:sub(i)
@@ -199,11 +242,13 @@ end
-- join path
function path.join(p, ...)
+ p = tostring(p)
return path.translate(p .. path.sep() .. table.concat({...}, path.sep()))
end
-- split path by the separator
function path.split(p)
+ p = tostring(p)
return p:split("[/\\]")
end
@@ -292,6 +337,7 @@ end
-- the last character is the path seperator?
function path.islastsep(p)
+ p = tostring(p)
local sep = p:sub(#p, #p)
return xmake._HOST == "windows" and (sep == '\\' or sep == '/') or (sep == '/')
end
@@ -319,6 +365,7 @@ end
-- get cygwin-style path on msys2/cygwin, e.g. "c:\xxx" -> "/c/xxx"
function path.cygwin_path(p)
+ p = tostring(p)
p = p:gsub("\\", "/")
local pos = p:find(":/")
if pos == 2 then
@@ -334,7 +381,7 @@ end
-- is path instance?
function path.instance_of(p)
- return type(p) == "table" and p.normalize and p._PATH
+ return type(p) == "table" and p.normalize and p._RAWSTR
end
-- register call function
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua
index 6c2b3aaf4..b8e83cd40 100644
--- a/xmake/core/base/table.lua
+++ b/xmake/core/base/table.lua
@@ -93,7 +93,7 @@ end
function table.join(...)
local result = {}
for _, t in ipairs({...}) do
- if type(t) == "table" then
+ if type(t) == "table" and not t.__wraplocked__ then
for k, v in pairs(t) do
if type(k) == "number" then table.insert(result, v)
else result[k] = v end
@@ -108,7 +108,7 @@ end
-- join all objects and tables to self
function table.join2(self, ...)
for _, t in ipairs({...}) do
- if type(t) == "table" then
+ if type(t) == "table" and not t.__wraplocked__ then
for k, v in pairs(t) do
if type(k) == "number" then table.insert(self, v)
else self[k] = v end
diff --git a/xmake/modules/private/utils/batchcmds.lua b/xmake/modules/private/utils/batchcmds.lua
index bb5204072..a5a636f07 100644
--- a/xmake/modules/private/utils/batchcmds.lua
+++ b/xmake/modules/private/utils/batchcmds.lua
@@ -222,13 +222,24 @@ function batchcmds:compile(sourcefiles, objectfile, opt)
opt = opt or {}
opt.target = self._TARGET
+ -- wrap path for sourcefiles, because we need translate path for project generator
+ if type(sourcefiles) == "table" then
+ local sourcefiles_wrap = {}
+ for _, sourcefile in ipairs(sourcefiles) do
+ table.insert(sourcefiles_wrap, path(sourcefile))
+ end
+ sourcefiles = sourcefiles_wrap
+ else
+ sourcefiles = path(sourcefiles)
+ end
+
-- load compiler and get compilation command
local sourcekind = opt.sourcekind
- if not sourcekind and type(sourcefiles) == "string" then
- sourcekind = language.sourcekind_of(sourcefiles)
+ if not sourcekind and type(sourcefiles) == "string" or path.instance_of(sourcefiles) then
+ sourcekind = language.sourcekind_of(tostring(sourcefiles))
end
local compiler_inst = compiler.load(sourcekind, opt)
- local program, argv = compiler_inst:compargv(sourcefiles, objectfile, opt)
+ local program, argv = compiler_inst:compargv(sourcefiles, path(objectfile), opt)
-- add compilation command and bind run environments of compiler
self:mkdir(path.directory(objectfile))
@@ -243,9 +254,16 @@ function batchcmds:link(objectfiles, targetfile, opt)
opt = opt or {}
opt.target = target
+ -- wrap path for objectfiles, because we need translate path for project generator
+ local objectfiles_wrap = {}
+ for _, objectfile in ipairs(objectfiles) do
+ table.insert(objectfiles_wrap, path(objectfile))
+ end
+ objectfiles = objectfiles_wrap
+
-- load linker and get link command
local linker_inst = target and target:linker() or linker.load(opt.targetkind, opt.sourcekinds, opt)
- local program, argv = linker_inst:linkargv(objectfiles, targetfile, opt)
+ local program, argv = linker_inst:linkargv(objectfiles, path(targetfile), opt)
-- add link command and bind run environments of linker
self:mkdir(path.directory(targetfile))
diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua
index eea74d04f..4ccb67670 100644
--- a/xmake/plugins/project/cmake/cmakelists.lua
+++ b/xmake/plugins/project/cmake/cmakelists.lua
@@ -42,12 +42,25 @@ function _get_cmake_minver()
return cmake_minver
end
+-- tranlate path
+function _translate_path(filepath, outputdir)
+ filepath = path.translate(filepath)
+ if filepath == "" then
+ return ""
+ end
+ if path.is_absolute(filepath) then
+ if filepath:startswith(project.directory()) then
+ return path.relative(filepath, outputdir)
+ end
+ return filepath
+ else
+ return path.relative(path.absolute(filepath), outputdir)
+ end
+end
+
-- get unix path
function _get_unix_path(filepath, outputdir)
- if path.is_absolute(filepath) and filepath:startswith(os.projectdir()) then
- filepath = path.relative(filepath, os.projectdir())
- end
- filepath = path.relative(filepath, outputdir)
+ filepath = _translate_path(filepath, outputdir)
filepath = path.translate(filepath):gsub('\\', '/')
return os.args(filepath)
end
@@ -55,7 +68,8 @@ end
-- get unix path relative to the cmake path
-- @see https://github.com/xmake-io/xmake/issues/2026
function _get_unix_path_relative_to_cmake(filepath, outputdir)
- filepath = _get_unix_path(filepath, outputdir)
+ filepath = _translate_path(filepath, outputdir)
+ filepath = path.translate(filepath):gsub('\\', '/')
if filepath and not path.is_absolute(filepath) then
filepath = "${CMAKE_SOURCE_DIR}/" .. filepath
end
@@ -289,8 +303,6 @@ function _add_target_include_directories(cmakelists, target, outputdir)
end
cmakelists:print(")")
end
-
- -- TODO deprecated
local includedirs_interface = target:get("includedirs", {interface = true})
if includedirs_interface then
cmakelists:print("target_include_directories(%s INTERFACE", target:name())
@@ -329,6 +341,42 @@ function _add_target_sysinclude_directories(cmakelists, target, outputdir)
end
end
+-- add target framework directories
+function _add_target_framework_directories(cmakelists, target, outputdir)
+ local frameworkdirs = _get_configs_from_target(target, "frameworkdirs")
+ if #frameworkdirs > 0 then
+ cmakelists:print("target_compile_options(%s PRIVATE", target:name())
+ for _, frameworkdir in ipairs(frameworkdirs) do
+ cmakelists:print(" $<$<COMPILE_LANGUAGE:C>:-F" .. _get_unix_path(frameworkdir, outputdir) .. ">")
+ cmakelists:print(" $<$<COMPILE_LANGUAGE:CXX>:-F" .. _get_unix_path(frameworkdir, outputdir) .. ">")
+ cmakelists:print(" $<$<COMPILE_LANGUAGE:OBJC>:-F" .. _get_unix_path(frameworkdir, outputdir) .. ">")
+ cmakelists:print(" $<$<COMPILE_LANGUAGE:OBJCXX>:-F" .. _get_unix_path(frameworkdir, outputdir) .. ">")
+ end
+ cmakelists:print(")")
+ local cmake_minver = _get_cmake_minver()
+ if cmake_minver:ge("3.13.0") then
+ cmakelists:print("target_link_options(%s PRIVATE", target:name())
+ else
+ cmakelists:print("target_link_libraries(%s PRIVATE", target:name())
+ end
+ for _, frameworkdir in ipairs(frameworkdirs) do
+ cmakelists:print(" -F" .. _get_unix_path(frameworkdir, outputdir))
+ end
+ cmakelists:print(")")
+ end
+ local frameworkdirs_interface = target:get("frameworkdirs", {interface = true})
+ if frameworkdirs_interface then
+ cmakelists:print("target_compile_options(%s PRIVATE", target:name())
+ for _, frameworkdir in ipairs(frameworkdirs_interface) do
+ cmakelists:print(" $<$<COMPILE_LANGUAGE:C>:-F" .. _get_unix_path(frameworkdir, outputdir) .. ">")
+ cmakelists:print(" $<$<COMPILE_LANGUAGE:CXX>:-F" .. _get_unix_path(frameworkdir, outputdir) .. ">")
+ cmakelists:print(" $<$<COMPILE_LANGUAGE:OBJC>:-F" .. _get_unix_path(frameworkdir, outputdir) .. ">")
+ cmakelists:print(" $<$<COMPILE_LANGUAGE:OBJCXX>:-F" .. _get_unix_path(frameworkdir, outputdir) .. ">")
+ end
+ cmakelists:print(")")
+ end
+end
+
-- add target compile definitions
function _add_target_compile_definitions(cmakelists, target)
local defines = _get_configs_from_target(target, "defines")
@@ -605,13 +653,15 @@ function _get_command_string(cmd, outputdir)
if cmd.program then
-- @see https://github.com/xmake-io/xmake/discussions/2156
local argv = {}
- for _, v in ipairs(table.join(cmd.program, cmd.argv)) do
- if path.is_absolute(v) then
+ for _, v in ipairs(cmd.argv) do
+ if path.instance_of(v) then
+ v = v:clone():set(_get_unix_path_relative_to_cmake(v:rawstr(), outputdir)):str()
+ elseif path.is_absolute(v) then
v = _get_unix_path_relative_to_cmake(v, outputdir)
end
table.insert(argv, v)
end
- local command = os.args(argv)
+ local command = cmd.program .. " " .. os.args(argv)
if opt and opt.curdir then
command = "${CMAKE_COMMAND} -E chdir " .. _get_unix_path_relative_to_cmake(opt.curdir, outputdir) .. " " .. command
end
@@ -799,6 +849,9 @@ function _add_target(cmakelists, target, outputdir)
-- add target system include directories
_add_target_sysinclude_directories(cmakelists, target, outputdir)
+ -- add target framework directories
+ _add_target_framework_directories(cmakelists, target, outputdir)
+
-- add target compile definitions
_add_target_compile_definitions(cmakelists, target)
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua
index 8752d49ed..ce07549c0 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x.lua
@@ -85,7 +85,9 @@ function _get_command_string(cmd, vcxprojdir)
if cmd.program then
local argv = {}
for _, v in ipairs(table.join(cmd.program, cmd.argv)) do
- if path.is_absolute(v) then
+ if path.instance_of(v) then
+ v = v:clone():set(_translate_path(v:rawstr(), vcxprojdir)):str()
+ elseif path.is_absolute(v) then
v = _translate_path(v, vcxprojdir)
end
table.insert(argv, v)
@@ -96,15 +98,16 @@ function _get_command_string(cmd, vcxprojdir)
end
return command
elseif kind == "cp" then
- return string.format("copy /Y \"%s\" \"%s\"", cmd.srcpath, cmd.dstpath)
+ return string.format("copy /Y \"%s\" \"%s\"", _translate_path(cmd.srcpath, vcxprojdir), _translate_path(cmd.dstpath, vcxprojdir))
elseif kind == "rm" then
- return string.format("del /F /Q \"%s\" || rmdir /S /Q \"%s\"", cmd.filepath, cmd.filepath)
+ return string.format("del /F /Q \"%s\" || rmdir /S /Q \"%s\"", _translate_path(cmd.filepath, vcxprojdir), _translate_path(cmd.filepath, vcxprojdir))
elseif kind == "mv" then
- return string.format("rename \"%s\" \"%s\"", cmd.srcpath, cmd.dstpath)
+ return string.format("rename \"%s\" \"%s\"", _translate_path(cmd.srcpath, vcxprojdir), _translate_path(cmd.dstpath, vcxprojdir))
elseif kind == "cd" then
- return string.format("cd \"%s\"", cmd.dir)
+ return string.format("cd \"%s\"", _translate_path(cmd.dir, vcxprojdir))
elseif kind == "mkdir" then
- return string.format("if not exist \"%s\" mkdir \"%s\"", cmd.dir, cmd.dir)
+ local dir = _translate_path(cmd.dir, vcxprojdir)
+ return string.format("if not exist \"%s\" mkdir \"%s\"", dir, dir)
elseif kind == "show" then
return string.format("echo %s", cmd.showtext)
end
diff --git a/xmake/rules/asn1c/xmake.lua b/xmake/rules/asn1c/xmake.lua
index 7efbcd040..cc1c60dd0 100644
--- a/xmake/rules/asn1c/xmake.lua
+++ b/xmake/rules/asn1c/xmake.lua
@@ -30,7 +30,7 @@ rule("asn1c")
local sourcefile_dir = path.join(target:autogendir(), "rules", "asn1c")
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.asn1c %s", sourcefile_asn1)
batchcmds:mkdir(sourcefile_dir)
- batchcmds:vrunv(asn1c.program, {path.absolute(sourcefile_asn1)}, {curdir = sourcefile_dir})
+ batchcmds:vrunv(asn1c.program, {path(sourcefile_asn1):absolute()}, {curdir = sourcefile_dir})
-- compile *.c
for _, sourcefile in ipairs(os.files(path.join(sourcefile_dir, "*.c|converter-*.c"))) do
diff --git a/xmake/rules/capnproto/capnp.lua b/xmake/rules/capnproto/capnp.lua
index 5b37b0956..747608755 100644
--- a/xmake/rules/capnproto/capnp.lua
+++ b/xmake/rules/capnproto/capnp.lua
@@ -70,15 +70,15 @@ function buildcmd(target, batchcmds, sourcefile_capnp, opt)
local includes = capnproto:get("sysincludedirs")
local argv = {"compile"}
for _, value in ipairs(includes) do
- table.insert(argv, "-I" .. value)
+ table.insert(argv, path(value, function (p) return "-I" .. p end))
end
- table.insert(argv, "-I" .. (prefixdir and prefixdir or path.directory(sourcefile_capnp)))
+ table.insert(argv, path(prefixdir and prefixdir or path.directory(sourcefile_capnp), function (p) return "-I" .. p end))
if prefixdir then
- table.insert(argv, "--src-prefix=" .. prefixdir)
+ table.insert(argv, path(prefixdir, function (p) return "--src-prefix=" .. p end))
end
table.insert(argv, "-o")
- table.insert(argv, "c++:" .. sourcefile_dir)
- table.insert(argv, sourcefile_capnp)
+ table.insert(argv, path(sourcefile_dir, function (p) return "c++:" .. p end))
+ table.insert(argv, path(sourcefile_capnp))
batchcmds:vrunv(capnp, argv)
local configs = {includedirs = sourcefile_dir, languages = "c++14"}
if target:is_plat("windows") then
diff --git a/xmake/rules/lex_yacc/lex/xmake.lua b/xmake/rules/lex_yacc/lex/xmake.lua
index adc3c49ec..e8c30d204 100644
--- a/xmake/rules/lex_yacc/lex/xmake.lua
+++ b/xmake/rules/lex_yacc/lex/xmake.lua
@@ -38,7 +38,7 @@ rule("lex")
-- add commands
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.lex %s", sourcefile_lex)
batchcmds:mkdir(path.directory(sourcefile_cx))
- batchcmds:vrunv(lex.program, {"-o", sourcefile_cx, sourcefile_lex})
+ batchcmds:vrunv(lex.program, {"-o", path(sourcefile_cx), path(sourcefile_lex)})
batchcmds:compile(sourcefile_cx, objectfile)
-- add deps
diff --git a/xmake/rules/lex_yacc/yacc/xmake.lua b/xmake/rules/lex_yacc/yacc/xmake.lua
index 70514cadb..021780c5f 100644
--- a/xmake/rules/lex_yacc/yacc/xmake.lua
+++ b/xmake/rules/lex_yacc/yacc/xmake.lua
@@ -21,6 +21,10 @@
-- define rule: yacc
rule("yacc")
set_extensions(".y", ".yy")
+ on_load(function (target)
+ local sourcefile_dir = path.join(target:autogendir(), "rules", "yacc_yacc")
+ target:add("includedirs", sourcefile_dir)
+ end)
before_buildcmd_file(function (target, batchcmds, sourcefile_yacc, opt)
-- get yacc
@@ -37,12 +41,11 @@ rule("yacc")
-- add includedirs
local sourcefile_dir = path.directory(sourcefile_cx)
- target:add("includedirs", sourcefile_dir)
-- add commands
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.yacc %s", sourcefile_yacc)
batchcmds:mkdir(sourcefile_dir)
- batchcmds:vrunv(yacc.program, {"-d", "-o", sourcefile_cx, sourcefile_yacc})
+ batchcmds:vrunv(yacc.program, {"-d", "-o", path(sourcefile_cx), path(sourcefile_yacc)})
batchcmds:compile(sourcefile_cx, objectfile)
-- add deps
diff --git a/xmake/rules/platform/linux/bpf/xmake.lua b/xmake/rules/platform/linux/bpf/xmake.lua
index d78693708..d4a48e70c 100644
--- a/xmake/rules/platform/linux/bpf/xmake.lua
+++ b/xmake/rules/platform/linux/bpf/xmake.lua
@@ -50,7 +50,7 @@ rule("platform.linux.bpf")
batchcmds:mkdir(path.directory(objectfile))
batchcmds:compile(sourcefile, objectfile, {configs = {force = {cxflags = {"-target bpf", "-g", "-O2"}}, defines = targetarch}})
batchcmds:mkdir(path.directory(headerfile))
- batchcmds:execv("bpftool", {"gen", "skeleton", objectfile}, {stdout = headerfile})
+ batchcmds:execv("bpftool", {"gen", "skeleton", path(objectfile)}, {stdout = headerfile})
batchcmds:add_depfiles(sourcefile)
batchcmds:set_depmtime(os.mtime(headerfile))
batchcmds:set_depcache(target:dependfile(headerfile))
diff --git a/xmake/rules/protobuf/proto.lua b/xmake/rules/protobuf/proto.lua
index 56d3bcdec..9c20857ff 100644
--- a/xmake/rules/protobuf/proto.lua
+++ b/xmake/rules/protobuf/proto.lua
@@ -109,9 +109,9 @@ function buildcmd(target, batchcmds, sourcefile_proto, opt, sourcekind)
-- add commands
batchcmds:mkdir(sourcefile_dir)
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.proto %s", sourcefile_proto)
- batchcmds:vrunv(protoc, {sourcefile_proto,
- "-I" .. (prefixdir and prefixdir or path.directory(sourcefile_proto)),
- (sourcekind == "cxx" and "--cpp_out=" or "--c_out=") .. sourcefile_dir})
+ batchcmds:vrunv(protoc, {path(sourcefile_proto),
+ path(prefixdir and prefixdir or path.directory(sourcefile_proto), function (p) return "-I" .. p end),
+ path(sourcefile_dir, function (p) return (sourcekind == "cxx" and "--cpp_out=" or "--c_out=") .. p end)})
batchcmds:compile(sourcefile_cx, objectfile, {configs = {includedirs = sourcefile_dir, languages = (sourcekind == "cxx" and "c++11")}})
-- add deps
diff --git a/xmake/rules/qt/moc/xmake.lua b/xmake/rules/qt/moc/xmake.lua
index f12fcf217..8b619677a 100644
--- a/xmake/rules/qt/moc/xmake.lua
+++ b/xmake/rules/qt/moc/xmake.lua
@@ -59,11 +59,21 @@ rule("qt.moc")
-- generate c++ source file for moc
local flags = {}
table.join2(flags, compiler.map_flags("cxx", "define", target:get("defines")))
- table.join2(flags, compiler.map_flags("cxx", "includedir", target:get("includedirs")))
- table.join2(flags, compiler.map_flags("cxx", "includedir", target:get("sysincludedirs"))) -- for now, moc process doesn't support MSVC external includes flags and will fail
- table.join2(flags, compiler.map_flags("cxx", "frameworkdir", target:get("frameworkdirs")))
+ local pathmaps = {
+ {"includedirs", "includedir"},
+ {"sysincludedirs", "includedir"}, -- for now, moc process doesn't support MSVC external includes flags and will fail
+ {"frameworkdirs", "frameworkdir"}
+ }
+ for _, pathmap in ipairs(pathmaps) do
+ for _, item in ipairs(target:get(pathmap[1])) do
+ local pathitem = path(item, function (p)
+ return table.unwrap(compiler.map_flags("cxx", pathmap[2], p))
+ end)
+ table.insert(flags, pathitem)
+ end
+ end
batchcmds:mkdir(path.directory(sourcefile_moc))
- batchcmds:vrunv(moc, table.join(flags, sourcefile, "-o", sourcefile_moc))
+ batchcmds:vrunv(moc, table.join(flags, path(sourcefile), "-o", path(sourcefile_moc)))
-- we need compile this moc_xxx.cpp file if exists Q_PRIVATE_SLOT, @see https://github.com/xmake-io/xmake/issues/750
local mocdata = io.readfile(sourcefile)
diff --git a/xmake/rules/qt/qrc/xmake.lua b/xmake/rules/qt/qrc/xmake.lua
index 28db39f87..f5e057957 100644
--- a/xmake/rules/qt/qrc/xmake.lua
+++ b/xmake/rules/qt/qrc/xmake.lua
@@ -54,12 +54,12 @@ rule("qt.qrc")
-- add commands
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.qt.qrc %s", sourcefile_qrc)
batchcmds:mkdir(sourcefile_dir)
- batchcmds:vrunv(rcc, {"-name", path.basename(sourcefile_qrc), sourcefile_qrc, "-o", sourcefile_cpp})
+ batchcmds:vrunv(rcc, {"-name", path.basename(sourcefile_qrc), path(sourcefile_qrc), "-o", path(sourcefile_cpp)})
batchcmds:compile(sourcefile_cpp, objectfile)
-
+
-- get qrc resources files
local outdata = os.iorunv(rcc, {"-name", path.basename(sourcefile_qrc), sourcefile_qrc, "-list"})
-
+
-- add resources files to batch
for _, file in ipairs(outdata:split("\n")) do
batchcmds:add_depfiles(file)
diff --git a/xmake/rules/qt/ui/xmake.lua b/xmake/rules/qt/ui/xmake.lua
index 2d02a134b..52e1a5228 100644
--- a/xmake/rules/qt/ui/xmake.lua
+++ b/xmake/rules/qt/ui/xmake.lua
@@ -55,7 +55,7 @@ rule("qt.ui")
local headerfile_ui = path.join(headerfile_dir, "ui_" .. path.basename(sourcefile_ui) .. ".h")
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.qt.ui %s", sourcefile_ui)
batchcmds:mkdir(headerfile_dir)
- batchcmds:vrunv(uic, {sourcefile_ui, "-o", headerfile_ui})
+ batchcmds:vrunv(uic, {path(sourcefile_ui), "-o", path(headerfile_ui)})
batchcmds:add_depfiles(sourcefile_ui)
batchcmds:set_depmtime(os.mtime(headerfile_ui))
batchcmds:set_depcache(target:dependfile(headerfile_ui))
diff --git a/xmake/rules/utils/bin2c/xmake.lua b/xmake/rules/utils/bin2c/xmake.lua
index 77f81125c..3e5e9144d 100644
--- a/xmake/rules/utils/bin2c/xmake.lua
+++ b/xmake/rules/utils/bin2c/xmake.lua
@@ -37,7 +37,7 @@ rule("utils.bin2c")
-- add commands
batchcmds:show_progress(opt.progress, "${color.build.object}generating.bin2c %s", sourcefile_bin)
batchcmds:mkdir(headerdir)
- local argv = {"lua", "private.utils.bin2c", "-i", sourcefile_bin, "-o", headerfile}
+ local argv = {"lua", "private.utils.bin2c", "-i", path(sourcefile_bin), "-o", path(headerfile)}
local linewidth = target:extraconf("rules", "utils.bin2c", "linewidth")
if linewidth then
table.insert(argv, "-w")
diff --git a/xmake/rules/utils/glsl2spv/xmake.lua b/xmake/rules/utils/glsl2spv/xmake.lua
index b7c772a2b..d9846c6bc 100644
--- a/xmake/rules/utils/glsl2spv/xmake.lua
+++ b/xmake/rules/utils/glsl2spv/xmake.lua
@@ -63,9 +63,9 @@ rule("utils.glsl2spv")
batchcmds:show_progress(opt.progress, "${color.build.object}generating.glsl2spv %s", sourcefile_glsl)
batchcmds:mkdir(outputdir)
if glslangValidator then
- batchcmds:vrunv(glslangValidator.program, {"--target-env", targetenv, "-o", spvfilepath, sourcefile_glsl})
+ batchcmds:vrunv(glslangValidator.program, {"--target-env", targetenv, "-o", path(spvfilepath), path(sourcefile_glsl)})
else
- batchcmds:vrunv(glslc.program, {"--target-env", targetenv, "-o", spvfilepath, sourcefile_glsl})
+ batchcmds:vrunv(glslc.program, {"--target-env", targetenv, "-o", path(spvfilepath), path(sourcefile_glsl)})
end
-- do bin2c
@@ -79,7 +79,7 @@ rule("utils.glsl2spv")
outputfile = headerfile
-- add commands
- local argv = {"lua", "private.utils.bin2c", "--nozeroend", "-i", spvfilepath, "-o", headerfile}
+ local argv = {"lua", "private.utils.bin2c", "--nozeroend", "-i", path(spvfilepath), "-o", path(headerfile)}
batchcmds:vrunv(os.programfile(), argv, {envs = {XMAKE_SKIP_HISTORY = "y"}})
end
diff --git a/xmake/rules/vala/xmake.lua b/xmake/rules/vala/xmake.lua
index 6c3d36213..8f1431fca 100644
--- a/xmake/rules/vala/xmake.lua
+++ b/xmake/rules/vala/xmake.lua
@@ -75,12 +75,12 @@ rule("vala.build")
-- add commands
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.vala %s", sourcefile_vala)
batchcmds:mkdir(basedir)
- local argv = {"-C", "-b", basedir}
+ local argv = {"-C", "-b", path(basedir)}
local packages = target:values("vala.packages")
if packages then
for _, package in ipairs(packages) do
table.insert(argv, "--pkg")
- table.insert(argv, package)
+ table.insert(argv, path(package))
end
end
if target:is_binary() then
@@ -88,30 +88,30 @@ rule("vala.build")
if dep:is_shared() or dep:is_static() then
local vapifile = dep:data("vala.vapifile")
if vapifile then
- table.join2(argv, vapifile)
+ table.join2(argv, path(vapifile))
end
end
end
else
local vapifile = target:data("vala.vapifile")
if vapifile then
- table.insert(argv, "--vapi=" .. vapifile)
+ table.insert(argv, path(vapifile, function (p) return "--vapi=" .. p end))
end
local headerfile = target:data("vala.headerfile")
if headerfile then
table.insert(argv, "-H")
- table.insert(argv, headerfile)
+ table.insert(argv, path(headerfile))
end
end
local vapidir = target:data("vala.vapidir")
if vapidir then
- table.insert(argv, "--vapidir=" .. vapidir)
+ table.insert(argv, path(vapidir, function (p) return "--vapidir=" .. p end))
end
local valaflags = target:data("vala.flags")
if valaflags then
table.join2(argv, valaflags)
end
- table.insert(argv, sourcefile_vala)
+ table.insert(argv, path(sourcefile_vala))
batchcmds:vrunv(valac.program, argv)
batchcmds:compile(sourcefile_c, objectfile)
diff --git a/xmake/rules/xcode/metal/xmake.lua b/xmake/rules/xcode/metal/xmake.lua
index a876f946b..9484b8fea 100644
--- a/xmake/rules/xcode/metal/xmake.lua
+++ b/xmake/rules/xcode/metal/xmake.lua
@@ -87,11 +87,11 @@ rule("xcode.metal")
end
if xcode_sysroot then
table.insert(argv, "-isysroot")
- table.insert(argv, xcode_sysroot)
+ table.insert(argv, path(xcode_sysroot))
end
table.insert(argv, "-o")
- table.insert(argv, objectfile)
- table.insert(argv, sourcefile)
+ table.insert(argv, path(objectfile))
+ table.insert(argv, path(sourcefile))
-- add commands
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.metal %s", sourcefile)
@@ -109,10 +109,12 @@ rule("xcode.metal")
-- get objectfiles
local objectfiles = {}
+ local objectfiles_wrap = {}
for rulename, sourcebatch in pairs(target:sourcebatches()) do
if rulename == "xcode.metal" then
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
table.insert(objectfiles, target:objectfile(sourcefile) .. ".air")
+ table.insert(objectfiles_wrap, path(target:objectfile(sourcefile) .. ".air"))
end
break
end
@@ -136,7 +138,7 @@ rule("xcode.metal")
local libraryfile = resourcesdir and path.join(resourcesdir, "default.metallib") or (target:targetfile() .. ".metallib")
batchcmds:show_progress(opt.progress, "${color.build.target}linking.metal %s", path.filename(libraryfile))
batchcmds:mkdir(path.directory(libraryfile))
- batchcmds:vrunv(metallib.program, table.join({"-o", libraryfile}, objectfiles), {envs = {SDKROOT = xcode_sysroot}})
+ batchcmds:vrunv(metallib.program, table.join({"-o", path(libraryfile)}, objectfiles_wrap), {envs = {SDKROOT = xcode_sysroot}})
-- add deps
batchcmds:add_depfiles(objectfiles)