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/bin/target.cxx | 7 ++++++ build2/cli/target.cxx | 2 ++ build2/cxx/target.cxx | 6 +++++ build2/dump.cxx | 11 +++++++++ build2/parser.cxx | 5 ++-- build2/search.cxx | 6 ++--- build2/target | 15 ++++++++++++ build2/target-key | 13 +++++++++-- build2/target-type | 2 ++ build2/target.cxx | 64 ++++++++++++++++++++++++++++++++++++++++++++------- 10 files changed, 115 insertions(+), 16 deletions(-) diff --git a/build2/bin/target.cxx b/build2/bin/target.cxx index 136de9c..de51fc7 100644 --- a/build2/bin/target.cxx +++ b/build2/bin/target.cxx @@ -28,6 +28,7 @@ namespace build2 &file::static_type, &obja_factory, &target_extension_assert, + nullptr, &search_target, // Note: not _file(); don't look for an existing file. false }; @@ -50,6 +51,7 @@ namespace build2 &file::static_type, &objso_factory, &target_extension_assert, + nullptr, &search_target, // Note: not _file(); don't look for an existing file. false }; @@ -76,6 +78,7 @@ namespace build2 &target::static_type, &obj_factory, nullptr, + nullptr, &search_target, false }; @@ -98,6 +101,7 @@ namespace build2 &file::static_type, &target_factory, &target_extension_fix, + nullptr, &search_file, false }; @@ -135,6 +139,7 @@ namespace build2 &file::static_type, &liba_factory, &target_extension_fix, + nullptr, &search_file, false }; @@ -160,6 +165,7 @@ namespace build2 &file::static_type, &libso_factory, &target_extension_fix, + nullptr, &search_file, false }; @@ -195,6 +201,7 @@ namespace build2 &target::static_type, &lib_factory, nullptr, + nullptr, &search_target, false }; diff --git a/build2/cli/target.cxx b/build2/cli/target.cxx index f5b4ee6..44d1a9a 100644 --- a/build2/cli/target.cxx +++ b/build2/cli/target.cxx @@ -24,6 +24,7 @@ namespace build2 &file::static_type, &target_factory, &target_extension_var, + nullptr, &search_file, false }; @@ -70,6 +71,7 @@ namespace build2 &mtime_target::static_type, &cli_cxx_factory, nullptr, + nullptr, &search_target, true // "See through" default iteration mode. }; diff --git a/build2/cxx/target.cxx b/build2/cxx/target.cxx index 5a909a5..c5b5080 100644 --- a/build2/cxx/target.cxx +++ b/build2/cxx/target.cxx @@ -19,6 +19,7 @@ namespace build2 &file::static_type, &target_factory, &target_extension_var, + nullptr, &search_file, false }; @@ -30,6 +31,7 @@ namespace build2 &file::static_type, &target_factory, &target_extension_var, + nullptr, &search_file, false }; @@ -41,6 +43,7 @@ namespace build2 &file::static_type, &target_factory, &target_extension_var, + nullptr, &search_file, false }; @@ -52,6 +55,7 @@ namespace build2 &file::static_type, &target_factory, &target_extension_var, + nullptr, &search_file, false }; @@ -63,6 +67,7 @@ namespace build2 &file::static_type, &target_factory, &target_extension_var, + nullptr, &search_file, false }; @@ -74,6 +79,7 @@ namespace build2 &file::static_type, &target_factory, &target_extension_var, + nullptr, &search_file, false }; diff --git a/build2/dump.cxx b/build2/dump.cxx index 92985f6..b3d78bb 100644 --- a/build2/dump.cxx +++ b/build2/dump.cxx @@ -88,6 +88,15 @@ namespace build2 static void dump_target (ostream& os, string& ind, action a, const target& t) { + // Print the target and its prerequisites relative to the scope. To achieve + // this we are going to temporarily lower the stream verbosity to level 1. + // The drawback of doing this is that we also lower the verbosity of + // extension printing (it wouldn't have been bad at all to get 'foo.?' for + // unassigned and 'foo.' for empty). + // + uint16_t sv (stream_verb (os)); + stream_verb (os, 1); + os << ind << t; if (t.group != nullptr) @@ -123,6 +132,8 @@ namespace build2 } } + stream_verb (os, sv); // We want variable values in full. + // Print target-specific variables. // if (!t.vars.empty ()) diff --git a/build2/parser.cxx b/build2/parser.cxx index b28f4f6..ad556ce 100644 --- a/build2/parser.cxx +++ b/build2/parser.cxx @@ -941,9 +941,8 @@ namespace build2 // base doesn't use extensions, then most likely neither do we (think // foo: alias). // - dt->extension = /*bt->extension == nullptr - ? nullptr - :*/ &target_extension_var; + if (bt->extension != nullptr) + dt->extension = &target_extension_var; target_type& rdt (*dt); // Save a non-const reference to the object. diff --git a/build2/search.cxx b/build2/search.cxx index 7c27ca5..2ab3d1f 100644 --- a/build2/search.cxx +++ b/build2/search.cxx @@ -114,7 +114,7 @@ namespace build2 continue; level5 ([&]{trace << "found existing file " << f << " for prerequisite " - << pk;}); + << cpk;}); // Find or insert. Note: using our updated extension. // @@ -125,7 +125,7 @@ namespace build2 file& t (dynamic_cast (r.first)); level5 ([&]{trace << (r.second ? "new" : "existing") << " target " - << t << " for prerequisite " << pk;}); + << t << " for prerequisite " << cpk;}); if (t.path ().empty ()) t.path (move (f)); @@ -134,7 +134,7 @@ namespace build2 return &t; } - level4 ([&]{trace << "no existing file found for prerequisite " << pk;}); + level4 ([&]{trace << "no existing file found for prerequisite " << cpk;}); return nullptr; } diff --git a/build2/target b/build2/target index c6cc46e..e6ebc42 100644 --- a/build2/target +++ b/build2/target @@ -1078,6 +1078,21 @@ namespace build2 const std::string& target_extension_assert (const target_key&, scope&); + // Target print functions. + // + + // Target type uses the extension but it is fixed and there is no use + // printing it (e.g., man1{}). + // + void + target_print_0_ext_verb (ostream&, const target_key&); + + // Target type uses the extension and there is normally no default so it + // should be printed (e.g., file{}). + // + void + target_print_1_ext_verb (ostream&, const target_key&); + // The default behavior, that is, look for an existing target in the // prerequisite's directory scope. // diff --git a/build2/target-key b/build2/target-key index 4246cf2..1c8037c 100644 --- a/build2/target-key +++ b/build2/target-key @@ -13,6 +13,8 @@ #include // compare_c_string #include +#include + #include namespace build2 @@ -48,8 +50,15 @@ namespace build2 } }; - std::ostream& - operator<< (std::ostream&, const target_key&); // Defined in target.cxx + // If the target type has a custom print function, call that. Otherwise, + // call to_stream() with the current stream verbosity as a third argument. + // Both are defined in target.cxx. + // + ostream& + operator<< (ostream&, const target_key&); + + ostream& + to_stream (ostream&, const target_key&, uint16_t ext_verb); } #endif // BUILD2_TARGET_KEY diff --git a/build2/target-type b/build2/target-type index 60a0e35..a831670 100644 --- a/build2/target-type +++ b/build2/target-type @@ -10,6 +10,7 @@ #include #include +#include namespace build2 { @@ -36,6 +37,7 @@ namespace build2 const target_type* base; target* (*factory) (const target_type&, dir_path, string, const string*); const string& (*extension) (const target_key&, scope&); + void (*print) (ostream&, const target_key&); target* (*search) (const prerequisite_key&); bool see_through; // A group with the default "see through" semantics. 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