summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-06-01 10:35:22 +0800
committerruki <[email protected]>2016-06-01 10:35:22 +0800
commit6b64748d083be2348d46075bea288656a69f5caa (patch)
treeb6e8c19ab704eb16b0355ade0860e69ce005d524
parente720bbe224eb7aec57ca488a67e840a685fe612f (diff)
add package macro
-rwxr-xr-xxmake/plugins/macro/macros/package.lua54
-rwxr-xr-xxmake/plugins/macro/main.lua85
2 files changed, 117 insertions, 22 deletions
diff --git a/xmake/plugins/macro/macros/package.lua b/xmake/plugins/macro/macros/package.lua
new file mode 100755
index 000000000..0bf506d1d
--- /dev/null
+++ b/xmake/plugins/macro/macros/package.lua
@@ -0,0 +1,54 @@
+--!The Automatic Cross-platform Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file package.lua
+--
+
+-- imports
+import("core.platform.platform")
+
+-- package all
+--
+-- .e.g
+-- xmake m package
+-- xmake m package linux
+-- xmake m package iphoneos "--demo=false --xxx ..."
+--
+function main(argv)
+
+ -- get plat
+ local plat = argv[1] or os.host()
+
+ -- get args
+ local args = argv[2] or ""
+
+ -- package all archs
+ for _, arch in ipairs(platform.archs(plat)) do
+
+ -- package debug
+ os.exec("xmake f -p %s -a %s -m debug %s", plat, arch, args)
+ os.exec("xmake -r")
+ os.exec("xmake p")
+
+ -- package release
+ os.exec("xmake f -p %s -a %s -m release %s", plat, arch, args)
+ os.exec("xmake -r")
+ os.exec("xmake p")
+ end
+end
diff --git a/xmake/plugins/macro/main.lua b/xmake/plugins/macro/main.lua
index 3de5ca598..b83b156b4 100755
--- a/xmake/plugins/macro/main.lua
+++ b/xmake/plugins/macro/main.lua
@@ -26,15 +26,48 @@ import("core.project.cache")
import("core.project.config")
import("core.project.history")
+-- the macro directories
+function _directories()
+
+ return { path.join(config.directory(), "macros")
+ , path.join(os.scriptdir(), "macros")}
+end
+
-- the macro directory
-function _directory()
+function _directory(macroname)
+
+ -- find macro directory
+ local macrodir = nil
+ for _, dir in ipairs(_directories()) do
+
+ -- found?
+ if os.isfile(path.join(dir, macroname .. ".lua")) then
+ macrodir = dir
+ break
+ end
+ end
+
+ -- check
+ assert(macrodir, "macro(%s) not found!", macroname)
+
+ -- ok
+ return macrodir
+end
+
+-- the readable macro file
+function _rfile(macroname)
+
+ -- is anonymous?
+ if macroname == '.' then
+ macroname = "anonymous"
+ end
-- get it
- return path.join(config.directory(), "macros")
+ return path.join(_directory(macroname), macroname .. ".lua")
end
--- the macro file
-function _file(macroname)
+-- the writable macro file
+function _wfile(macroname)
-- is anonymous?
if macroname == '.' then
@@ -42,7 +75,7 @@ function _file(macroname)
end
-- get it
- return path.join(_directory(), macroname .. ".lua")
+ return path.join(path.join(config.directory(), "macros"), macroname .. ".lua")
end
-- list macros
@@ -52,17 +85,19 @@ function _list()
print("macros:")
-- find all macros
- local macrofiles = os.match(path.join(_directory(), "*.lua"))
- for _, macrofile in ipairs(macrofiles) do
+ for _, dir in ipairs(_directories()) do
+ local macrofiles = os.match(path.join(dir, "*.lua"))
+ for _, macrofile in ipairs(macrofiles) do
- -- get macro name
- local macroname = path.basename(macrofile)
- if macroname == "anonymous" then
- macroname = ".<anonymous>"
- end
+ -- get macro name
+ local macroname = path.basename(macrofile)
+ if macroname == "anonymous" then
+ macroname = ".<anonymous>"
+ end
- -- show it
- print(" " .. macroname)
+ -- show it
+ print(" " .. macroname)
+ end
end
end
@@ -70,7 +105,7 @@ end
function _show(macroname)
-- show it
- local file = _file(macroname)
+ local file = _rfile(macroname)
if os.isfile(file) then
io.cat(file)
else
@@ -82,7 +117,13 @@ end
function _delete(macroname)
-- remove it
- os.rm(_file(macroname))
+ if os.isfile(_wfile(macroname)) then
+ os.rm(_wfile(macroname))
+ elseif os.isfile(_rfile(macroname)) then
+ raise("macro(%s) cannot be deleted!", macroname)
+ else
+ raise("macro(%s) not found!", macroname)
+ end
-- trace
print("delete macro(%s) ok!", macroname)
@@ -92,7 +133,7 @@ end
function _import(macrofile, macroname)
-- import it
- os.cp(macrofile, _file(macroname))
+ os.cp(macrofile, _wfile(macroname))
-- trace
print("import macro(%s) ok!", macroname)
@@ -102,7 +143,7 @@ end
function _export(macrofile, macroname)
-- export it
- os.cp(_file(macroname), macrofile)
+ os.cp(_rfile(macroname), macrofile)
-- trace
print("export macro(%s) ok!", macroname)
@@ -164,7 +205,7 @@ function _end(macroname)
history.save("cmdlines", "__macro_end__")
-- open the macro file
- local file = io.open(_file(macroname), "w")
+ local file = io.open(_wfile(macroname), "w")
-- save the macro begin
file:print("function main(argv)")
@@ -197,11 +238,11 @@ function _run(macroname)
macroname = "anonymous"
end
- -- import macro
- macro = import(macroname, {rootdir = _directory()})
+ -- load macro
+ local macro = import(macroname, {rootdir = _directory(macroname)})
-- run macro
- macro.main(option.get("arguments"))
+ macro.main(option.get("arguments") or {})
-- trace
print("run macro(%s) ok!", macroname)