aboutsummaryrefslogtreecommitdiff
path: root/build2/target.txx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-08-07 14:59:07 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-08-07 14:59:07 +0200
commite4f41c7319261b9585bd501256664679457e1d9d (patch)
tree21ef10a30d932a3172080de2690c6e38d851d0e2 /build2/target.txx
parent7149c8eaeec3efcfc9da0f89c9ae979ff2c07fd5 (diff)
Add support for default extension specification, trailing dot escaping
For example: cxx{*}: extension = cxx cxx{foo} # foo.cxx cxx{foo.test} # foo.test (probably what we want...) cxx{foo.test...} # foo.test.cxx (... is this) cxx{foo..} # foo. cxx{foo....} # foo.. cxx{foo.....} # error (must come in escape pair)
Diffstat (limited to 'build2/target.txx')
-rw-r--r--build2/target.txx51
1 files changed, 22 insertions, 29 deletions
diff --git a/build2/target.txx b/build2/target.txx
index d832d6b..8030c1a 100644
--- a/build2/target.txx
+++ b/build2/target.txx
@@ -55,29 +55,27 @@ namespace build2
template <const char* ext>
bool
- target_pattern_fix (const target_type&, const scope&, string& v, bool r)
+ target_pattern_fix (const target_type&,
+ const scope&,
+ string&,
+ optional<string>& e,
+ bool r)
{
- size_t p (path::traits::find_extension (v));
-
if (r)
{
// If we get called to reverse then it means we've added the extension
- // in the first place. So simply strip it.
+ // in the first place.
//
- assert (p != string::npos);
- v.resize (p);
+ assert (e);
+ e = nullopt;
}
//
// We only add our extension if there isn't one already.
//
- else if (p == string::npos)
+ else if (!e)
{
- if (*ext != '\0') // Don't add empty extension (means no extension).
- {
- v += '.';
- v += ext;
- return true;
- }
+ e = ext;
+ return true;
}
return false;
@@ -115,35 +113,30 @@ namespace build2
template <const char* var, const char* def>
bool
- target_pattern_var (const target_type& tt, const scope& s, string& v, bool r)
+ target_pattern_var (const target_type& tt,
+ const scope& s,
+ string&,
+ optional<string>& e,
+ bool r)
{
- size_t p (path::traits::find_extension (v));
-
if (r)
{
// If we get called to reverse then it means we've added the extension
- // in the first place. So simply strip it.
+ // in the first place.
//
- assert (p != string::npos);
- v.resize (p);
+ assert (e);
+ e = nullopt;
}
//
// We only add our extension if there isn't one already.
//
- else if (p == string::npos)
+ else if (!e)
{
// Use empty name as a target since we only want target type/pattern-
// specific variables that match any target (e.g., '*' but not '*.txt').
//
- if (auto e = target_extension_var_impl (tt, string (), s, var, def))
- {
- if (!e->empty ()) // Don't add empty extension (means no extension).
- {
- v += '.';
- v += *e;
- return true;
- }
- }
+ if ((e = target_extension_var_impl (tt, string (), s, var, def)))
+ return true;
}
return false;