diff options
| author | ruki <[email protected]> | 2018-07-11 23:57:06 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-07-11 17:42:36 +0800 |
| commit | 9bf2dfab4b53cb2b804bdb599b13b25e104d4b3f (patch) | |
| tree | 610b335c94fb082eb1cd5b1b10f8c20b512e1b6b | |
| parent | 3365fc7ea36a050a3cfba771b78c48d44cb8a6e1 (diff) | |
improve find_path
| -rw-r--r-- | xmake/core/base/os.lua | 6 | ||||
| -rw-r--r-- | xmake/core/base/path.lua | 10 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_path.lua | 14 |
3 files changed, 24 insertions, 6 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 2cf56e3df..4820fa3a1 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -291,11 +291,7 @@ function os.match(pattern, mode, callback) end -- convert pattern to a lua pattern - pattern = pattern:gsub("([%+%.%-%^%$%(%)%%])", "%%%1") - pattern = pattern:gsub("%*%*", "\001") - pattern = pattern:gsub("%*", "\002") - pattern = pattern:gsub("\001", ".*") - pattern = pattern:gsub("\002", "[^/]*") + pattern = path.pattern(pattern) -- find it return os.find(rootdir, pattern, recursion, mode, excludes, callback) diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua index 4b8914ef5..340d57b83 100644 --- a/xmake/core/base/path.lua +++ b/xmake/core/base/path.lua @@ -109,5 +109,15 @@ function path.seperator() end end +-- convert path pattern to a lua pattern +function path.pattern(pattern) + pattern = pattern:gsub("([%+%.%-%^%$%(%)%%])", "%%%1") + pattern = pattern:gsub("%*%*", "\001") + pattern = pattern:gsub("%*", "\002") + pattern = pattern:gsub("\001", ".*") + pattern = pattern:gsub("\002", "[^/]*") + return pattern +end + -- return module: path return path 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 084983b8a..bc60f83fd 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_path.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_path.lua @@ -38,7 +38,19 @@ function sandbox_lib_detect_find_path._find(filedir, name) -- find the first path local results = os.filedirs(path.join(filedir, name), function (file, isdir) return false end) if results and #results > 0 then - return path.directory(results[1]) + local filepath = results[1] + if filepath then + local p = filepath:find(path.pattern(name)) + if p then + filepath = path.translate(filepath:sub(1, p - 1)) + if os.isdir(filepath) then + return filepath + else + return path.directory(filepath) + end + end + end + end end |
