From 3e39190bc50284a620605c7b61faff197e116457 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 23 Jan 2016 12:13:06 +0200 Subject: Clean up default target extension derivation logic --- build2/target.cxx | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'build2/target.cxx') diff --git a/build2/target.cxx b/build2/target.cxx index 43c6a41..89e16b5 100644 --- a/build2/target.cxx +++ b/build2/target.cxx @@ -308,7 +308,7 @@ namespace build2 if (de != nullptr) ext = &extension_pool.find (de); // - // Otherwis see if the target type has function that will + // Otherwise see if the target type has function that will // give us the default extension. // else if (auto f = type ().extension) @@ -393,6 +393,36 @@ namespace build2 return t; } + const string& + target_extension_fail (const target_key& tk, scope& s) + { + { + diag_record dr; + dr << error << "no default extension to derive file name for "; + + // This is a bit hacky: we may be dealing with a target (see + // file::derive_path()) or prerequisite (see search_existing_file()). So + // we are going to check if dir is absolute. If it is, then we assume + // this is a target, otherwise -- prerequisite. + // + if (tk.dir->absolute ()) + dr << "target " << tk; + else + dr << "prerequisite " << prerequisite_key {nullptr, tk, &s}; + } + + throw failed (); + } + + // Assert if called. + // + const string& + target_extension_assert (const target_key&, scope&) + { + assert (false); // Attempt to obtain the default extension. + throw failed (); + } + // type info // @@ -525,7 +555,7 @@ namespace build2 "man", &doc::static_type, &man_factory, - nullptr, // Should be specified explicitly. + &target_extension_assert, // Should be specified explicitly (see factory). &search_file, false }; -- cgit v1.1