diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2017-06-08 20:06:06 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2017-06-08 20:06:45 +0300 |
commit | 3ca3b89b407ffa1a70d863c3d450dee2fa31ddb7 (patch) | |
tree | 79269c7be086608ccfd6f85cfae399cab24de2c6 | |
parent | d52de69d635ce3fc840fc15b9db4f395d0763aed (diff) |
Add full support for pattern exclusions
-rw-r--r-- | build2/parser.cxx | 55 | ||||
-rw-r--r-- | tests/name/pattern.test | 5 |
2 files changed, 29 insertions, 31 deletions
diff --git a/build2/parser.cxx b/build2/parser.cxx index 71e742c..b6aff19 100644 --- a/build2/parser.cxx +++ b/build2/parser.cxx @@ -2359,6 +2359,23 @@ namespace build2 names r; bool dir (false); + // Figure out the start directory. + // + const dir_path* sp; + dir_path s; + if (dp != nullptr) + { + if (dp->absolute ()) + sp = dp; + else + { + s = *pbase_ / *dp; + sp = &s; + } + } + else + sp = pbase_; + // Compare string to name as paths and according to dir. // auto equal = [&dir] (const string& v, const name& n) -> bool @@ -2371,15 +2388,10 @@ namespace build2 // Compare name to pattern as paths and according to dir. // - auto match = [&dir] (const string& p, const name& n) -> bool + auto match = [&dir, sp] (const path& pattern, const name& n) -> bool { - // Currently exclusions only match the last component to a pattern. - // - string c (dir - ? n.dir.leaf ().representation () - : string (n.value, path::traits::find_leaf (n.value))); - - return butl::path_match (p, c); + const path& p (dir ? path_cast<path> (n.dir) : path (n.value)); + return butl::path_match (pattern, p, *sp); }; // Append string to result according to dir. Store an indication of @@ -2402,7 +2414,7 @@ namespace build2 append (move (m), a); }; - auto include_pattern = [&r, &append, &include_match, dp, this] + auto include_pattern = [&r, &append, &include_match, sp, this] (string&& p, bool a) { // If we don't already have any matches and our pattern doesn't contain @@ -2446,23 +2458,6 @@ namespace build2 return true; }; - // Figure out the start directory. - // - const dir_path* sp; - dir_path s; - if (dp != nullptr) - { - if (dp->absolute ()) - sp = dp; - else - { - s = *pbase_ / *dp; - sp = &s; - } - } - else - sp = pbase_; - butl::path_search (path (move (p)), func, *sp); }; @@ -2480,11 +2475,13 @@ namespace build2 r.erase (i); }; - auto exclude_pattern = [&r, &match] (const string& p) + auto exclude_pattern = [&r, &match] (string&& p) { + path pattern (move (p)); + for (auto i (r.begin ()); i != r.end (); ) { - if (match (p, *i)) + if (match (pattern, *i)) i = r.erase (i); else ++i; @@ -2567,7 +2564,7 @@ namespace build2 else { if (p) - exclude_pattern (v); + exclude_pattern (move (v)); else exclude_match (v); } diff --git a/tests/name/pattern.test b/tests/name/pattern.test index 6606d86..9eff855 100644 --- a/tests/name/pattern.test +++ b/tests/name/pattern.test @@ -95,8 +95,9 @@ EOI touch foo.txt bar.txt; $* <'print {*.txt -bar.txt}' >'foo.txt' : exclude-match - touch foo.txt bar.txt; - $* <'print {*.txt -b*.txt}' >'foo.txt' : exclude-pattern + mkdir baz; + touch foo.txt bar.txt baz/fox.txt baz/box.txt; + $* <'print {**.txt -b*.txt -b*/*}' >'foo.txt' : exclude-pattern touch foo.txt bar.txt baz.txt; $* <'print {*.txt -{*z.txt bar.txt}}' >'foo.txt' : exclude-group |