summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-04-28 20:36:20 +0800
committerruki <[email protected]>2016-04-28 20:41:19 +0800
commit6acc7c9d410f46d804a8f278badf14e7e99ea1be (patch)
tree26fcbab400dda4d6d55303215dc021cc4a9e9806
parent0d9ea7b88dc9cef68c4823bd671fca17d0e4fccf (diff)
add build action
-rwxr-xr-x.gitignore1
-rwxr-xr-xxmake/actions/build/main.lua144
-rwxr-xr-xxmake/actions/build/xmake.lua55
-rw-r--r--xmake/core/base/option.lua1
4 files changed, 200 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index e2ed6d817..91a04017f 100755
--- a/.gitignore
+++ b/.gitignore
@@ -34,3 +34,4 @@ core/pre
core/tool/msys
core/xmake.config.h
core/.config.mak
+!xmake/actions/build
diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua
new file mode 100755
index 000000000..8c118a24b
--- /dev/null
+++ b/xmake/actions/build/main.lua
@@ -0,0 +1,144 @@
+--!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.project.cache")
+import("core.platform.platform")
+import("core.tool.tool")
+
+-- project files(xmake.lua) have been changed?
+function _project_changed(targetname)
+
+ -- get the current mtimes
+ local mtimes = project.mtimes()
+
+ -- get the previous mtimes
+ local changed = false
+ local mtimes_prev = cache.get("mtimes")
+ if mtimes_prev then
+
+ -- check for all project files
+ for file, mtime in pairs(mtimes) do
+
+ -- modified? reconfig and rebuild it
+ local mtime_prev = mtimes_prev[file]
+ if not mtime_prev or mtime > mtime_prev then
+ changed = true
+ break
+ end
+ end
+ end
+
+ -- update mtimes
+ cache.set("mtimes", mtimes)
+
+ -- changed?
+ return changed
+end
+
+-- main
+function main()
+
+ -- check xmake.lua
+ if not os.isfile(project.file()) then
+ raise("xmake.lua not found!")
+ end
+
+ -- get the target name
+ local targetname = option.get("target")
+
+ -- load project configure
+ config.load(targetname)
+
+ -- load platform
+ platform.load(config.plat())
+
+ -- load project
+ project.load()
+
+ -- enter cache scope: build
+ cache.enter("local.build")
+
+ -- host changed or project changed? reconfig it
+ if config.host() ~= os.host() or _project_changed(targetname) then
+
+ -- config it first
+ task.run("config", {target = targetname})
+ end
+
+ -- rebuild?
+ if option.get("rebuild") or cache.get("rebuild") then
+
+ -- clean it first
+ task.run("clean", {target = targetname})
+
+ -- reset state
+ cache.set("rebuild", nil)
+ end
+
+ -- flush cache to file
+ cache.flush()
+
+ -- check target
+ if targetname and targetname ~= "all" and nil == project.target(targetname) then
+ raise("unknown target: %s", targetname)
+ end
+
+ -- enter project directory
+ os.cd(project.directory())
+
+ -- build it
+ try
+ {
+ function ()
+
+ -- run make
+ tool.run("make", path.join(config.get("buildir"), "makefile"), targetname, option.get("jobs"))
+
+ end,
+
+ catch
+ {
+ function (errors)
+
+ -- show error log
+ io.tail("$(buildir)/.build.log", ifelse(option.get("verbose"), -1, 32))
+
+ -- failed
+ raise("build target: %s failed!", targetname)
+
+ end
+ }
+ }
+
+ -- leave project directory
+ os.cd("-")
+
+ -- trace
+ print("build ok!")
+
+end
diff --git a/xmake/actions/build/xmake.lua b/xmake/actions/build/xmake.lua
new file mode 100755
index 000000000..90d11efed
--- /dev/null
+++ b/xmake/actions/build/xmake.lua
@@ -0,0 +1,55 @@
+--!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 xmake.lua
+--
+
+-- define task
+task("build")
+
+ -- set category
+ set_task_category("main")
+
+ -- on run
+ on_task_run("main")
+
+ -- set menu
+ set_task_menu({
+ -- usage
+ usage = "xmake [task] [options] [target]"
+
+ -- description
+ , description = "Build the project if no given tasks."
+
+ -- options
+ , options =
+ {
+ {'b', "build", "k", nil, "Build project. This is default building mode and optional." }
+ , {'r', "rebuild", "k", nil, "Rebuild the project." }
+
+ , {}
+ , {'j', "jobs", "kv", nil, "Specifies the number of jobs to build simultaneously" }
+
+ , {}
+ , {nil, "target", "v", "all", "Build the given target." }
+ }
+ })
+
+
+
diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua
index ad103ccbb..532eb3301 100644
--- a/xmake/core/base/option.lua
+++ b/xmake/core/base/option.lua
@@ -52,7 +52,6 @@ function option._translate(menu)
-- save menu
option._MENU = menu
-
end
-- get the task menu