summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-02-28 23:04:13 +0800
committerruki <[email protected]>2026-02-28 23:04:13 +0800
commita4b8b3e4d3725ada922dbd62d48f833a83746dcb (patch)
tree2816ae8e85bbd98a8cff2fbf3b83e9b484ef77ca
parentcfa0f9320bf323a42921ac7238202aa33f732006 (diff)
improve filter
-rw-r--r--xmake/actions/create/template.lua17
1 files changed, 16 insertions, 1 deletions
diff --git a/xmake/actions/create/template.lua b/xmake/actions/create/template.lua
index d097456d8..2e27d8459 100644
--- a/xmake/actions/create/template.lua
+++ b/xmake/actions/create/template.lua
@@ -21,6 +21,7 @@
-- imports
import("core.base.global")
import("core.base.hashset")
+import("core.language.language")
-- some builtin template variables in xmake.lua
function builtinvars(targetname)
@@ -67,11 +68,25 @@ function copy_files(sourcedir, projectdir)
return createdfiles
end
+-- only replace variables in template source files and xmake.lua
+function _need_replace_variables(filepath)
+ if not os.isfile(filepath) then
+ return false
+ end
+ if path.filename(filepath) == "xmake.lua" then
+ return true
+ end
+ local extension = path.extension(filepath)
+ if extension then
+ return language.extensions()[extension:lower()] ~= nil
+ end
+end
+
-- replace variables in files
function replace_variables_in_files(files, vars)
local pattern = "%${(.-)}"
for _, file in ipairs(files) do
- if os.isfile(file) and path.filename(file) == "xmake.lua" then
+ if _need_replace_variables(file) then
io.gsub(file, "(" .. pattern .. ")", function(_, variable)
variable = variable:trim()
local value = vars[variable]