diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-01-27 13:59:51 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-01-27 13:59:51 +0200 |
commit | a5949f9e974171144dba84771a9f305f9e1dcc3f (patch) | |
tree | 1e70c60d0c9daf4065e1163426c65b512d70c0c6 /build2/target.cxx | |
parent | bb171dd3fa145b15a6defd122b15be6822806e2b (diff) |
Rework default extension derivation, again
Diffstat (limited to 'build2/target.cxx')
-rw-r--r-- | build2/target.cxx | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/build2/target.cxx b/build2/target.cxx index 3fd099d..50188ac 100644 --- a/build2/target.cxx +++ b/build2/target.cxx @@ -322,24 +322,28 @@ namespace build2 if (ns != nullptr) n += ns; - // Update the extension. - // - // See also search_existing_file() if updating anything here. + // Update the extension. See also search_existing_file() if updating + // anything here. // + assert (de == nullptr || type ().extension != nullptr); + if (ext == nullptr) { - // If provided by the caller, then use that. - // - if (de != nullptr) - ext = &extension_pool.find (de); + // If the target type has the extension function then try that first. + // The reason for preferring it over what's been provided by the caller + // is that this function will often use the 'extension' variable which + // the user can use to override extensions. // - // Otherwise see if the target type has function that will - // give us the default extension. - // - else if (auto f = type ().extension) - ext = &f (key (), base_scope ()); // Already from the pool. - else - fail << "no default extension for target " << *this; + if (auto f = type ().extension) + ext = f (key (), base_scope ()); // Already from the pool. + + if (ext == nullptr) + { + if (de != nullptr) + ext = &extension_pool.find (de); + else + fail << "no default extension for target " << *this; + } } // Add the extension. @@ -418,7 +422,13 @@ namespace build2 return t; } - const string& + const string* + target_extension_null (const target_key&, scope&) + { + return nullptr; + } + + const string* target_extension_fail (const target_key& tk, scope& s) { { @@ -439,7 +449,7 @@ namespace build2 throw failed (); } - const string& + const string* target_extension_assert (const target_key&, scope&) { assert (false); // Attempt to obtain the default extension. @@ -556,13 +566,13 @@ namespace build2 false }; - static const std::string& + static const std::string* buildfile_target_extension (const target_key& tk, scope&) { // If the name is special 'buildfile', then there is no extension, // otherwise it is .build. // - return extension_pool.find (*tk.name == "buildfile" ? "" : "build"); + return &extension_pool.find (*tk.name == "buildfile" ? "" : "build"); } const target_type buildfile::static_type |