From e1f472e471533330db05a42d5bcd4e99b211da0c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 21 May 2021 15:11:04 +0200 Subject: Clean default target type extension logic --- libbuild2/target.cxx | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'libbuild2/target.cxx') diff --git a/libbuild2/target.cxx b/libbuild2/target.cxx index a5061e3..6ba12b9 100644 --- a/libbuild2/target.cxx +++ b/libbuild2/target.cxx @@ -979,6 +979,23 @@ namespace build2 return search_existing_file (t.ctx, pk); } + extern const char target_extension_none_[] = ""; + + const char* + target_extension_none (const target_key& k, const scope* s) + { + return target_extension_fix (k, s); + } + + const char* + target_extension_must (const target_key& tk, const scope*) + { + if (!tk.ext) + fail << tk.type->name << " target " << tk << " must include extension"; + + return tk.ext->c_str (); + } + void target_print_0_ext_verb (ostream& os, const target_key& k) { @@ -1037,14 +1054,12 @@ namespace build2 false }; - extern const char file_ext_def[] = ""; - const target_type file::static_type { "file", &path_target::static_type, &target_factory, - &target_extension_fix, + &target_extension_none, nullptr, /* default_extension */ nullptr, /* pattern */ &target_print_1_ext_verb, // Print extension even at verbosity level 0. @@ -1467,7 +1482,7 @@ namespace build2 "doc", &file::static_type, &target_factory, - &target_extension_fix, // Same as file (no extension). + &target_extension_none, // Same as file (no extension). nullptr, /* default_extension */ nullptr, /* pattern */ // Same as file. &target_print_1_ext_verb, // Same as file. @@ -1480,7 +1495,7 @@ namespace build2 "legal", &doc::static_type, &target_factory, - &target_extension_fix, // Same as file (no extension). + &target_extension_none, // Same as file (no extension). nullptr, /* default_extension */ nullptr, /* pattern */ // Same as file. &target_print_1_ext_verb, // Same as file. @@ -1488,21 +1503,12 @@ namespace build2 false }; - static const char* - man_extension (const target_key& tk, const scope*) - { - if (!tk.ext) - fail << "man target " << tk << " must include extension (man section)"; - - return tk.ext->c_str (); - } - const target_type man::static_type { "man", &doc::static_type, &target_factory, - &man_extension, // Should be specified explicitly. + &target_extension_must, // Should be specified explicitly. nullptr, /* default_extension */ nullptr, &target_print_1_ext_verb, // Print extension even at verbosity level 0. -- cgit v1.1