diff options
| author | ruki <[email protected]> | 2015-06-05 10:18:00 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-05 10:18:00 +0800 |
| commit | 12ce7dea3c7a74f77e9792236cb85bab4fd001e4 (patch) | |
| tree | a64fd1ef7c1380ae63e5c982472e8712489b3374 /xmake/scripts/tools/tools.lua | |
| parent | f9cecfd11c958122bb6d619069593b91333bdf6f (diff) | |
add ccache
Diffstat (limited to 'xmake/scripts/tools/tools.lua')
| -rw-r--r-- | xmake/scripts/tools/tools.lua | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/xmake/scripts/tools/tools.lua b/xmake/scripts/tools/tools.lua index af095618e..abcee4018 100644 --- a/xmake/scripts/tools/tools.lua +++ b/xmake/scripts/tools/tools.lua @@ -73,6 +73,24 @@ function tools._find_from(root, name) end +-- probe it's absolute path if exists from the given tool name and root directory +function tools._probe(root, name) + + -- check + assert(root and name) + + -- make the tool path + local toolpath = string.format("%s/%s", root, name) + toolpath = path.translate(toolpath) + + -- the tool exists? ok + if toolpath and os.isfile(toolpath) then + return toolpath + end +end + + + -- find tool from the given name and directory (optional) function tools.find(name, root) @@ -140,5 +158,32 @@ function tools.get(name) return tools.load(platform.tool(name)) end +-- probe it's absolute path if exists from the given tool name +function tools.probe(name, dirs) + + -- check + assert(name) + + -- attempt to run it directly first + if os.execute(string.format("%s > %s 2>&1", name, xmake._NULDEV)) ~= 0x7f00 then + return name + end + + -- attempt to get it from the given directories + if dirs then + for _, dir in ipairs(dirs) do + + -- probe it + local toolpath = tools._probe(dir, name) + + -- ok? + if toolpath then + return toolpath + end + end + end +end + + -- return module: tools return tools |
