summaryrefslogtreecommitdiff
path: root/xmake/core/base/template.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2016-01-25 09:47:57 +0800
committerruki <[email protected]>2016-02-15 19:10:25 +0800
commit80f231295375a965495885e015963ad563d2935a (patch)
tree26925828acbe4c5981dbf074b47f8a6d9586ae34 /xmake/core/base/template.lua
parentb8b1b5129ddcc0154e701dbac023f19ae1a3bf8c (diff)
update templates
Diffstat (limited to 'xmake/core/base/template.lua')
-rw-r--r--xmake/core/base/template.lua59
1 files changed, 58 insertions, 1 deletions
diff --git a/xmake/core/base/template.lua b/xmake/core/base/template.lua
index 2dc7135fa..ab2f400dc 100644
--- a/xmake/core/base/template.lua
+++ b/xmake/core/base/template.lua
@@ -52,7 +52,9 @@ function template._interpreter()
interp:api_register_add_values(nil, nil, "macrofiles")
-- register api: add_keyvalues() for root
- interp:api_register_add_keyvalues(nil, nil, "macros")
+ interp:api_register_add_keyvalues(nil, nil, "macros"
+ , "copydirs"
+ , "movedirs")
-- save interpreter
template._INTERPRETER = interp
@@ -61,6 +63,42 @@ function template._interpreter()
return interp
end
+-- copy directories
+function template._copydirs(copydirs)
+
+ -- check
+ assert(copydirs)
+
+ -- copy them
+ for srcdir, dstdir in pairs(copydirs) do
+ local ok, errors = os.cp(srcdir, dstdir)
+ if not ok then
+ return false, errors
+ end
+ end
+
+ -- ok
+ return true
+end
+
+-- move directories
+function template._movedirs(movedirs)
+
+ -- check
+ assert(movedirs)
+
+ -- copy them
+ for srcdir, dstdir in pairs(movedirs) do
+ local ok, errors = os.mv(srcdir, dstdir)
+ if not ok then
+ return false, errors
+ end
+ end
+
+ -- ok
+ return true
+end
+
-- replace macros
function template._replace(macros, macrofiles)
@@ -172,6 +210,9 @@ function template.create(language, templateid, targetname)
-- replace targetname
if variable == "targetname" then
variable = targetname
+ -- replace packagesdir
+ elseif variable == "packagesdir" then
+ variable = xmake._PACKAGES_DIR
end
-- ok?
@@ -215,6 +256,22 @@ function template.create(language, templateid, targetname)
return false, string.format("can not enter %s!", xmake._PROJECT_DIR)
end
+ -- copy directories
+ if module.copydirs then
+ ok, errors = template._copydirs(module.copydirs)
+ if not ok then
+ return false, errors
+ end
+ end
+
+ -- move directories
+ if module.movedirs then
+ ok, errors = template._movedirs(module.movedirs)
+ if not ok then
+ return false, errors
+ end
+ end
+
-- replace macros
if module.macros and module.macrofiles then
ok, errors = template._replace(module.macros, module.macrofiles)