diff options
| author | ruki <[email protected]> | 2018-05-02 23:25:59 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-05-02 14:35:58 +0800 |
| commit | 4bda9b04b16460c93f6342a17c93cf07f191b7cc (patch) | |
| tree | b2aafa6646ec79db030fe71f056cc64c8d326e0c /xmake/core/base/os.lua | |
| parent | cb8d8dcf2b7a698e7a6c31f1e58722b505132f32 (diff) | |
improve os.match
Diffstat (limited to 'xmake/core/base/os.lua')
| -rw-r--r-- | xmake/core/base/os.lua | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 32028b231..71a6119f6 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -265,14 +265,30 @@ function os.match(pattern, mode, callback) -- get the root directory local rootdir = pattern - local starpos = pattern:find("%*") - if starpos then - rootdir = rootdir:sub(1, starpos - 1) + local startpos = pattern:find("*", 1, true) + if startpos then + rootdir = rootdir:sub(1, startpos - 1) end rootdir = path.directory(rootdir) - -- is recurse? - local recurse = pattern:find("**", nil, true) + -- compute the recursion level + -- + -- infinite recursion: src/**.c + -- limit recursion level: src/*/*.c + local recursion = 0 + if pattern:find("**", 1, true) then + recursion = -1 + else + -- "src/*/*.c" -> "*/" -> recursion level: 1 + -- "src/*/main.c" -> "*/" -> recursion level: 1 + -- "src/*/subdir/main.c" -> "*//" -> recursion level: 2 + if startpos then + local _, seps = pattern:sub(startpos):gsub("[/\\]", "") + if seps > 0 then + recursion = seps + end + end + end -- convert pattern to a lua pattern pattern = pattern:gsub("([%+%.%-%^%$%(%)%%])", "%%%1") @@ -282,7 +298,7 @@ function os.match(pattern, mode, callback) pattern = pattern:gsub("\002", "[^/]*") -- find it - return os.find(rootdir, pattern, recurse, mode, excludes, callback) + return os.find(rootdir, pattern, recursion, mode, excludes, callback) end -- match directories |
