summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-26 13:24:40 +0800
committerruki <[email protected]>2015-06-26 13:24:40 +0800
commitde65696cf95ff6c266d3b0174c9c10e3711bb643 (patch)
tree51dbd468bcb6bb1c34dfd94c78eb5422f9534e3e /xmake/scripts
parent37247cc86d31c6134deca9819f9ffe8cfe253797 (diff)
load package script from platform
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/action/_package.lua25
-rw-r--r--xmake/scripts/base/package.lua122
2 files changed, 128 insertions, 19 deletions
diff --git a/xmake/scripts/action/_package.lua b/xmake/scripts/action/_package.lua
index 590d071bc..6c71e4fa1 100644
--- a/xmake/scripts/action/_package.lua
+++ b/xmake/scripts/action/_package.lua
@@ -121,13 +121,18 @@ function _package._makeconf(target_name, target)
configs[target_name] = configs[target_name] or {}
local configs_target = configs[target_name]
- -- init configs for kinds
- configs_target[target.kind] = configs_target[target.kind] or {}
- local configs_kind = configs_target[target.kind]
+ -- init configs for files
+ configs_target.files = configs_target.files or {}
-- init configs for architecture
- configs_kind[arch] = configs_kind[arch] or {}
- local configs_arch = configs_kind[arch]
+ configs_target.files[arch] = configs_target.files[arch] or {}
+ local configs_arch = configs_target.files[arch]
+
+ -- save name
+ configs_target.name = target_name
+
+ -- save kind
+ configs_target.kind = target.kind
-- save the root directory
configs_arch.rootdir = rule.packagedir(target_name, arch)
@@ -148,17 +153,17 @@ function _package._makeconf(target_name, target)
configs_arch.headerdir = target.headerdir
-- save the package script
- configs_arch.pkgscript = target.pkgscript
- if type(configs_arch.pkgscript) == "string" and os.isfile(configs_arch.pkgscript) then
- local script, errors = loadfile(configs_arch.pkgscript)
+ configs_target.pkgscript = target.pkgscript
+ if type(configs_target.pkgscript) == "string" and os.isfile(configs_target.pkgscript) then
+ local script, errors = loadfile(configs_target.pkgscript)
if script then
- configs_arch.pkgscript = script()
+ configs_target.pkgscript = script()
else
utils.error(errors)
return false
end
end
- if target.pkgscript and type(configs_arch.pkgscript) ~= "function" then
+ if target.pkgscript and type(configs_target.pkgscript) ~= "function" then
utils.error("invalid package script!")
return false
end
diff --git a/xmake/scripts/base/package.lua b/xmake/scripts/base/package.lua
index d2018573d..6a0e66afa 100644
--- a/xmake/scripts/base/package.lua
+++ b/xmake/scripts/base/package.lua
@@ -30,15 +30,119 @@ local utils = require("base/utils")
local config = require("base/config")
local platform = require("platform/platform")
--- package info from the given info configure
-function package._done_target(name, info)
+-- package target for the static library
+function package._done_static(target)
+
+
+ -- continue
+ return 0
+end
+
+-- package target for the shared library
+function package._done_shared(target)
+
+
+ -- continue
+ return 0
+end
+
+-- package target for the binary library
+function package._done_binary(target)
+
+
+ -- continue
+ return 0
+end
+
+-- package target from the default script
+function package._done_from_default(target)
-- check
- assert(name and info)
+ assert(target.kind)
+
+ -- the package scripts
+ local pkgscripts =
+ {
+ static = package._done_static
+ , shared = package._done_shared
+ , binary = package._done_binary
+ }
+
+ -- package it
+ local pkgscript = pkgscripts[target.kind]
+ if pkgscript then return pkgscript(target) end
+
+ -- continue
+ return 0
+end
+
+-- package target from the project script
+function package._done_from_project(target)
+
+ -- check
+ assert(target)
+
+ -- package it using the project script first
+ local pkgscript = target.pkgscript
+ if type(pkgscript) == "function" then
+
+ -- remove it
+ target.pkgscript = nil
+
+ -- package it
+ return pkgscript(target)
+ end
+
+ -- continue
+ return 0
+end
+
+-- package target from the platform script
+function package._done_from_platform(target)
+
+ -- check
+ assert(target)
+
+ -- the platform package script file
+ local pkgscript = nil
+ local scriptfile = platform.directory() .. "/package.lua"
+ if os.isfile(scriptfile) then
+
+ -- load the package script
+ local script, errors = loadfile(scriptfile)
+ if script then pkgscript = script()
+ else
+ utils.error(errors)
+ end
+ end
+
+ -- package it
+ if type(pkgscript) == "function" then
+ return pkgscript(target)
+ end
+
+ -- continue
+ return 0
+end
+
+-- package target from the given target configure
+function package._done(target)
+
+ -- check
+ assert(target)
+
+ -- package it from the project script
+ local ok = package._done_from_project(target)
+ if ok ~= 0 then return utils.ifelse(ok == 1, true, false) end
+
+ -- package it from the platform script
+ local ok = package._done_from_platform(target)
+ if ok ~= 0 then return utils.ifelse(ok == 1, true, false) end
+
+ -- package it from the default script
+ local ok = package._done_from_default(target)
+ if ok ~= 0 then return utils.ifelse(ok == 1, true, false) end
- -- dump
- utils.dump(info)
-
-- ok
return true
end
@@ -50,12 +154,12 @@ function package.done(configs)
assert(configs)
-- package targets
- for name, info in pairs(configs) do
+ for _, target in pairs(configs) do
-- package it
- if not package._done_target(name, info) then
+ if not package._done(target) then
-- errors
- utils.error("package %s failed!", name)
+ utils.error("package %s failed!", target.name)
return false
end