diff options
| author | ruki <[email protected]> | 2015-06-25 11:41:38 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-25 11:41:38 +0800 |
| commit | 5b6c2e819db721baa24d42ad33924431a28cd7e6 (patch) | |
| tree | 1d2c4089f16b6d768f43cddd973ed2d3b7b1adb1 | |
| parent | 40aeeb7d3f1f2fdc4b2a18fd6654301f4a757394 (diff) | |
rebuild all archs for package and fix find option bug
| -rw-r--r-- | xmake/scripts/action/_package.lua | 111 | ||||
| -rw-r--r-- | xmake/scripts/base/option.lua | 84 |
2 files changed, 119 insertions, 76 deletions
diff --git a/xmake/scripts/action/_package.lua b/xmake/scripts/action/_package.lua index 5e91f8e9d..149d1e4b4 100644 --- a/xmake/scripts/action/_package.lua +++ b/xmake/scripts/action/_package.lua @@ -26,27 +26,88 @@ local _package = _package or {} -- load modules local utils = require("base/utils") local config = require("base/config") +local string = require("base/string") local platform = require("platform/platform") -- need access to the given file? function _package.need(name) - -- check - assert(name) + -- no accessors + return false +end + +-- configure target for the given platform and architecture +function _package._config(plat, arch, target) + + -- make the command + local cmd = nil; + if plat and arch then cmd = string.format("xmake f -P %s -f %s -p %s -a %s %s", xmake._PROJECT_DIR, xmake._PROJECT_FILE, plat, arch, target); + elseif plat then cmd = string.format("xmake f -P %s -f %s -p %s %s", xmake._PROJECT_DIR, xmake._PROJECT_FILE, plat, target); + elseif arch then cmd = string.format("xmake f -P %s -f %s -a %s %s", xmake._PROJECT_DIR, xmake._PROJECT_FILE, arch, target); + else return true end + + -- done the command + return os.execute(cmd) == 0; +end + +-- build target for the given architecture +function _package._build(plat, arch, target) - -- the accessors - local accessors = { config = true, global = true, project = true, platform = true } + -- configure it first + if not _package._config(plat, arch, target) then return false end - -- need it? - return accessors[name] + print(string.format("xmake -r -P %s %s", xmake._PROJECT_DIR, target)) + -- rebuild it + return os.execute(string.format("xmake -r -P %s %s", xmake._PROJECT_DIR, target)) == 0; +end + +-- build target for all architectures +function _package._build_all(plat, archs, target) + + -- get the target + if not target or target == "all" then + target = "" + end + + -- exists the given architectures? + if archs then + + -- split all architectures + archs = archs:split(",") + if not archs then return false end + + -- build for all architectures + for _, arch in ipairs(archs) do + if not _package._build(plat, arch:trim(), target) then return false end + end + + -- build for single architecture + elseif not _package._build(plat, nil, target) then return false end + + -- ok + return true end -- done function _package.done() - -- TODO - print("not implement!") + -- the options + local options = xmake._OPTIONS + assert(options) + + -- trace + print("package: ...") + + -- build the given target first for all architectures + if not _package._build_all(options.plat, options.archs, options.target) then + -- errors + utils.error("build %s failed!", utils.ifelse(options.target, options.target, "all")) + return false + end + -- trace + print("package: ok!") + -- ok return true end @@ -67,7 +128,39 @@ function _package.menu() -- options , options = { - {'f', "file", "kv", "xmake.lua", "Create a given xmake.lua file." } + {'p', "plat", "kv", nil, "Package a given platform." + , function () + local descriptions = {} + local plats = platform.plats() + if plats then + for i, plat in ipairs(plats) do + descriptions[i] = " - " .. plat + end + end + return descriptions + end } + , {'a', "archs", "kv", nil, "Package multiple given architectures." + , " .e.g --archs=\"armv7, arm64\" or -a i386" + , "" + , function () + local descriptions = {} + local plats = platform.plats() + if plats then + for i, plat in ipairs(plats) do + descriptions[i] = " - " .. plat .. ":" + local archs = platform.archs(plat) + if archs then + for _, arch in ipairs(archs) do + descriptions[i] = descriptions[i] .. " " .. arch + end + end + end + end + return descriptions + end } + + , {} + , {'f', "file", "kv", "xmake.lua", "Create a given xmake.lua file." } , {'P', "project", "kv", nil, "Create from the given project directory." , "Search priority:" , " 1. The Given Command Argument" diff --git a/xmake/scripts/base/option.lua b/xmake/scripts/base/option.lua index 36963476b..1c8c35573 100644 --- a/xmake/scripts/base/option.lua +++ b/xmake/scripts/base/option.lua @@ -355,79 +355,29 @@ end function option.find(argv, name, shortname) -- check - assert(argv and name) + assert(argv and (name or shortname)) - -- parse _ARGV to _OPTIONS - local _iter, _s, _k = ipairs(argv) - while true do + -- find it + local nextvalue = false + for _, arg in ipairs(argv) do - -- the idx and arg - local idx, arg = _iter(_s, _k) + -- get this value + if nextvalue then return arg end - -- end? - _k = idx - if idx == nil then break end - - -- parse key and value - local key, value - local i = arg:find("=", 1, true) - - -- key=value? - if i then - key = arg:sub(1, i - 1) - value = arg:sub(i + 1) - -- only key? - else - key = arg - value = true - end - - -- --key? - local prefix = 0 - if key:startswith("--") then - key = key:sub(3) - prefix = 2 - -- -k? - elseif key:startswith("-") then - key = key:sub(2) - prefix = 1 - end + -- --name=value? + if name and arg:startswith("--" .. name) then + + -- get value + local i = arg:find("=", 1, true) + if i then return arg:sub(i + 1) end - -- check key - if prefix and #key == 0 then - -- failed - return + -- -shortname value? + elseif shortname and arg:startswith("-" .. shortname) then + + -- get value + nextvalue = true end - -- --key=value or -k value or -k? - if prefix ~= 0 then - - -- -k value? continue to get the value - if prefix == 1 then - - -- get the next idx and arg - idx, arg = _iter(_s, _k) - - -- exists value? - _k = idx - if idx == nil or arg:startswith("-") then - -- failed - return - end - - -- get value - value = arg - end - - -- ok? - if key == name or (shortname and key == shortname) then - return value - end - - -- action? skip it - elseif idx == 1 then - -- value? - else return end end end |
