summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-03-23 09:44:57 +0800
committerruki <[email protected]>2016-03-23 09:44:57 +0800
commit7312f0c3b96c79235d95c4cfe1e458a586a5cf81 (patch)
tree0347fde0f886c241e9b71d7ac8e11e4dc76a7aa2
parentfa6157898a39fd68cf0dd2c45593ca4ac1b7d2eb (diff)
impl build action
-rw-r--r--xmake/core/base/io.lua5
-rw-r--r--xmake/core/platform/compiler.lua4
-rw-r--r--xmake/core/platform/linker.lua10
-rw-r--r--xmake/core/platform/tool.lua17
-rw-r--r--xmake/core/platform/tools/make.lua10
-rw-r--r--xmake/core/project/target.lua4
-rw-r--r--xmake/core/sandbox/modules/import.lua7
-rw-r--r--xmake/core/sandbox/modules/import/core/platform/tool.lua20
8 files changed, 51 insertions, 26 deletions
diff --git a/xmake/core/base/io.lua b/xmake/core/base/io.lua
index 9c55b1f2d..ac23814f8 100644
--- a/xmake/core/base/io.lua
+++ b/xmake/core/base/io.lua
@@ -384,6 +384,11 @@ end
-- tail the given file
function io.tail(filepath, linecount)
+ -- all?
+ if linecount < 0 then
+ return io.cat(filepath)
+ end
+
-- open file
local file = io.open(filepath, "r")
if file then
diff --git a/xmake/core/platform/compiler.lua b/xmake/core/platform/compiler.lua
index 000805055..86ef1ef86 100644
--- a/xmake/core/platform/compiler.lua
+++ b/xmake/core/platform/compiler.lua
@@ -404,7 +404,7 @@ function compiler.init(srcfile)
end
-- get compiler tool from the source file type
- instance._TOOL = tool.get(kind)
+ instance._TOOL, errors = tool.get(kind)
if instance._TOOL then
-- invalid compiler
@@ -415,7 +415,7 @@ function compiler.init(srcfile)
-- save kind
instance._KIND = kind
else
- return nil, string.format("unknown compiler for %s", kind)
+ return nil, errors
end
-- ok
diff --git a/xmake/core/platform/linker.lua b/xmake/core/platform/linker.lua
index 015dbac2f..1b4573c92 100644
--- a/xmake/core/platform/linker.lua
+++ b/xmake/core/platform/linker.lua
@@ -284,14 +284,18 @@ function linker.init(kind)
if kind == "binary" then name = "ld"
elseif kind == "static" then name = "ar"
elseif kind == "shared" then name = "sh"
- else return end
+ else
+ return nil, string.format("unknown kind: %s for linker", kind)
+ end
-- init instance
local instance = table.inherit(linker)
-- get the linker tool
- instance._TOOL = tool.get(name)
- assert(instance._TOOL and instance._TOOL.command_link)
+ instance._TOOL, errors = tool.get(name)
+ if not instance._TOOL then
+ return nil, errors
+ end
-- ok?
return instance
diff --git a/xmake/core/platform/tool.lua b/xmake/core/platform/tool.lua
index 4395eeb9a..cc7346179 100644
--- a/xmake/core/platform/tool.lua
+++ b/xmake/core/platform/tool.lua
@@ -150,7 +150,7 @@ function tool.load(name, root)
-- not exists?
if not toolpath or not os.isfile(toolpath) then
- return
+ return nil, string.format("%s not found!", name)
end
-- load script
@@ -160,9 +160,7 @@ function tool.load(name, root)
-- load tool
local ok, result = pcall(script)
if not ok then
- utils.error(result)
- utils.error("load %s failed!", toolpath)
- assert(false)
+ return nil, result
end
-- init tool
@@ -175,11 +173,11 @@ function tool.load(name, root)
-- ok?
return result
- else
- utils.error(errors)
- utils.error("load %s failed!", toolpath)
- assert(false)
end
+
+
+ -- failed
+ return nil, errors
end
-- get the given tool script from the given kind
@@ -188,8 +186,7 @@ function tool.get(kind)
-- get the tool name
local toolname = platform.tool(kind)
if not toolname then
- utils.error("cannot get tool name for %s", kind)
- return
+ return nil, string.format("cannot get tool name for %s", kind)
end
-- load it
diff --git a/xmake/core/platform/tools/make.lua b/xmake/core/platform/tools/make.lua
index c6664fd69..c4ca73de8 100644
--- a/xmake/core/platform/tools/make.lua
+++ b/xmake/core/platform/tools/make.lua
@@ -40,7 +40,7 @@ function make.init(self, name)
end
-- the main function
-function make.main(self, mkfile, target)
+function make.main(self, makefile, target)
-- enable jobs?
local jobs = ""
@@ -54,8 +54,8 @@ function make.main(self, mkfile, target)
-- make command
local cmd = nil
- if mkfile and os.isfile(mkfile) then
- cmd = string.format("%s -r %s -f %s %s VERBOSE=%s", self.name, jobs, mkfile, target or "", self._VERBOSE)
+ if makefile and os.isfile(makefile) then
+ cmd = string.format("%s -r %s -f %s %s VERBOSE=%s", self.name, jobs, makefile, target or "", self._VERBOSE)
else
cmd = string.format("%s -r %s %s VERBOSE=%s", self.name, jobs, target or "", self._VERBOSE)
end
@@ -65,8 +65,8 @@ function make.main(self, mkfile, target)
if ok ~= 0 then
-- attempt to execute it again for getting the error logs without jobs
- if mkfile and os.isfile(mkfile) then
- cmd = string.format("%s -r -f %s %s VERBOSE=%s", self.name, mkfile, target or "", self._VERBOSE)
+ if makefile and os.isfile(makefile) then
+ cmd = string.format("%s -r -f %s %s VERBOSE=%s", self.name, makefile, target or "", self._VERBOSE)
else
cmd = string.format("%s -r %s VERBOSE=%s", self.name, target or "", self._VERBOSE)
end
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 4fef8fbd6..834e9f456 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -70,9 +70,9 @@ function target.linker(self)
assert(self)
-- init the linker from the given kind
- local result = linker.init(self:get("kind"))
+ local result, errors = linker.init(self:get("kind"))
if not result then
- os.raise("cannot get linker with kind: %s", self:get("kind"))
+ os.raise(errors)
end
-- ok?
diff --git a/xmake/core/sandbox/modules/import.lua b/xmake/core/sandbox/modules/import.lua
index 78a7cabee..00669bd15 100644
--- a/xmake/core/sandbox/modules/import.lua
+++ b/xmake/core/sandbox/modules/import.lua
@@ -30,6 +30,7 @@ local utils = require("base/utils")
local table = require("base/table")
local string = require("base/string")
local sandbox = require("sandbox/sandbox")
+local raise = require("sandbox/modules/raise")
-- get module name
function sandbox_import._modulename(name)
@@ -258,13 +259,13 @@ function sandbox_import.import(name, alias, rootdir)
-- check
if not module then
- os.raise("cannot import module: %s, %s", name, errors)
+ raise("cannot import module: %s, %s", name, errors)
end
-- get module name
local modulename = sandbox_import._modulename(name)
if not modulename then
- os.raise("cannot get module name for %s", name)
+ raise("cannot get module name for %s", name)
end
-- get the parent scope
@@ -273,7 +274,7 @@ function sandbox_import.import(name, alias, rootdir)
-- this module has been imported?
if rawget(scope_parent, modulename) then
- os.raise("this module: %s has been imported!", name)
+ raise("this module: %s has been imported!", name)
end
-- import this module into the parent scope
diff --git a/xmake/core/sandbox/modules/import/core/platform/tool.lua b/xmake/core/sandbox/modules/import/core/platform/tool.lua
index 27cb9af52..389400167 100644
--- a/xmake/core/sandbox/modules/import/core/platform/tool.lua
+++ b/xmake/core/sandbox/modules/import/core/platform/tool.lua
@@ -24,7 +24,9 @@
local sandbox_core_platform_tool = sandbox_core_platform_tool or {}
-- load modules
-local platform = require("platform/platform")
+local tool = require("platform/tool")
+local platform = require("platform/platform")
+local raise = require("sandbox/modules/raise")
-- get the tool shell name
function sandbox_core_platform_tool.shellname(name)
@@ -33,5 +35,21 @@ function sandbox_core_platform_tool.shellname(name)
return platform.tool(name)
end
+-- run the tool
+function sandbox_core_platform_tool.run(name, ...)
+
+ -- check
+ assert(name)
+
+ -- get the tool instance
+ local instance, errors = tool.get(name)
+ if not instance then
+ raise(errors)
+ end
+
+ -- run it
+ return instance:main(...)
+end
+
-- return module
return sandbox_core_platform_tool