summaryrefslogtreecommitdiff
path: root/xmake/core
diff options
context:
space:
mode:
authorruki <[email protected]>2016-04-19 10:15:50 +0800
committerruki <[email protected]>2016-04-19 10:15:50 +0800
commit223c87f37fb9e8f3ffe808fae5041a1c4aee95d0 (patch)
tree2aad82da78da4444094a83ad5705f5cdeef28cd4 /xmake/core
parent9495e08a20c2aeda6b54a4b06b17057056c79ec9 (diff)
reimpl check tool
Diffstat (limited to 'xmake/core')
-rw-r--r--xmake/core/base/io.lua2
-rw-r--r--xmake/core/sandbox/modules/io.lua4
-rw-r--r--xmake/core/sandbox/modules/os.lua7
-rw-r--r--xmake/core/tool/compiler.lua14
-rw-r--r--xmake/core/tool/linker.lua14
-rw-r--r--xmake/core/tool/tool.lua114
6 files changed, 91 insertions, 64 deletions
diff --git a/xmake/core/base/io.lua b/xmake/core/base/io.lua
index a93a01170..2de9c11c1 100644
--- a/xmake/core/base/io.lua
+++ b/xmake/core/base/io.lua
@@ -217,7 +217,7 @@ function io.readall(filepath)
return data
end
--- write all data to file
+-- write data to file
function io.writall(filepath, data)
-- open file
diff --git a/xmake/core/sandbox/modules/io.lua b/xmake/core/sandbox/modules/io.lua
index b70664722..0fb383862 100644
--- a/xmake/core/sandbox/modules/io.lua
+++ b/xmake/core/sandbox/modules/io.lua
@@ -136,7 +136,7 @@ function sandbox_io.read(filepath)
filepath = vformat(filepath)
-- done
- local result, errors = io.read(filepath)
+ local result, errors = io.readall(filepath)
if not result then
raise(errors)
end
@@ -155,7 +155,7 @@ function sandbox_io.write(filepath, data)
filepath = vformat(filepath)
-- done
- local ok, errors = io.write(filepath, data)
+ local ok, errors = io.writall(filepath, data)
if not ok then
raise(errors)
end
diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua
index 9ab8eb648..fc4f3c195 100644
--- a/xmake/core/sandbox/modules/os.lua
+++ b/xmake/core/sandbox/modules/os.lua
@@ -159,6 +159,13 @@ function sandbox_os.tmpdir()
return tmpdir
end
+-- get the temporary file
+function sandbox_os.tmpfile()
+
+ -- get it
+ return os.tmpname()
+end
+
-- get the program directory
function sandbox_os.programdir()
diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua
index a5f7eafdf..701983411 100644
--- a/xmake/core/tool/compiler.lua
+++ b/xmake/core/tool/compiler.lua
@@ -402,7 +402,7 @@ end
function compiler:command(target, srcfile, objfile, logfile)
-- get it
- return self:_tool().command(srcfile, objfile, self:_flags(target), logfile)
+ return self:_tool().compcmd(srcfile, objfile, self:_flags(target), logfile)
end
-- make the define flag
@@ -444,16 +444,16 @@ function compiler:check(flags)
end
-- check it
- local ok, results = sandbox.load(ctool.check, flags)
- if not ok then
- os.raise(results)
- end
+ local ok, errors = sandbox.load(ctool.check, flags)
-- trace
- utils.printf("checking for the flags %s ... %s", flags, utils.ifelse(results, "ok", "no"))
+ utils.printf("checking for the flags %s ... %s", flags, utils.ifelse(ok, "ok", "no"))
+ if not ok then
+ utils.verbose(errors)
+ end
-- save the checked result
- self._CHECKED[flags] = results
+ self._CHECKED[flags] = ok
-- ok?
return ok
diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua
index 51938ecf1..8d878a7d7 100644
--- a/xmake/core/tool/linker.lua
+++ b/xmake/core/tool/linker.lua
@@ -336,7 +336,7 @@ end
function linker:command(target, objfiles, targetfile, logfile)
-- get it
- return self:_tool().command(table.concat(table.wrap(objfiles), " "), targetfile, self:_flags(target), logfile)
+ return self:_tool().linkcmd(table.concat(table.wrap(objfiles), " "), targetfile, self:_flags(target), logfile)
end
-- make the link flag
@@ -371,16 +371,16 @@ function linker:check(flags)
end
-- check it
- local ok, results = sandbox.load(ltool.check, flags)
- if not ok then
- os.raise(results)
- end
+ local ok, errors = sandbox.load(ltool.check, flags)
-- trace
- utils.printf("checking for the flags %s ... %s", flags, utils.ifelse(results, "ok", "no"))
+ utils.printf("checking for the flags %s ... %s", flags, utils.ifelse(ok, "ok", "no"))
+ if not ok then
+ utils.verbose(errors)
+ end
-- save the checked result
- self._CHECKED[flags] = results
+ self._CHECKED[flags] = ok
-- ok?
return ok
diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua
index 22831ba00..c885f9e48 100644
--- a/xmake/core/tool/tool.lua
+++ b/xmake/core/tool/tool.lua
@@ -38,26 +38,10 @@ local platform = require("platform/platform")
-- the directories of tools
function tool._directories(name)
- -- the kinds
- local kinds =
- {
- cc = "compiler"
- , cxx = "compiler"
- , mm = "compiler"
- , mxx = "compiler"
- , sc = "compiler"
- , ar = "linker"
- , sh = "linker"
- , ld = "linker"
- }
-
- -- get kind sub-directory
- local subdir = kinds[name] or ""
-
-- the directories
- return { path.join(path.join(config.directory(), "tools"), subdir)
- , path.join(path.join(global.directory(), "tools"), subdir)
- , path.join(path.join(xmake._PROGRAM_DIR, "tools"), subdir)
+ return { path.join(config.directory(), "tools")
+ , path.join(global.directory(), "tools")
+ , path.join(xmake._PROGRAM_DIR, "tools")
}
end
@@ -122,30 +106,19 @@ function tool._find(root, name)
return file_ok
end
--- load the given tool from the given kind
---
--- the kinds:
---
--- .e.g cc, cxx, mm, mxx, as, ar, ld, sh, ..
---
-function tool.load(kind)
-
- -- get the shell name
- local shellname = platform.tool(kind)
- if not shellname then
- return nil, string.format("cannot get tool for %s", kind)
- end
+-- load the given tool from the given shell name
+function tool._load(shellname)
-- get it directly from cache dirst
tool._TOOLS = tool._TOOLS or {}
- if tool._TOOLS[kind] then
- return tool._TOOLS[kind]
+ if tool._TOOLS[shellname] then
+ return tool._TOOLS[shellname]
end
-- find the tool script path
local toolpath = nil
local toolname = path.basename(shellname)
- for _, dir in ipairs(tool._directories(kind)) do
+ for _, dir in ipairs(tool._directories()) do
-- find this directory
toolpath = tool._find(dir, toolname)
@@ -182,7 +155,7 @@ function tool.load(kind)
end
-- save tool to the cache
- tool._TOOLS[kind] = module
+ tool._TOOLS[shellname] = module
-- ok?
return module
@@ -192,25 +165,72 @@ function tool.load(kind)
return nil, errors
end
+-- check the shellname
+function tool._check(shellname)
+
+ -- load the tool module
+ local module = tool._load(shellname)
+ if not module then
+ return false
+ end
+
+ -- no checker? attempt to run it directly
+ if not module.check then
+ return 0 == os.execute(string.format("%s > %s 2>&1", shellname, xmake._NULDEV))
+ end
+
+ -- check it
+ local ok, errors = sandbox.load(module.check)
+ if not ok then
+ utils.verbose(errors)
+ end
+
+ -- ok?
+ return ok
+end
+
+-- load the given tool from the given kind
+--
+-- the kinds:
+--
+-- .e.g cc, cxx, mm, mxx, as, ar, ld, sh, ..
+--
+function tool.load(kind)
+
+ -- get the shell name
+ local shellname = platform.tool(kind)
+ if not shellname then
+ return nil, string.format("cannot get tool for %s", kind)
+ end
+
+ -- load it
+ return tool._load(shellname)
+end
+
-- check the tool and return the absolute path if exists
function tool.check(shellname, dirs)
-- check
assert(shellname)
-
- -- FIXME: 7f00
- -- attempt to run it directly first
- if os.execute(string.format("%s > %s 2>&1", shellname, xmake._NULDEV)) ~= 0x7f00 then
+
+ -- attempt to check it directly first
+ if tool._check(shellname) then
return shellname
end
- -- attempt to get it from the given directories
- for _, dir in ipairs(table.wrap(dirs)) do
-
- -- check it
- local toolpath = path.translate(string.format("%s/%s", dir, shellname))
- if os.isfile(toolpath) and os.execute(string.format("%s > %s 2>&1", toolpath, xmake._NULDEV)) ~= 0x7f00 then
- return toolpath
+ -- attempt to check it from the given directories
+ if not path.is_absolute(shellname) then
+ for _, dir in ipairs(table.wrap(dirs)) do
+
+ -- the tool path
+ local toolpath = path.join(dir, shellname)
+ if os.isfile(toolpath) then
+
+ -- check it
+ if tool._check(toolpath) then
+ return toolpath
+ end
+ end
end
end
end