From bf959a7fc119f9156c4b84c9d0a10900d9153f8d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 27 Jul 2017 14:45:05 +0200 Subject: Initial infrastructure for utility libraries --- build2/bin/init.cxx | 27 ++++++++++++------ build2/bin/rule.cxx | 27 +++++------------- build2/bin/rule.hxx | 18 +++--------- build2/bin/target.cxx | 78 +++++++++++++++++++++++++++++++++++++++++++++++++-- build2/bin/target.hxx | 71 ++++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 173 insertions(+), 48 deletions(-) (limited to 'build2/bin') diff --git a/build2/bin/init.cxx b/build2/bin/init.cxx index 71c580b..fb9dd71 100644 --- a/build2/bin/init.cxx +++ b/build2/bin/init.cxx @@ -24,8 +24,7 @@ namespace build2 { namespace bin { - static const obj_rule obj_; - static const bmi_rule bmi_; + static const fail_rule fail_; static const lib_rule lib_; // Default config.bin.*.lib values. @@ -368,10 +367,17 @@ namespace build2 t.insert (); t.insert (); + t.insert (); + t.insert (); + t.insert (); + t.insert (); + t.insert (); t.insert (); t.insert (); + // Note: libu*{} are not installable. + // if (install_loaded) { install_path (bs, dir_path ("lib")); // Install in install.lib. @@ -422,22 +428,25 @@ namespace build2 { auto& r (bs.rules); - r.insert (perform_update_id, "bin.obj", obj_); - r.insert (perform_clean_id, "bin.obj", obj_); + r.insert (perform_update_id, "bin.obj", fail_); + r.insert (perform_clean_id, "bin.obj", fail_); + + r.insert (perform_update_id, "bin.bmi", fail_); + r.insert (perform_clean_id, "bin.bmi", fail_); - r.insert (perform_update_id, "bin.bmi", bmi_); - r.insert (perform_clean_id, "bin.bmi", bmi_); + r.insert (perform_update_id, "bin.libu", fail_); + r.insert (perform_clean_id, "bin.libu", fail_); r.insert (perform_update_id, "bin.lib", lib_); - r.insert (perform_clean_id, "bin.lib", lib_); + r.insert (perform_clean_id, "bin.lib", lib_); - // Configure member. + // Configure members. // r.insert (configure_update_id, "bin.lib", lib_); if (install_loaded) { - r.insert (perform_install_id, "bin.lib", lib_); + r.insert (perform_install_id, "bin.lib", lib_); r.insert (perform_uninstall_id, "bin.lib", lib_); } } diff --git a/build2/bin/rule.cxx b/build2/bin/rule.cxx index b6e5a53..bb9036b 100644 --- a/build2/bin/rule.cxx +++ b/build2/bin/rule.cxx @@ -17,35 +17,22 @@ namespace build2 { namespace bin { - // obj + // fail_rule // - match_result obj_rule:: + match_result fail_rule:: match (action a, target& t, const string&) const { - fail << diag_doing (a, t) << " target group" << - info << "explicitly select obje{}, obja{}, or objs{} member"; - - return false; - } - - recipe obj_rule:: - apply (action, target&) const {return empty_recipe;} + const char* n (t.dynamic_type ().name); // Ignore derived type. - // bmi - // - match_result bmi_rule:: - match (action a, target& t, const string&) const - { fail << diag_doing (a, t) << " target group" << - info << "explicitly select bmie{}, bmia{}, or bmis{} member"; - - return false; + info << "explicitly select " << n << "e{}, " << n << "a{}, or " + << n << "s{} member" << endf; } - recipe bmi_rule:: + recipe fail_rule:: apply (action, target&) const {return empty_recipe;} - // lib + // lib_rule // // The whole logic is pretty much as if we had our two group members as // our prerequisites. diff --git a/build2/bin/rule.hxx b/build2/bin/rule.hxx index 4637479..b4835dc 100644 --- a/build2/bin/rule.hxx +++ b/build2/bin/rule.hxx @@ -14,22 +14,12 @@ namespace build2 { namespace bin { - class obj_rule: public rule + // Fail rule for obj{}, bmi{}, and libu{}. + // + class fail_rule: public rule { public: - obj_rule () {} - - virtual match_result - match (action, target&, const string&) const override; - - virtual recipe - apply (action, target&) const override; - }; - - class bmi_rule: public rule - { - public: - bmi_rule () {} + fail_rule () {} virtual match_result match (action, target&, const string&) const override; diff --git a/build2/bin/target.cxx b/build2/bin/target.cxx index f0e0152..aa37202 100644 --- a/build2/bin/target.cxx +++ b/build2/bin/target.cxx @@ -10,6 +10,30 @@ namespace build2 { namespace bin { + const target_type libx::static_type + { + "libx", + &target::static_type, + nullptr, + nullptr, + nullptr, + nullptr, + &target_search, + false + }; + + const target_type libux::static_type + { + "libux", + &file::static_type, + nullptr, + nullptr, + nullptr, + nullptr, + &target_search, + false + }; + // Note that we link groups during the load phase since this is often // relied upon when setting target-specific variables (e.g., we may set a // common value for lib{} and then append liba/libs-specific values to @@ -19,7 +43,7 @@ namespace build2 extern const char ext_var[] = "extension"; // VC14 rejects constexpr. - // obj*{} and bmi*{} member factory. + // obj*{}, bmi*{}, libu*{} member factory. // template static pair> @@ -61,6 +85,18 @@ namespace build2 false }; + const target_type libue::static_type + { + "libue", + &libux::static_type, + &m_factory, + &target_extension_var, + &target_pattern_var, + nullptr, + &target_search, // Note: not _file(); don't look for an existing file. + false + }; + const target_type obja::static_type { "obja", @@ -85,6 +121,18 @@ namespace build2 false }; + const target_type libua::static_type + { + "libua", + &libux::static_type, + &m_factory, + &target_extension_var, + &target_pattern_var, + nullptr, + &target_search, // Note: not _file(); don't look for an existing file. + false + }; + const target_type objs::static_type { "objs", @@ -109,7 +157,19 @@ namespace build2 false }; - // obj{} and bmi{} group factory. + const target_type libus::static_type + { + "libus", + &libux::static_type, + &m_factory, + &target_extension_var, + &target_pattern_var, + nullptr, + &target_search, // Note: not _file(); don't look for an existing file. + false + }; + + // obj{}, bmi{}, and libu{} group factory. // template static pair> @@ -164,6 +224,18 @@ namespace build2 false }; + const target_type libu::static_type + { + "libu", + &libx::static_type, + &g_factory, + nullptr, + nullptr, + nullptr, + &target_search, + false + }; + // What extensions should we use? At the outset, this is platform- // dependent. And if we consider cross-compilation, is it build or // host-dependent? Feels like it should be host-dependent so that @@ -238,7 +310,7 @@ namespace build2 const target_type lib::static_type { "lib", - &target::static_type, + &libx::static_type, &lib_factory, nullptr, nullptr, diff --git a/build2/bin/target.hxx b/build2/bin/target.hxx index 13d7596..e0c0358 100644 --- a/build2/bin/target.hxx +++ b/build2/bin/target.hxx @@ -117,6 +117,73 @@ namespace build2 virtual const target_type& dynamic_type () const {return static_type;} }; + // Common base for lib{} and libu{} groups. + // + class libx: public target + { + public: + using target::target; + + public: + static const target_type static_type; + }; + + // The libu{} target group (utility library). + // + // All the members are static libraries that differ base on the kind of + // object files they contains. Note that the group is more like obj{} + // rather than lib{} in that one does not build the group directly rather + // picking a suitable member. + // + class libux: public file // Common base of all libuX{} static libraries. + { + public: + using file::file; + + public: + static const target_type static_type; + }; + + class libue: public libux + { + public: + using libux::libux; + + public: + static const target_type static_type; + virtual const target_type& dynamic_type () const {return static_type;} + }; + + class libua: public libux + { + public: + using libux::libux; + + public: + static const target_type static_type; + virtual const target_type& dynamic_type () const {return static_type;} + }; + + class libus: public libux + { + public: + using libux::libux; + + public: + static const target_type static_type; + virtual const target_type& dynamic_type () const {return static_type;} + }; + + class libu: public libx + { + public: + using libx::libx; + + public: + static const target_type static_type; + virtual const target_type& dynamic_type () const {return static_type;} + }; + // The lib{} target group. // class liba: public file @@ -149,10 +216,10 @@ namespace build2 const libs* s = nullptr; }; - class lib: public target, public lib_members + class lib: public libx, public lib_members { public: - using target::target; + using libx::libx; virtual group_view group_members (action_type) const override; -- cgit v1.1