From c990367664d6389990cb37c5a0ae4e9157d7b24e Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 22 May 2022 11:28:58 +0800 Subject: improve path for cmake/vs --- xmake/plugins/project/cmake/cmakelists.lua | 28 +++++++++++++++++++++------ xmake/plugins/project/vstudio/impl/vs201x.lua | 15 ++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index eea74d04f..34c8bc126 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 @@ -606,7 +620,9 @@ function _get_command_string(cmd, outputdir) -- @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 + 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) 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 -- cgit v1.3.1 From 9d7ff9055927118fab28537d204d4bb331842826 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 22 May 2022 12:06:52 +0800 Subject: wrap path for batchcmds --- xmake/modules/private/utils/batchcmds.lua | 22 ++++++++++++++++++++-- xmake/rules/qt/moc/xmake.lua | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/xmake/modules/private/utils/batchcmds.lua b/xmake/modules/private/utils/batchcmds.lua index bb5204072..8a31f7afd 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 + 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) 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 + 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/rules/qt/moc/xmake.lua b/xmake/rules/qt/moc/xmake.lua index f12fcf217..0648931ba 100644 --- a/xmake/rules/qt/moc/xmake.lua +++ b/xmake/rules/qt/moc/xmake.lua @@ -63,7 +63,7 @@ rule("qt.moc") 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"))) 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) -- cgit v1.3.1 From 489e4c01e2c4fb443c250e9ac9ec39b6bfcc129f Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 22 May 2022 12:15:22 +0800 Subject: improve bin2c path --- xmake/modules/private/utils/batchcmds.lua | 4 ++-- xmake/rules/utils/bin2c/xmake.lua | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/xmake/modules/private/utils/batchcmds.lua b/xmake/modules/private/utils/batchcmds.lua index 8a31f7afd..10b037f4e 100644 --- a/xmake/modules/private/utils/batchcmds.lua +++ b/xmake/modules/private/utils/batchcmds.lua @@ -222,7 +222,7 @@ function batchcmds:compile(sourcefiles, objectfile, opt) opt = opt or {} opt.target = self._TARGET - -- wrap path for sourcefiles + -- 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 @@ -254,7 +254,7 @@ function batchcmds:link(objectfiles, targetfile, opt) opt = opt or {} opt.target = target - -- wrap path for objectfiles + -- 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)) 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") -- cgit v1.3.1 From 5c23b2a425df9fad4edb17f5b64f34e8af87e628 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 22 May 2022 12:18:11 +0800 Subject: wrap path for glsl --- xmake/rules/utils/glsl2spv/xmake.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 -- cgit v1.3.1 From b9b395d835e4433e19b29e271b8348827c108772 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 22 May 2022 12:21:06 +0800 Subject: wrap path for metal --- xmake/rules/xcode/metal/xmake.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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) -- cgit v1.3.1 From 1ae7b87af15a19bbfb85f8c717ecef9fd72dc79e Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 22 May 2022 12:28:06 +0800 Subject: wrap path for vala --- xmake/rules/vala/xmake.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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) -- cgit v1.3.1 From 268371fc70abcb8a7d455923e5d937ceeaa6a04c Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 22 May 2022 14:59:17 +0800 Subject: fix batchcmds --- xmake/modules/private/utils/batchcmds.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/modules/private/utils/batchcmds.lua b/xmake/modules/private/utils/batchcmds.lua index 10b037f4e..a5a636f07 100644 --- a/xmake/modules/private/utils/batchcmds.lua +++ b/xmake/modules/private/utils/batchcmds.lua @@ -235,8 +235,8 @@ function batchcmds:compile(sourcefiles, objectfile, opt) -- 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, path(objectfile), opt) -- cgit v1.3.1 From 603749bcd6eff68165f0e0695b532a6173580f67 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 22 May 2022 16:42:52 +0800 Subject: improve table to support path --- xmake/core/base/path.lua | 10 ++++++++++ xmake/core/base/table.lua | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua index edc6daa24..7ccb320e6 100644 --- a/xmake/core/base/path.lua +++ b/xmake/core/base/path.lua @@ -32,6 +32,7 @@ function _instance.new(p, transform) instance._PATH = p instance._TRANSFORM = transform setmetatable(instance, _instance) + table.wraplock(instance) return instance end @@ -131,12 +132,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 @@ -155,6 +158,7 @@ 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 +175,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 +187,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 +205,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 +300,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 +328,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 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 -- cgit v1.3.1 From 65350947080e83310f3efff3dcf82f3b12c43f06 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 22 May 2022 18:31:31 +0800 Subject: improve path and moc rule --- core/src/xmake/os/args.c | 2 +- core/src/xmake/process/openv.c | 2 +- xmake/core/base/path.lua | 23 ++++++++++++++++------- xmake/rules/qt/moc/xmake.lua | 16 +++++++++++++--- 4 files changed, 31 insertions(+), 12 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 7ccb320e6..79eb28c3f 100644 --- a/xmake/core/base/path.lua +++ b/xmake/core/base/path.lua @@ -29,32 +29,41 @@ local _instance = _instance or {} -- 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) + instance:_update() return self end function _instance:transform_set(transform) self._TRANSFORM = transform + instance:_update() return self end @@ -344,7 +353,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/rules/qt/moc/xmake.lua b/xmake/rules/qt/moc/xmake.lua index 0648931ba..8b619677a 100644 --- a/xmake/rules/qt/moc/xmake.lua +++ b/xmake/rules/qt/moc/xmake.lua @@ -59,9 +59,19 @@ 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, path(sourcefile), "-o", path(sourcefile_moc))) -- cgit v1.3.1 From 095ab891b08842a9827e2147cb6cbb58cf908df6 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 22 May 2022 18:33:01 +0800 Subject: fix path --- xmake/core/base/path.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua index 79eb28c3f..04c386c23 100644 --- a/xmake/core/base/path.lua +++ b/xmake/core/base/path.lua @@ -57,13 +57,13 @@ end function _instance:set(p) self._RAWSTR = tostring(p) - instance:_update() + self:_update() return self end function _instance:transform_set(transform) self._TRANSFORM = transform - instance:_update() + self:_update() return self end -- cgit v1.3.1 From 0b460a9fd1215ac89de539c91eabe2eb234f9d24 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 22 May 2022 18:36:36 +0800 Subject: improve ui rule --- xmake/rules/qt/ui/xmake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)) -- cgit v1.3.1 From 0c354983c76505f843d76b916fbd1716f93fd369 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 22 May 2022 18:46:42 +0800 Subject: improve cmakelists --- xmake/plugins/project/cmake/cmakelists.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index 34c8bc126..a627e1f81 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -619,7 +619,7 @@ 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 + 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 @@ -627,7 +627,7 @@ function _get_command_string(cmd, 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 -- cgit v1.3.1 From 59b0d6109513a973815ff08a811305d70ec5fe01 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 22 May 2022 19:06:22 +0800 Subject: add path wrap for qrc --- xmake/rules/qt/qrc/xmake.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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) -- cgit v1.3.1 From a3d82bd43a50906804597a86a9deea950c2e5adb Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 22 May 2022 19:19:39 +0800 Subject: improve lex yacc rules --- xmake/core/base/path.lua | 13 +++++++++++++ xmake/rules/asn1c/xmake.lua | 2 +- xmake/rules/lex_yacc/lex/xmake.lua | 2 +- xmake/rules/lex_yacc/yacc/xmake.lua | 7 +++++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua index 04c386c23..4f534bb50 100644 --- a/xmake/core/base/path.lua +++ b/xmake/core/base/path.lua @@ -26,6 +26,9 @@ local string = require("base/string") local table = require("base/table") local _instance = _instance or {} +-- save original interfaces +path._absolute = path._absolute or path.absolute + -- new a path function _instance.new(p, transform) local instance = table.inherit(_instance) @@ -95,6 +98,10 @@ function _instance:directory() return path.new(path.directory(self:str()), self._TRANSFORM) end +function _instance:absolute() + return path.new(path.absolute(self:str()), self._TRANSFORM) +end + function _instance:join(...) local items = {self:str()} for _, item in ipairs(table.pack(...)) do @@ -165,6 +172,12 @@ if not path.directory then end end +-- get absolute path +function path.absolute(p) + p = tostring(p) + return path._absolute(p) +end + -- get the filename of the path function path.filename(p, sep) p = tostring(p) 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/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 -- cgit v1.3.1 From e96506ac537795a441e27338f485564fc11fdf5c Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 22 May 2022 19:28:29 +0800 Subject: improve protobuf rule --- xmake/rules/protobuf/proto.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 -- cgit v1.3.1 From bf34cd08b63a0a1c8314ca8b81c7fe04cc8531f1 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 22 May 2022 19:34:26 +0800 Subject: improve more rules --- xmake/rules/capnproto/capnp.lua | 10 +++++----- xmake/rules/platform/linux/bpf/xmake.lua | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) 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/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)) -- cgit v1.3.1 From f72603fcc27a74339b4bd1df794cf1382504c2f5 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 22 May 2022 20:14:31 +0800 Subject: fix path --- xmake/core/base/path.lua | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua index 4f534bb50..df99ef30e 100644 --- a/xmake/core/base/path.lua +++ b/xmake/core/base/path.lua @@ -28,6 +28,7 @@ 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) @@ -98,8 +99,12 @@ function _instance:directory() return path.new(path.directory(self:str()), self._TRANSFORM) end -function _instance:absolute() - return path.new(path.absolute(self:str()), self._TRANSFORM) +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(...) @@ -173,9 +178,19 @@ if not path.directory then end -- get absolute path -function path.absolute(p) - p = tostring(p) - return path._absolute(p) +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 -- cgit v1.3.1 From 656d298a6a3cfe2baace28da2f74da4e090f3b16 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 22 May 2022 20:43:40 +0800 Subject: add frameworkdir to cmakelists --- xmake/plugins/project/cmake/cmakelists.lua | 31 ++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index a627e1f81..5c327a924 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -303,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()) @@ -343,6 +341,32 @@ 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(" $<$:-F" .. _get_unix_path(frameworkdir, outputdir) .. ">") + cmakelists:print(" $<$:-F" .. _get_unix_path(frameworkdir, outputdir) .. ">") + cmakelists:print(" $<$:-F" .. _get_unix_path(frameworkdir, outputdir) .. ">") + 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(" $<$:-F" .. _get_unix_path(frameworkdir, outputdir) .. ">") + cmakelists:print(" $<$:-F" .. _get_unix_path(frameworkdir, outputdir) .. ">") + cmakelists:print(" $<$:-F" .. _get_unix_path(frameworkdir, outputdir) .. ">") + cmakelists:print(" $<$:-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") @@ -815,6 +839,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) -- cgit v1.3.1 From 029710a592452e79883ec01205162836908fc45d Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 22 May 2022 20:50:15 +0800 Subject: add frameworks to cmake links --- xmake/plugins/project/cmake/cmakelists.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index 5c327a924..4ccb67670 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -353,6 +353,16 @@ function _add_target_framework_directories(cmakelists, target, outputdir) cmakelists:print(" $<$:-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 -- cgit v1.3.1