diff options
| author | ruki <[email protected]> | 2016-04-19 10:15:50 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-04-19 10:15:50 +0800 |
| commit | 223c87f37fb9e8f3ffe808fae5041a1c4aee95d0 (patch) | |
| tree | 2aad82da78da4444094a83ad5705f5cdeef28cd4 | |
| parent | 9495e08a20c2aeda6b54a4b06b17057056c79ec9 (diff) | |
reimpl check tool
| -rw-r--r-- | xmake/core/base/io.lua | 2 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/io.lua | 4 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 7 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 14 | ||||
| -rw-r--r-- | xmake/core/tool/linker.lua | 14 | ||||
| -rw-r--r-- | xmake/core/tool/tool.lua | 114 | ||||
| -rw-r--r-- | xmake/tools/ar.lua (renamed from xmake/tools/linker/ar.lua) | 11 | ||||
| -rwxr-xr-x | xmake/tools/clang++.lua (renamed from xmake/tools/compiler/clang++.lua) | 0 | ||||
| -rwxr-xr-x | xmake/tools/clang.lua (renamed from xmake/tools/linker/clang.lua) | 5 | ||||
| -rwxr-xr-x | xmake/tools/compiler/clang.lua | 38 | ||||
| -rwxr-xr-x | xmake/tools/g++.lua (renamed from xmake/tools/compiler/g++.lua) | 0 | ||||
| -rwxr-xr-x | xmake/tools/gcc.lua (renamed from xmake/tools/compiler/gcc.lua) | 66 | ||||
| -rwxr-xr-x | xmake/tools/linker/clang++.lua | 33 | ||||
| -rwxr-xr-x | xmake/tools/linker/g++.lua | 33 | ||||
| -rwxr-xr-x | xmake/tools/linker/gcc.lua | 101 | ||||
| -rw-r--r-- | xmake/tools/make.lua | 21 | ||||
| -rw-r--r-- | xmake/tools/swiftc.lua (renamed from xmake/tools/compiler/swiftc.lua) | 9 |
17 files changed, 176 insertions, 296 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 diff --git a/xmake/tools/linker/ar.lua b/xmake/tools/ar.lua index 484ba3199..0999672f1 100644 --- a/xmake/tools/linker/ar.lua +++ b/xmake/tools/ar.lua @@ -46,8 +46,8 @@ end function linkdir(dir) end --- make the command -function command(objfiles, targetfile, flags, logfile) +-- make the link command +function linkcmd(objfiles, targetfile, flags, logfile) -- redirect local redirect = "" @@ -63,3 +63,10 @@ function run(...) -- run it os.run(...) end + +-- check the given flags +function check(flags) + + -- check it + os.run("%s %s", _g.shellname, ifelse(flags, flags, "")) +end diff --git a/xmake/tools/compiler/clang++.lua b/xmake/tools/clang++.lua index 6b2feaa2f..6b2feaa2f 100755 --- a/xmake/tools/compiler/clang++.lua +++ b/xmake/tools/clang++.lua diff --git a/xmake/tools/linker/clang.lua b/xmake/tools/clang.lua index 712b578e3..27bce4e3a 100755 --- a/xmake/tools/linker/clang.lua +++ b/xmake/tools/clang.lua @@ -32,6 +32,11 @@ function init(shellname) -- init shflags _super._g.shflags = { "-dynamiclib", "-fPIC" } + -- suppress warning + _super._g.cxflags = {"-Qunused-arguments"} + _super._g.mxflags = {"-Qunused-arguments"} + _super._g.asflags = {"-Qunused-arguments"} + -- init flags map _super._g.mapflags["-s"] = "-Wl,-S" _super._g.mapflags["-S"] = "-Wl,-S" diff --git a/xmake/tools/compiler/clang.lua b/xmake/tools/compiler/clang.lua deleted file mode 100755 index 253e14270..000000000 --- a/xmake/tools/compiler/clang.lua +++ /dev/null @@ -1,38 +0,0 @@ ---!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 clang.lua --- - --- inherit gcc -inherit("gcc") - --- init it -function init(shellname) - - -- init super - _super.init(shellname or "clang") - - -- suppress warning - _super._g.cxflags = {"-Qunused-arguments"} - _super._g.mxflags = {"-Qunused-arguments"} - _super._g.asflags = {"-Qunused-arguments"} - -end - diff --git a/xmake/tools/compiler/g++.lua b/xmake/tools/g++.lua index 7b2837b8e..7b2837b8e 100755 --- a/xmake/tools/compiler/g++.lua +++ b/xmake/tools/g++.lua diff --git a/xmake/tools/compiler/gcc.lua b/xmake/tools/gcc.lua index ebe5c492f..9e0f55671 100755 --- a/xmake/tools/compiler/gcc.lua +++ b/xmake/tools/gcc.lua @@ -34,6 +34,9 @@ function init(shellname) , "\"-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))\"" , "\"-DIBAction=void)__attribute__((ibaction)\""} + -- init shflags + _g.shflags = { "-shared", "-fPIC" } + -- init cxflags for the kind: shared _g.shared = {} _g.shared.cxflags = {"-fPIC"} @@ -42,10 +45,14 @@ function init(shellname) _g.mapflags = { -- warnings - ["-W1"] = "-Wall" - , ["-W2"] = "-Wall" - , ["-W3"] = "-Wall" - + ["-W1"] = "-Wall" + , ["-W2"] = "-Wall" + , ["-W3"] = "-Wall" + + -- strip + , ["-s"] = "-s" + , ["-S"] = "-S" + } end @@ -77,8 +84,22 @@ function includedir(dir) return "-I" .. dir end --- make the command -function command(srcfile, objfile, flags, logfile) +-- make the link flag +function link(lib) + + -- make it + return "-l" .. lib +end + +-- make the linkdir flag +function linkdir(dir) + + -- make it + return "-L" .. dir +end + +-- make the complie command +function compcmd(srcfile, objfile, flags, logfile) -- redirect local redirect = "" @@ -88,26 +109,15 @@ function command(srcfile, objfile, flags, logfile) return format("%s -c %s -o %s %s%s", _g.shellname, flags, objfile, srcfile, redirect) end --- check the given flags -function check(flags) +-- make the link command +function linkcmd(objfiles, targetfile, flags, logfile) - -- done - local ok = false - try - { - function () - - -- check it - os.run("%s %s -S -o %s -xc %s > %s 2>&1", _g.shellname, flags, os.nuldev(), os.nuldev(), os.nuldev()) - - -- ok - ok = true - - end - } + -- redirect + local redirect = "" + if logfile then redirect = format(" > %s 2>&1", logfile) end - -- ok? - return ok + -- make it + return format("%s -o %s %s %s%s", _g.shellname, targetfile, objfiles, flags, redirect) end -- run command @@ -116,3 +126,11 @@ function run(...) -- run it os.run(...) end + +-- check the given flags +function check(flags) + + -- check it + os.run("%s %s -S -o %s -xc %s", _g.shellname, ifelse(flags, flags, ""), os.nuldev(), os.nuldev()) +end + diff --git a/xmake/tools/linker/clang++.lua b/xmake/tools/linker/clang++.lua deleted file mode 100755 index 6b2feaa2f..000000000 --- a/xmake/tools/linker/clang++.lua +++ /dev/null @@ -1,33 +0,0 @@ ---!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 clang++.lua --- - --- inherit clang -inherit("clang") - --- init it -function init(shellname) - - -- init super - _super.init(shellname or "clang++") - -end - diff --git a/xmake/tools/linker/g++.lua b/xmake/tools/linker/g++.lua deleted file mode 100755 index 7b2837b8e..000000000 --- a/xmake/tools/linker/g++.lua +++ /dev/null @@ -1,33 +0,0 @@ ---!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 g++.lua --- - --- inherit gcc -inherit("gcc") - --- init it -function init(shellname) - - -- init super - _super.init(shellname or "g++") - -end - diff --git a/xmake/tools/linker/gcc.lua b/xmake/tools/linker/gcc.lua deleted file mode 100755 index 35c263e34..000000000 --- a/xmake/tools/linker/gcc.lua +++ /dev/null @@ -1,101 +0,0 @@ ---!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 gcc.lua --- - --- init it -function init(shellname) - - -- save the shell name - _g.shellname = shellname or "gcc" - - -- init shflags - _g.shflags = { "-shared", "-fPIC" } - - -- init flags map - _g.mapflags = - { - -- strip - ["-s"] = "-s" - , ["-S"] = "-S" - - } -end - --- get the property -function get(name) - - -- get it - return _g[name] -end - --- make the link flag -function link(lib) - - -- make it - return "-l" .. lib -end - --- make the linkdir flag -function linkdir(dir) - - -- make it - return "-L" .. dir -end - --- make the command -function command(objfiles, targetfile, flags, logfile) - - -- redirect - local redirect = "" - if logfile then redirect = format(" > %s 2>&1", logfile) end - - -- make it - return format("%s -o %s %s %s%s", _g.shellname, targetfile, objfiles, flags, redirect) -end - --- check the given flags -function check(flags) - - -- done - local ok = false - try - { - function () - - -- check it - os.run("%s %s -S -o %s -xc %s > %s 2>&1", _g.shellname, flags, os.nuldev(), os.nuldev(), os.nuldev()) - - -- ok - ok = true - - end - } - - -- ok? - return ok -end - --- run command -function run(...) - - -- run it - os.run(...) -end diff --git a/xmake/tools/make.lua b/xmake/tools/make.lua index 8cab41067..2785eaf73 100644 --- a/xmake/tools/make.lua +++ b/xmake/tools/make.lua @@ -31,6 +31,13 @@ function init(shellname) end +-- get the property +function get(name) + + -- get it + return _g[name] +end + -- run it function run(makefile, target, jobs) @@ -74,3 +81,17 @@ function run(makefile, target, jobs) end end + +-- check the given flags +function check(flags) + + -- make an empty makefile + local tmpfile = os.tmpfile() + io.write(tmpfile, "all:\n") + + -- check it + os.run("%s %s -f %s", _g.shellname, ifelse(flags, flags, ""), tmpfile) + + -- remove this makefile + os.rm(tmpfile) +end diff --git a/xmake/tools/compiler/swiftc.lua b/xmake/tools/swiftc.lua index 517df88a8..65e6f8245 100644 --- a/xmake/tools/compiler/swiftc.lua +++ b/xmake/tools/swiftc.lua @@ -72,7 +72,7 @@ function get(name) end -- make the compile command -function command(srcfile, objfile, flags, logfile) +function compcmd(srcfile, objfile, flags, logfile) -- redirect local redirect = "" @@ -103,3 +103,10 @@ function undefine(macro) return "-Xcc -U" .. macro end +-- run command +function run(...) + + -- run it + os.run(...) +end + |
