summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-22 18:31:31 +0800
committerruki <[email protected]>2022-05-22 18:31:31 +0800
commit65350947080e83310f3efff3dcf82f3b12c43f06 (patch)
tree5d702aca2207977f950091aaf65effc29bd5b9d2
parent603749bcd6eff68165f0e0695b532a6173580f67 (diff)
improve path and moc rule
-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.lua23
-rw-r--r--xmake/rules/qt/moc/xmake.lua16
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)))