summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-05-05 11:16:32 +0800
committerruki <[email protected]>2016-05-05 11:16:32 +0800
commitf68de1b816bd631634a82d6cd8c8ea4636961a54 (patch)
tree2c6721241cfe821dcb96386a6705fe7496acd213
parentc5818eef6be6d364bacfc32f7ec71154f71b6f96 (diff)
modify assert and check target
-rwxr-xr-xxmake/actions/build/builder.lua42
-rwxr-xr-xxmake/actions/build/main.lua22
-rw-r--r--xmake/core/sandbox/modules/assert.lua2
-rw-r--r--xmake/core/sandbox/modules/utils.lua18
4 files changed, 68 insertions, 16 deletions
diff --git a/xmake/actions/build/builder.lua b/xmake/actions/build/builder.lua
index fc64e8e1b..4113b8ef7 100755
--- a/xmake/actions/build/builder.lua
+++ b/xmake/actions/build/builder.lua
@@ -17,7 +17,7 @@
-- Copyright (C) 2015 - 2016, ruki All rights reserved.
--
-- @author ruki
--- @file build.lua
+-- @file builder.lua
--
-- imports
@@ -28,14 +28,50 @@ import("core.project.project")
import("core.project.cache")
import("core.tool.tool")
--- make target
+-- get target
+function _target(targetname)
+
+ -- get and check it
+ return assert(project.target(targetname), "unknown target: %s", targetname)
+end
+
+-- make the given target
+function _make_target(target)
+
+ -- make for all dependent targets
+ for _, depname in ipairs(target:get("deps")) do
+ _make_target(_target(depname))
+ end
+
+ -- trace
+ print("make target: %s", target:name())
+end
+
+-- make
function make(targetname)
+ -- make all targets
+ if targetname == "all" then
+
+ -- make all targets
+ for _, target in pairs(project.targets()) do
+ _make_target(target)
+ end
+ else
+
+ -- make target
+ _make_target(_target(targetname))
+ end
end
--- make target from makefile
+-- make from makefile
function make_from_makefile(targetname)
+ -- check target
+ if targetname ~= "all" then
+ _target(targetname)
+ end
+
-- make makefile
task.run("makefile", {output = path.join(config.get("buildir"), "makefile")})
diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua
index a08794005..d690bb303 100755
--- a/xmake/actions/build/main.lua
+++ b/xmake/actions/build/main.lua
@@ -103,11 +103,6 @@ function main()
-- 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())
@@ -116,11 +111,11 @@ function main()
{
function ()
- -- make target
--- builder.make(targetname)
+ -- make
+-- builder.make(targetname or "all")
- -- make target from makefile
- builder.make_from_makefile(targetname)
+ -- make from makefile
+ builder.make_from_makefile(targetname or "all")
end,
@@ -130,10 +125,13 @@ function main()
-- show error log
io.tail("$(buildir)/.build.log", ifelse(option.get("verbose"), -1, 32))
-
+
-- failed
- raise("build target: %s failed!", targetname)
-
+ if errors then
+ raise(errors)
+ else
+ raise("build target: %s failed!", targetname)
+ end
end
}
}
diff --git a/xmake/core/sandbox/modules/assert.lua b/xmake/core/sandbox/modules/assert.lua
index 1e64c73db..1b454195e 100644
--- a/xmake/core/sandbox/modules/assert.lua
+++ b/xmake/core/sandbox/modules/assert.lua
@@ -21,5 +21,5 @@
--
-- load module
-return assert
+return require("sandbox/modules/utils").assert
diff --git a/xmake/core/sandbox/modules/utils.lua b/xmake/core/sandbox/modules/utils.lua
index d5f5c73c7..d419c257e 100644
--- a/xmake/core/sandbox/modules/utils.lua
+++ b/xmake/core/sandbox/modules/utils.lua
@@ -24,6 +24,7 @@
local io = require("base/io")
local utils = require("base/utils")
local vformat = require("sandbox/modules/vformat")
+local raise = require("sandbox/modules/raise")
-- define module
local sandbox_utils = sandbox_utils or {}
@@ -54,6 +55,23 @@ function sandbox_utils.printf(format, ...)
return io.write(vformat(format, ...))
end
+-- assert
+function sandbox_utils.assert(value, format, ...)
+
+ -- check
+ if not value then
+ if format ~= nil then
+ raise(format, ...)
+ else
+ raise("assertion failed!")
+ end
+ end
+
+ -- return it
+ return value
+end
+
+
-- return module
return sandbox_utils