From d2bf2df2c3afdf1335721ae37cfeb721ff130227 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 9 Mar 2021 00:45:15 +0800 Subject: improve rules --- xmake/core/base/path.lua | 5 ++++- xmake/core/project/target.lua | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua index aa0cd571a..9da3f57c4 100644 --- a/xmake/core/base/path.lua +++ b/xmake/core/base/path.lua @@ -69,9 +69,12 @@ function path.basename(p) end -- get the file extension of the path: .xxx -function path.extension(p) +function path.extension(p, level) local i = p:lastof(".", true) if i then + if level and level > 1 then + return path.extension(p:sub(1, i - 1), level - 1) .. p:sub(i) + end return p:sub(i) else return "" diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 079199b47..ee7e3f519 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1105,7 +1105,10 @@ function _instance:filerules(sourcefile) end -- get target rules from the given sourcekind or extension - for _, r in ipairs(table.wrap(key2rules[self:sourcekind_of(sourcefile)] or key2rules[path.extension(sourcefile):lower()])) do + local filename = path.filename(sourcefile):lower() + for _, r in ipairs(table.wrap(key2rules[path.extension(filename, 2)] or + key2rules[path.extension(filename)] or + key2rules[self:sourcekind_of(filename)])) do table.insert(rules, r) end return rules -- cgit v1.3.1