From aec5f7309b2ee7210dc39de9c792f35273c73c10 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 24 Jan 2016 12:03:50 +0200 Subject: Differentiate extension printing according to stream verbosity --- build2/target.cxx | 64 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 8 deletions(-) (limited to 'build2/target.cxx') diff --git a/build2/target.cxx b/build2/target.cxx index 89e16b5..3fd099d 100644 --- a/build2/target.cxx +++ b/build2/target.cxx @@ -248,7 +248,7 @@ namespace build2 } ostream& - operator<< (ostream& os, const target_key& k) + to_stream (ostream& os, const target_key& k, uint16_t ev) { // If the name is empty, then we want to print the directory // inside {}, e.g., dir{bar/}, not bar/dir{}. @@ -271,8 +271,22 @@ namespace build2 { os << *k.name; - if (k.ext != nullptr && !k.ext->empty ()) - os << '.' << *k.ext; + // If the extension derivation function is NULL, then it means this + // target type doesn't use extensions. + // + if (k.type->extension != nullptr) + { + // For verbosity level 0 we don't print the extension. For 1 we print + // it if there is one. For 2 we print 'foo.?' if it hasn't yet been + // assigned and 'foo.' if it is assigned as "no extension" (empty). + // + if (ev > 0 && (ev > 1 || (k.ext != nullptr && !k.ext->empty ()))) + { + os << '.' << (k.ext != nullptr ? *k.ext : "?"); + } + } + else + assert (k.ext == nullptr); } else os << *k.dir; @@ -282,6 +296,17 @@ namespace build2 return os; } + ostream& + operator<< (ostream& os, const target_key& k) + { + if (auto p = k.type->print) + p (os, k); + else + to_stream (os, k, stream_verb (os)); + + return os; + } + // path_target // void path_target:: @@ -414,8 +439,6 @@ namespace build2 throw failed (); } - // Assert if called. - // const string& target_extension_assert (const target_key&, scope&) { @@ -423,6 +446,20 @@ namespace build2 throw failed (); } + void + target_print_0_ext_verb (ostream& os, const target_key& k) + { + uint16_t v (stream_verb (os)); + to_stream (os, k, v < 2 ? 0 : v); // Remap 1 to 0. + } + + void + target_print_1_ext_verb (ostream& os, const target_key& k) + { + uint16_t v (stream_verb (os)); + to_stream (os, k, v < 1 ? 1 : v); // Remap 0 to 1. + } + // type info // @@ -432,6 +469,7 @@ namespace build2 nullptr, nullptr, nullptr, + nullptr, &search_target, false }; @@ -442,6 +480,7 @@ namespace build2 &target::static_type, nullptr, nullptr, + nullptr, &search_target, false }; @@ -452,6 +491,7 @@ namespace build2 &mtime_target::static_type, nullptr, nullptr, + nullptr, &search_target, false }; @@ -478,6 +518,7 @@ namespace build2 &path_target::static_type, &file_factory, &target_extension_var, + &target_print_1_ext_verb, // Print extension even at verbosity level 0. &search_file, false }; @@ -487,7 +528,8 @@ namespace build2 "alias", &target::static_type, &target_factory, - nullptr, // Should never need. + nullptr, // Extension not used. + nullptr, &search_alias, false }; @@ -497,7 +539,8 @@ namespace build2 "dir", &alias::static_type, &target_factory, - nullptr, // Should never need. + nullptr, // Extension not used. + nullptr, &search_alias, false }; @@ -507,7 +550,8 @@ namespace build2 "fsdir", &target::static_type, &target_factory, - nullptr, // Should never need. + nullptr, // Extension not used. + nullptr, &search_target, false }; @@ -527,6 +571,7 @@ namespace build2 &file::static_type, &file_factory, &buildfile_target_extension, + nullptr, &search_file, false }; @@ -537,6 +582,7 @@ namespace build2 &file::static_type, &file_factory, &target_extension_var, // Same as file. + &target_print_1_ext_verb, // Same as file. &search_file, false }; @@ -556,6 +602,7 @@ namespace build2 &doc::static_type, &man_factory, &target_extension_assert, // Should be specified explicitly (see factory). + &target_print_1_ext_verb, // Print extension even at verbosity level 0. &search_file, false }; @@ -567,6 +614,7 @@ namespace build2 &man::static_type, &file_factory, &target_extension_fix, + &target_print_0_ext_verb, // Fixed extension, no use printing. &search_file, false }; -- cgit v1.1