summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-25 18:09:37 +0800
committerruki <[email protected]>2015-06-25 18:09:37 +0800
commit73a91c19b7c306ef2d2056914f285e1588985534 (patch)
treee86bf702560fab1e820c6368b7b7f6a69e1cbebd /xmake/scripts
parent8f45b7c5b9e62f3ac2cc8782d4de1bff3ed31008 (diff)
backup the packaged files
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/action/_package.lua47
-rw-r--r--xmake/scripts/base/rule.lua15
2 files changed, 60 insertions, 2 deletions
diff --git a/xmake/scripts/action/_package.lua b/xmake/scripts/action/_package.lua
index ccd2c2e38..759ec3be3 100644
--- a/xmake/scripts/action/_package.lua
+++ b/xmake/scripts/action/_package.lua
@@ -25,6 +25,7 @@ local _package = _package or {}
-- load modules
local rule = require("base/rule")
+local path = require("base/path")
local utils = require("base/utils")
local config = require("base/config")
local global = require("base/global")
@@ -71,6 +72,32 @@ function _package._build(arch, target_name)
return true
end
+-- backup the target files
+function _package._backup(rootdir, filepath)
+
+ -- the relative file path
+ if filepath and path.is_absolute(filepath) then
+ filepath = path.relative(filepath, xmake._PROJECT_DIR)
+ end
+
+ -- not exists? return it directly
+ if not filepath or not os.isfile(filepath) then return end
+
+ -- the backup file
+ local backupfile = string.format("%s/%s", rootdir, filepath)
+
+ -- backup it
+ local ok, errors = os.cp(filepath, backupfile)
+ if not ok then
+ -- errors
+ utils.error(errors)
+ return
+ end
+
+ -- ok
+ return filepath
+end
+
-- make configure for the given target
function _package._makeconf(target_name, target)
@@ -97,15 +124,24 @@ function _package._makeconf(target_name, target)
-- save the target kind
configs_arch.kind = target.kind
+ -- save the root directory
+ configs_arch.rootdir = rule.packagedir(target_name, arch)
+
-- save the config file
- configs_arch.config_h = rule.config_h(target)
+ configs_arch.config_h = _package._backup(configs_arch.rootdir, rule.config_h(target))
-- save the target file
- configs_arch.targetfile = rule.targetfile(target_name, target)
+ configs_arch.targetfile = _package._backup(configs_arch.rootdir, rule.targetfile(target_name, target))
+
+ -- save the target directory
+ configs_arch.targetdir = target.targetdir
-- save the header files
configs_arch.headerfiles = rule.headerfiles(target)
+ -- save the header directory
+ configs_arch.headerdir = target.headerdir
+
-- ok
return true
end
@@ -228,6 +264,13 @@ function _package.done()
-- load the global configure first
global.load()
+ -- enter the project directory
+ if not os.cd(xmake._PROJECT_DIR) then
+ -- errors
+ utils.error("not found project: %s!", xmake._PROJECT_DIR)
+ return false
+ end
+
-- build the given target first for all architectures
if not _package._build_all(options.archs, options.target) then
-- errors
diff --git a/xmake/scripts/base/rule.lua b/xmake/scripts/base/rule.lua
index 5dc4e5d53..bf28eb098 100644
--- a/xmake/scripts/base/rule.lua
+++ b/xmake/scripts/base/rule.lua
@@ -73,6 +73,21 @@ function rule.config_h(target)
return config_h
end
+-- get the temporary package directory
+function rule.packagedir(target_name, arch)
+
+ -- the temporary directory
+ local tmpdir = os.tmpdir()
+ assert(tmpdir)
+
+ -- the project name
+ local project_name = path.basename(xmake._PROJECT_DIR)
+ assert(project_name)
+
+ -- make it
+ return string.format("%s/.xmake/%s/pkgfiles/%s/%s", tmpdir, project_name, target_name, arch)
+end
+
-- get target file for the given target
function rule.targetfile(target_name, target, buildir)