From a738555f02626685f119fe332d4e2e6e9f2581f4 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 29 Nov 2023 09:51:43 +0200 Subject: Add rule for extracting C and C++ predefs --- libbuild2/cxx/init.cxx | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) (limited to 'libbuild2/cxx/init.cxx') diff --git a/libbuild2/cxx/init.cxx b/libbuild2/cxx/init.cxx index 8948e6a..626c795 100644 --- a/libbuild2/cxx/init.cxx +++ b/libbuild2/cxx/init.cxx @@ -957,16 +957,53 @@ namespace build2 return true; } + bool + predefs_init (scope& rs, + scope& bs, + const location& loc, + bool, + bool, + module_init_extra&) + { + tracer trace ("cxx::predefs_init"); + l5 ([&]{trace << "for " << bs;}); + + // We only support root loading (which means there can only be one). + // + if (rs != bs) + fail (loc) << "cxx.predefs module must be loaded in project root"; + + module* mod (rs.find_module ("cxx")); + + if (mod == nullptr) + fail (loc) << "cxx.predefs module must be loaded after cxx module"; + + // Register the cxx.predefs rule. + // + // Why invent a separate module instead of just always registering it in + // the cxx module? The reason is performance: this rule will be called + // for every C++ header. + // + cc::predefs_rule& r (*mod); + + rs.insert_rule (perform_update_id, r.rule_name, r); + rs.insert_rule (perform_clean_id, r.rule_name, r); + rs.insert_rule (configure_update_id, r.rule_name, r); + + return true; + } + static const module_functions mod_functions[] = { // NOTE: don't forget to also update the documentation in init.hxx if // changing anything here. - {"cxx.guess", nullptr, guess_init}, - {"cxx.config", nullptr, config_init}, - {"cxx.objcxx", nullptr, objcxx_init}, - {"cxx", nullptr, init}, - {nullptr, nullptr, nullptr} + {"cxx.guess", nullptr, guess_init}, + {"cxx.config", nullptr, config_init}, + {"cxx.objcxx", nullptr, objcxx_init}, + {"cxx.predefs", nullptr, predefs_init}, + {"cxx", nullptr, init}, + {nullptr, nullptr, nullptr} }; const module_functions* -- cgit v1.1