diff options
| author | ruki <[email protected]> | 2017-05-18 09:19:14 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-05-18 09:19:14 +0800 |
| commit | 36039001e207f21bb9c7af5baaa1e208d4743f3d (patch) | |
| tree | bd9bcc5178f56644c9c4d3f58e67dbb031711853 | |
| parent | 49dc5aa853cf5fb900c454d1f40b241af2b75501 (diff) | |
impl find file and path
| -rw-r--r-- | xmake/actions/build/kinds/object.lua | 2 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_file.lua | 39 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_path.lua | 41 | ||||
| -rw-r--r-- | xmake/modules/detect/tool/find_7z.lua (renamed from xmake/modules/lib/detect/find_7z.lua) | 0 | ||||
| -rw-r--r-- | xmake/modules/detect/tool/find_ccache.lua (renamed from xmake/modules/lib/detect/find_ccache.lua) | 0 | ||||
| -rw-r--r-- | xmake/modules/detect/tool/find_curl.lua (renamed from xmake/modules/lib/detect/find_curl.lua) | 0 | ||||
| -rw-r--r-- | xmake/modules/detect/tool/find_git.lua (renamed from xmake/modules/lib/detect/find_git.lua) | 0 | ||||
| -rw-r--r-- | xmake/modules/detect/tool/find_gzip.lua (renamed from xmake/modules/lib/detect/find_gzip.lua) | 0 | ||||
| -rw-r--r-- | xmake/modules/detect/tool/find_tar.lua (renamed from xmake/modules/lib/detect/find_tar.lua) | 0 | ||||
| -rw-r--r-- | xmake/modules/detect/tool/find_unzip.lua (renamed from xmake/modules/lib/detect/find_unzip.lua) | 0 | ||||
| -rw-r--r-- | xmake/modules/detect/tool/find_wget.lua (renamed from xmake/modules/lib/detect/find_wget.lua) | 0 | ||||
| -rw-r--r-- | xmake/tools/gcc.lua | 2 | ||||
| -rw-r--r-- | xmake/tools/swiftc.lua | 2 |
13 files changed, 72 insertions, 14 deletions
diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua index e3dbce956..367b5c437 100644 --- a/xmake/actions/build/kinds/object.lua +++ b/xmake/actions/build/kinds/object.lua @@ -28,7 +28,7 @@ import("core.tool.tool") import("core.tool.compiler") import("core.tool.extractor") import("core.project.config") -import("lib.detect.find_ccache") +import("detect.tool.find_ccache") -- build the object from the *.[o|obj] source file function _build_from_object(target, sourcefile, objectfile, percent) diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_file.lua b/xmake/core/sandbox/modules/import/lib/detect/find_file.lua index ca873ee71..9fc2f17a6 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_file.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_file.lua @@ -26,13 +26,42 @@ local sandbox_lib_detect_find_file = sandbox_lib_detect_find_file or {} -- load modules -local raise = require("sandbox/modules/raise") +local os = require("base/os") +local path = require("base/path") +local raise = require("sandbox/modules/raise") -- find file -function sandbox_lib_detect_find_file.main(...) - - -- TODO - print("find file") +-- +-- @param name the file name +-- @param dirs the file directories +-- +-- @return the file path +-- +-- @code +-- +-- local file = find_file("ccache", { "/usr/bin", "/usr/local/bin"}) +-- local file = find_file("test.h", { "/usr/include", "/usr/local/include/**"}) +-- +-- @endcode +-- +function sandbox_lib_detect_find_file.main(name, dirs) + + -- find file + local result = nil + for _, dir in ipairs(dirs) do + + -- TODO + -- dir is registry path? + + -- file exists? + for _, file in ipairs(os.files(path.join(dir, name))) do + result = file + break + end + end + + -- ok? + return result end -- return module diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_path.lua b/xmake/core/sandbox/modules/import/lib/detect/find_path.lua index fe2b4993d..bbc48c08a 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_path.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_path.lua @@ -26,13 +26,42 @@ local sandbox_lib_detect_find_path = sandbox_lib_detect_find_path or {} -- load modules -local raise = require("sandbox/modules/raise") +local os = require("base/os") +local path = require("base/path") +local raise = require("sandbox/modules/raise") --- find file -function sandbox_lib_detect_find_path.main(...) - - -- TODO - print("find path") +-- find path +-- +-- @param name the path name +-- @param dirs the path directories +-- +-- @return the path +-- +-- @code +-- +-- local p = find_path("include/test.h", { "/usr", "/usr/local"}) +-- local p = find_path("include/*.h", { "/usr", "/usr/local/**"}) +-- +-- @endcode +-- +function sandbox_lib_detect_find_path.main(name, dirs) + + -- find file + local result = nil + for _, dir in ipairs(dirs) do + + -- TODO + -- dir is registry path? + + -- path exists? + for _, p in ipairs(os.filedirs(path.join(dir, name))) do + result = p + break + end + end + + -- ok? + return result end -- return module diff --git a/xmake/modules/lib/detect/find_7z.lua b/xmake/modules/detect/tool/find_7z.lua index d0fdae402..d0fdae402 100644 --- a/xmake/modules/lib/detect/find_7z.lua +++ b/xmake/modules/detect/tool/find_7z.lua diff --git a/xmake/modules/lib/detect/find_ccache.lua b/xmake/modules/detect/tool/find_ccache.lua index 30348c6e6..30348c6e6 100644 --- a/xmake/modules/lib/detect/find_ccache.lua +++ b/xmake/modules/detect/tool/find_ccache.lua diff --git a/xmake/modules/lib/detect/find_curl.lua b/xmake/modules/detect/tool/find_curl.lua index 56fcee857..56fcee857 100644 --- a/xmake/modules/lib/detect/find_curl.lua +++ b/xmake/modules/detect/tool/find_curl.lua diff --git a/xmake/modules/lib/detect/find_git.lua b/xmake/modules/detect/tool/find_git.lua index 00665d8be..00665d8be 100644 --- a/xmake/modules/lib/detect/find_git.lua +++ b/xmake/modules/detect/tool/find_git.lua diff --git a/xmake/modules/lib/detect/find_gzip.lua b/xmake/modules/detect/tool/find_gzip.lua index 2ec660cfe..2ec660cfe 100644 --- a/xmake/modules/lib/detect/find_gzip.lua +++ b/xmake/modules/detect/tool/find_gzip.lua diff --git a/xmake/modules/lib/detect/find_tar.lua b/xmake/modules/detect/tool/find_tar.lua index 503701e0a..503701e0a 100644 --- a/xmake/modules/lib/detect/find_tar.lua +++ b/xmake/modules/detect/tool/find_tar.lua diff --git a/xmake/modules/lib/detect/find_unzip.lua b/xmake/modules/detect/tool/find_unzip.lua index 006d18be2..006d18be2 100644 --- a/xmake/modules/lib/detect/find_unzip.lua +++ b/xmake/modules/detect/tool/find_unzip.lua diff --git a/xmake/modules/lib/detect/find_wget.lua b/xmake/modules/detect/tool/find_wget.lua index 13b12c43e..13b12c43e 100644 --- a/xmake/modules/lib/detect/find_wget.lua +++ b/xmake/modules/detect/tool/find_wget.lua diff --git a/xmake/tools/gcc.lua b/xmake/tools/gcc.lua index 7dd1e6e6c..7cd135215 100644 --- a/xmake/tools/gcc.lua +++ b/xmake/tools/gcc.lua @@ -27,7 +27,7 @@ import("core.tool.tool") import("core.base.option") import("core.project.config") import("core.project.project") -import("lib.detect.find_ccache") +import("detect.tool.find_ccache") -- init it function init(shellname, kind) diff --git a/xmake/tools/swiftc.lua b/xmake/tools/swiftc.lua index e8edd8952..8a52125e4 100644 --- a/xmake/tools/swiftc.lua +++ b/xmake/tools/swiftc.lua @@ -25,7 +25,7 @@ -- imports import("core.tool.tool") import("core.project.config") -import("lib.detect.find_ccache") +import("detect.tool.find_ccache") -- init it function init(shellname, kind) |
