From f34dd20fb7578874925dacf21b32338af50e8c12 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 9 Nov 2022 10:59:36 +0200 Subject: Improve low-level diagnostics in `in` rule (and derived) --- libbuild2/in/rule.cxx | 30 +++++++++++++++++++++++++++++- libbuild2/in/target.cxx | 10 +++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) (limited to 'libbuild2/in') diff --git a/libbuild2/in/rule.cxx b/libbuild2/in/rule.cxx index d07adfc..07c11c6 100644 --- a/libbuild2/in/rule.cxx +++ b/libbuild2/in/rule.cxx @@ -299,7 +299,35 @@ namespace build2 if (verb >= 2) text << program_ << ' ' << ip << " >" << tp; else if (verb) - text << program_ << ' ' << ip; + { + // If we straight print the target, in most cases we will end up with + // something ugly like in{version...h.in} (due to the in{} target + // type search semantics). There is the `...h` part but also the + // `.in` part that is redundant given in{}. So let's tidy this up + // a bit if the extension could have been derived by in_search(). + // + target_key ik (i.key ()); + + if (ik.ext) + { + string& ie (*ik.ext); + const string* te (t.ext ()); + + size_t in (ie.size ()); + size_t tn (te != nullptr ? te->size () : 0); + + if (in == tn + (tn != 0 ? 1 : 0) + 2) // [.]in + { + if (ie.compare (in - 2, 2, "in") == 0) + { + if (tn == 0 || (ie.compare (0, tn, *te) == 0 && ie[tn] == '.')) + ie.clear (); + } + } + } + + text << program_ << ' ' << ik; + } // Read and process the file, one line at a time, while updating depdb. // diff --git a/libbuild2/in/target.cxx b/libbuild2/in/target.cxx index d548453..54130ff 100644 --- a/libbuild2/in/target.cxx +++ b/libbuild2/in/target.cxx @@ -20,6 +20,14 @@ namespace build2 if (!e) { + // Why is the extension, say, .h.in and not .in (with .h being in the + // name)? While this is mostly academic (in this case things will work + // the same either way), conceptually, it is a header template rather + // than some file template. In other words, we are adding the second + // level classification. + // + // See also the low verbosity tidying up code in the rule. + // if (const file* t = xt.is_a ()) { const string& te (t->derive_extension ()); @@ -51,7 +59,7 @@ namespace build2 &target_extension_none, nullptr, /* default_extension */ // Taken care of by search. &in_pattern, - &target_print_1_ext_verb, // Same as file. + &target_print_1_ext_verb, // Same as file (but see rule). &in_search, target_type::flag::none }; -- cgit v1.1