summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-05-30 09:21:58 +0800
committerruki <[email protected]>2016-05-30 09:21:58 +0800
commit23acb023758b0b47cb5083d0d800fc48fc96d920 (patch)
treeec5af9f5185aafb2dd7f7d6d46494f838a602b75
parent4b86a4104d8076636ffa9a778b244f698aec5a49 (diff)
impl install action
-rwxr-xr-xxmake/actions/clean/main.lua3
-rwxr-xr-xxmake/actions/install/main.lua131
-rwxr-xr-xxmake/actions/install/xmake.lua3
-rwxr-xr-xxmake/actions/uninstall/main.lua132
-rwxr-xr-xxmake/actions/uninstall/xmake.lua3
-rw-r--r--xmake/core/base/os.lua8
-rw-r--r--xmake/core/project/package.lua42
-rw-r--r--xmake/core/project/project.lua8
-rw-r--r--xmake/core/project/task.lua3
-rw-r--r--xmake/core/sandbox/modules/import/core/project/package.lua38
10 files changed, 365 insertions, 6 deletions
diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua
index 2c987f2ad..ba4330d40 100755
--- a/xmake/actions/clean/main.lua
+++ b/xmake/actions/clean/main.lua
@@ -132,9 +132,6 @@ function _clean(targetname)
-- remove the configure directory
_remove(config.directory())
-
- -- remove build directory if be empty
- os.rm("$(buildir)", true)
end
end
diff --git a/xmake/actions/install/main.lua b/xmake/actions/install/main.lua
new file mode 100755
index 000000000..34e4f15eb
--- /dev/null
+++ b/xmake/actions/install/main.lua
@@ -0,0 +1,131 @@
+--!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 main.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.project.task")
+import("core.project.config")
+import("core.project.global")
+import("core.project.project")
+import("core.platform.platform")
+
+-- install package
+function _install_package(target)
+
+ -- make the package directory first if not exists
+ os.mkdir("$(packagedir)")
+
+ -- copy the package to the output directory
+ os.cp(format("$(buildir)/%s.pkg", target:name()), "$(packagedir)")
+end
+
+-- install target
+function _install_target(target)
+
+ -- get kind
+ local kind = target:get("kind")
+
+ -- get script
+ local scripts =
+ {
+ binary = _install_package
+ , static = _install_package
+ , shared = _install_package
+ }
+
+ -- check
+ assert(scripts[kind], "this target(%s) with kind(%s) can not be installd!", target:name(), kind)
+
+ -- install it
+ scripts[kind](target)
+end
+
+-- install the given target
+function _install(target)
+
+ -- enter project directory
+ os.cd(project.directory())
+
+ -- the target scripts
+ local scripts =
+ {
+ target:get("install_before")
+ , target:get("install") or _install_target
+ , target:get("install_after")
+ }
+
+ -- install the target scripts
+ for i = 1, 3 do
+ local script = scripts[i]
+ if script ~= nil then
+ script(target)
+ end
+ end
+
+ -- leave project directory
+ os.cd("-")
+end
+
+-- install the given target and deps
+function _install_target_and_deps(target)
+
+ -- this target have been finished?
+ if _g.finished[target:name()] then
+ return
+ end
+
+ -- install for all dependent targets
+ for _, depname in ipairs(target:get("deps")) do
+ _install_target_and_deps(project.target(depname))
+ end
+
+ -- install target
+ _install_target(target)
+
+ -- finished
+ _g.finished[target:name()] = true
+end
+
+-- main
+function main()
+
+ -- get the target name
+ local targetname = option.get("target")
+
+ -- init finished states
+ _g.finished = {}
+
+ -- package it first
+ task.run("package", {target = targetname})
+
+ -- install all?
+ if targetname == "all" then
+ for _, target in pairs(project.targets()) do
+ _install_target_and_deps(target)
+ end
+ else
+ _install_target_and_deps(project.target(targetname))
+ end
+
+ -- trace
+ print("install ok!")
+end
diff --git a/xmake/actions/install/xmake.lua b/xmake/actions/install/xmake.lua
index f9de9dc9a..d2160490e 100755
--- a/xmake/actions/install/xmake.lua
+++ b/xmake/actions/install/xmake.lua
@@ -26,6 +26,9 @@ task("install")
-- set category
set_category("action")
+ -- on run
+ on_run("main")
+
-- set menu
set_menu({
-- usage
diff --git a/xmake/actions/uninstall/main.lua b/xmake/actions/uninstall/main.lua
new file mode 100755
index 000000000..fb0101efa
--- /dev/null
+++ b/xmake/actions/uninstall/main.lua
@@ -0,0 +1,132 @@
+--!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 main.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.project.task")
+import("core.project.config")
+import("core.project.global")
+import("core.project.project")
+import("core.platform.platform")
+
+-- uninstall binary
+function _uninstall_binary(target)
+
+end
+
+-- uninstall library
+function _uninstall_library(target)
+
+
+end
+
+-- uninstall target
+function _uninstall_target(target)
+
+ -- get kind
+ local kind = target:get("kind")
+
+ -- get script
+ local scripts =
+ {
+ binary = _uninstall_binary
+ , static = _uninstall_library
+ , shared = _uninstall_library
+ }
+
+ -- check
+ assert(scripts[kind], "this target(%s) with kind(%s) can not be uninstalld!", target:name(), kind)
+
+ -- uninstall it
+ scripts[kind](target)
+end
+
+-- uninstall the given target
+function _uninstall(target)
+
+ -- enter project directory
+ os.cd(project.directory())
+
+ -- the target scripts
+ local scripts =
+ {
+ target:get("uninstall_before")
+ , target:get("uninstall") or _uninstall_target
+ , target:get("uninstall_after")
+ }
+
+ -- uninstall the target scripts
+ for i = 1, 3 do
+ local script = scripts[i]
+ if script ~= nil then
+ script(target)
+ end
+ end
+
+ -- leave project directory
+ os.cd("-")
+end
+
+-- uninstall the given target and deps
+function _uninstall_target_and_deps(target)
+
+ -- this target have been finished?
+ if _g.finished[target:name()] then
+ return
+ end
+
+ -- uninstall for all dependent targets
+ for _, depname in ipairs(target:get("deps")) do
+ _uninstall_target_and_deps(project.target(depname))
+ end
+
+ -- uninstall target
+ _uninstall_target(target)
+
+ -- finished
+ _g.finished[target:name()] = true
+end
+
+-- main
+function main()
+
+ -- get the target name
+ local targetname = option.get("target")
+
+ -- init finished states
+ _g.finished = {}
+
+ -- build it first
+ task.run("build", {target = targetname})
+
+ -- uninstall all?
+ if targetname == "all" then
+ for _, target in pairs(project.targets()) do
+ _uninstall_target_and_deps(target)
+ end
+ else
+ _uninstall_target_and_deps(project.target(targetname))
+ end
+
+ -- trace
+ print("uninstall ok!")
+end
diff --git a/xmake/actions/uninstall/xmake.lua b/xmake/actions/uninstall/xmake.lua
index 5cac0ee20..b4ef7e8d4 100755
--- a/xmake/actions/uninstall/xmake.lua
+++ b/xmake/actions/uninstall/xmake.lua
@@ -26,6 +26,9 @@ task("uninstall")
-- set category
set_category("action")
+ -- on run
+ on_run("main")
+
-- set menu
set_menu({
-- usage
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index bb73b6c43..91dba1524 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -106,7 +106,7 @@ function os.cp(src, dst)
-- the destination is directory? append the filename
if os.isdir(dst) then
- dst = string.format("%s/%s", dst, path.filename(src))
+ dst = path.join(dst, path.filename(src))
end
-- copy file
@@ -115,6 +115,12 @@ function os.cp(src, dst)
end
-- is directory?
elseif os.isdir(src) then
+
+ -- the destination directory exists? append the filename
+ if os.isdir(dst) then
+ dst = path.join(dst, path.filename(path.translate(src)))
+ end
+
-- copy directory
if not os.cpdir(src, dst) then
return false, string.format("cannot copy directory %s to %s %s", src, dst, os.strerror())
diff --git a/xmake/core/project/package.lua b/xmake/core/project/package.lua
new file mode 100644
index 000000000..95828a9d9
--- /dev/null
+++ b/xmake/core/project/package.lua
@@ -0,0 +1,42 @@
+--!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
+--
+
+-- define module: package
+local package = package or {}
+
+-- load modules
+local os = require("base/os")
+local io = require("base/io")
+local path = require("base/path")
+local table = require("base/table")
+local utils = require("base/utils")
+local string = require("base/string")
+
+-- the package directory
+function package.directory()
+
+ -- the global directory
+ return path.translate("~/.xmake/packages")
+end
+
+-- return module: package
+return package
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index a76756d08..9d10717f3 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -33,7 +33,9 @@ local filter = require("base/filter")
local interpreter = require("base/interpreter")
local target = require("project/target")
local config = require("project/config")
+local global = require("project/global")
local option = require("project/option")
+local package = require("project/package")
local deprecated_project = require("project/deprecated/project")
local platform = require("platform/platform")
local environment = require("platform/environment")
@@ -489,12 +491,16 @@ function project._interpreter()
os = platform.os()
, host = xmake._HOST
, prefix = "$(prefix)"
+ , tmpdir = os.tmpdir()
+ , curdir = os.curdir()
+ , globaldir = global.directory()
+ , configdir = config.directory()
, projectdir = xmake._PROJECT_DIR
+ , packagedir = package.directory()
}
-- map it
result = maps[variable]
-
end
-- ok?
diff --git a/xmake/core/project/task.lua b/xmake/core/project/task.lua
index dd7eabf2c..a50f4e6e2 100644
--- a/xmake/core/project/task.lua
+++ b/xmake/core/project/task.lua
@@ -34,6 +34,7 @@ local sandbox = require("sandbox/sandbox")
local global = require("project/global")
local config = require("project/config")
local project = require("project/project")
+local package = require("project/package")
-- the directories of tasks
function task._directories()
@@ -194,11 +195,11 @@ function task._interpreter()
, globaldir = global.directory()
, configdir = config.directory()
, projectdir = xmake._PROJECT_DIR
+ , packagedir = package.directory()
}
-- map it
result = maps[variable]
-
end
-- ok?
diff --git a/xmake/core/sandbox/modules/import/core/project/package.lua b/xmake/core/sandbox/modules/import/core/project/package.lua
new file mode 100644
index 000000000..ca8f963b2
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/core/project/package.lua
@@ -0,0 +1,38 @@
+--!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
+--
+
+-- define module
+local sandbox_core_project_package = sandbox_core_project_package or {}
+
+-- load modules
+local package = require("project/package")
+local raise = require("sandbox/modules/raise")
+
+-- run the given package
+function sandbox_core_project_package.directory()
+
+ -- get it
+ return package.directory()
+end
+
+-- return module
+return sandbox_core_project_package