From becea217436a79b7ef37a023da6cb4c560225a71 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 2 Dec 2015 14:24:10 +0200 Subject: Redo extension derivation for file{}, doc{}, and cli{} We now first check the 'extension' variable, then use the default. --- build/cli/target.cxx | 6 ++++-- build/cxx/target.cxx | 12 ++++++------ build/parser.cxx | 7 +++++++ build/target | 5 +++-- build/target.cxx | 9 +++++---- build/target.txx | 22 ++++++++++++++-------- 6 files changed, 39 insertions(+), 22 deletions(-) diff --git a/build/cli/target.cxx b/build/cli/target.cxx index a480633..6eef99b 100644 --- a/build/cli/target.cxx +++ b/build/cli/target.cxx @@ -15,13 +15,15 @@ namespace build { // cli // - constexpr const char cli_ext[] = "cli"; + constexpr const char cli_ext_var[] = "extension"; + constexpr const char cli_ext_def[] = "cli"; + const target_type cli::static_type { "cli", &file::static_type, &target_factory, - &target_extension_fix, + &target_extension_var, &search_file, false }; diff --git a/build/cxx/target.cxx b/build/cxx/target.cxx index c8680b7..b84167b 100644 --- a/build/cxx/target.cxx +++ b/build/cxx/target.cxx @@ -16,7 +16,7 @@ namespace build "hxx", &file::static_type, &target_factory, - &target_extension_var, + &target_extension_var, &search_file, false }; @@ -27,7 +27,7 @@ namespace build "ixx", &file::static_type, &target_factory, - &target_extension_var, + &target_extension_var, &search_file, false }; @@ -38,7 +38,7 @@ namespace build "txx", &file::static_type, &target_factory, - &target_extension_var, + &target_extension_var, &search_file, false }; @@ -49,7 +49,7 @@ namespace build "cxx", &file::static_type, &target_factory, - &target_extension_var, + &target_extension_var, &search_file, false }; @@ -60,7 +60,7 @@ namespace build "h", &file::static_type, &target_factory, - &target_extension_var, + &target_extension_var, &search_file, false }; @@ -71,7 +71,7 @@ namespace build "c", &file::static_type, &target_factory, - &target_extension_var, + &target_extension_var, &search_file, false }; diff --git a/build/parser.cxx b/build/parser.cxx index c896c71..ee22254 100644 --- a/build/parser.cxx +++ b/build/parser.cxx @@ -818,6 +818,8 @@ namespace build return r; } + constexpr const char derived_ext_var[] = "extension"; + void parser:: define (token& t, token_type& tt) { @@ -852,6 +854,11 @@ namespace build dt->base = bt; dt->factory = &derived_factory; + // Override extension derivation function: we most likely don't want + // to use the same default as our base (think cli: file). + // + dt->extension = &target_extension_var; + target_type& rdt (*dt); // Save a non-const reference to the object. auto pr (scope_->target_types.emplace (dn, target_type_ref (move (dt)))); diff --git a/build/target b/build/target index 2aea7ae..69f8f4f 100644 --- a/build/target +++ b/build/target @@ -1051,9 +1051,10 @@ namespace build const std::string& target_extension_fix (const target_key&, scope&); - // Get the extension from the variable. + // Get the extension from the variable or use the default if none set. + // Issue diagnostics and fail if the default is NULL. // - template + template const std::string& target_extension_var (const target_key&, scope&); diff --git a/build/target.cxx b/build/target.cxx index 5c31311..41fe54a 100644 --- a/build/target.cxx +++ b/build/target.cxx @@ -433,13 +433,15 @@ namespace build (e != nullptr ? e : &extension_pool.find (""))); } - constexpr const char extension_var[] = "extension"; + constexpr const char file_ext_var[] = "extension"; + constexpr const char file_ext_def[] = ""; + const target_type file::static_type { "file", &path_target::static_type, &file_factory, - &target_extension_var, + &target_extension_var, &search_file, false }; @@ -493,13 +495,12 @@ namespace build false }; - constexpr const char doc_ext[] = ""; const target_type doc::static_type { "doc", &file::static_type, &file_factory, - &target_extension_fix, + &target_extension_var, // Same as file. &search_file, false }; diff --git a/build/target.txx b/build/target.txx index e347f77..89a402e 100644 --- a/build/target.txx +++ b/build/target.txx @@ -10,24 +10,27 @@ namespace build { template - const std::string& + const string& target_extension_fix (const target_key&, scope&) { return extension_pool.find (ext); } - template - const std::string& + template + const string& target_extension_var (const target_key& tk, scope& s) { // Include target type/pattern-specific variables. // - auto l (s.lookup (tk, var)); + if (auto l = s.lookup (tk, var)) + return extension_pool.find (as (*l)); + + if (def != nullptr) + return extension_pool.find (def); - if (!l) { diag_record dr; - dr << fail << "no default extension in variable '" << var << "'" + dr << error << "no default extension in variable '" << var << "'" << info << "required to derive file name for "; // This is a bit hacky: we may be dealing with a target (see @@ -39,11 +42,14 @@ namespace build dr << "target " << tk; else { - const std::string* proj (nullptr); // Used for local prerequisites. + const string* proj (nullptr); // Used for local prerequisites. dr << "prerequisite " << prerequisite_key {&proj, tk, &s}; } + + dr << info << "perhaps you forgot to add " + << tk.type->name << "{*}: " << var << " = ..."; } - return extension_pool.find (as (*l)); + throw failed (); } } -- cgit v1.1