diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2024-03-12 12:48:15 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2024-03-13 12:16:35 +0300 |
commit | 962c725f9fba6b7b4803f31dbcd497169b237f57 (patch) | |
tree | df9cf7e257323d81fd638b6d43f5ab060600ad3c /mod | |
parent | 351f89ffe10a2f3aadfbc3a80704b5954dc356ca (diff) |
Change semantics for build-toolchain-email configuration option
Diffstat (limited to 'mod')
-rw-r--r-- | mod/mod-build-result.cxx | 37 | ||||
-rw-r--r-- | mod/module.cli | 17 | ||||
-rw-r--r-- | mod/options-types.hxx | 7 | ||||
-rw-r--r-- | mod/types-parsers.cxx | 22 | ||||
-rw-r--r-- | mod/types-parsers.hxx | 7 |
5 files changed, 79 insertions, 11 deletions
diff --git a/mod/mod-build-result.cxx b/mod/mod-build-result.cxx index 7023e39..22613eb 100644 --- a/mod/mod-build-result.cxx +++ b/mod/mod-build-result.cxx @@ -191,6 +191,13 @@ handle (request& rq, response&) shared_ptr<build_package> pkg; const build_package_config* cfg (nullptr); + // True if the built package version is the latest buildable version of this + // package in the tenant. + // + // Note: is only meaningful if bld is not NULL. + // + bool latest_version (false); + bool build_notify (false); bool unforced (true); @@ -470,7 +477,27 @@ handle (request& rq, response&) build_db_->load (*pkg, pkg->constraints_section); if (!exclude (*cfg, pkg->builds, pkg->constraints, *tc)) + { bld = b; + + // While at it, check if the built package version is the latest + // buildable version of this package. + // + // Ideally we would like to avoid this query unless necessary + // (mode is latest and package manifest has build-*-email + // values), but that will make things quite hairy so let's + // keep it simple for now. + // + const auto& id (query<buildable_package>::build_package::id); + + buildable_package p ( + build_db_->query_value<buildable_package> ( + (id.tenant == b->tenant && id.name == b->package_name) + + order_by_version_desc (id.version) + + "LIMIT 1")); + + latest_version = (p.package->version == b->package_version); + } } } else @@ -529,13 +556,15 @@ handle (request& rq, response&) return true; // Bail out if sending build notification emails is disabled for this - // toolchain. + // toolchain for this package. // { - const map<string, bool>& tes (options_->build_toolchain_email ()); - + const map<string, build_email>& tes (options_->build_toolchain_email ()); auto i (tes.find (bld->id.toolchain_name)); - if (i != tes.end () && !i->second) + build_email mode (i != tes.end () ? i->second : build_email::latest); + + if (mode == build_email::none || + (mode == build_email::latest && !latest_version)) return true; } diff --git a/mod/module.cli b/mod/module.cli index 3e81b38..552a60b 100644 --- a/mod/module.cli +++ b/mod/module.cli @@ -586,15 +586,18 @@ namespace brep default is 10M." } - std::map<string, bool> build-toolchain-email + std::map<string, build_email> build-toolchain-email { - "<name>=<bool>", - "Enable or disable package build notification emails. If \cb{true} is + "<name>=<mode>", + "Enable or disable package build notification emails. The valid <mode> + values are \cb{none}, \cb{latest}, and \cb{all}. If \cb{all} is specified for a toolchain name, then emails are sent according to the - \cb{build-*email} package manifest values when the package is built - with this toolchain. If \cb{false} is specified, then no emails are - sent for this toolchain name. By default build notification emails - are enabled. Repeat this option to enable/disable emails for multiple + \cb{build-*email} package manifest values when all versions of a + package are built with this toolchain. If \cb{latest} is specified, + then for this toolchain name the emails are only sent for the latest + version of a package. If \cb{none} is specified, then no emails are + sent for this toolchain name. By default the \cb{latest} mode is + assumed. Repeat this option to enable/disable emails for multiple toolchains. See \l{bpkg#manifest-package Package Manifest} for details on \cb{build-*email} values." } diff --git a/mod/options-types.hxx b/mod/options-types.hxx index dc1047d..f2b059b 100644 --- a/mod/options-types.hxx +++ b/mod/options-types.hxx @@ -31,6 +31,13 @@ namespace brep stable, random }; + + enum class build_email + { + none, + latest, // Only send emails for the latest package versions. + all + }; } #endif // MOD_OPTIONS_TYPES_HXX diff --git a/mod/types-parsers.cxx b/mod/types-parsers.cxx index 34a8bac..60d70d7 100644 --- a/mod/types-parsers.cxx +++ b/mod/types-parsers.cxx @@ -261,5 +261,27 @@ namespace brep else throw invalid_value (o, v); } + + // Parse build_email. + // + void parser<build_email>:: + parse (build_email& x, bool& xs, scanner& s) + { + xs = true; + const char* o (s.next ()); + + if (!s.more ()) + throw missing_value (o); + + const string v (s.next ()); + if (v == "none") + x = build_email::none; + else if (v == "latest") + x = build_email::latest; + else if (v == "all") + x = build_email::all; + else + throw invalid_value (o, v); + } } } diff --git a/mod/types-parsers.hxx b/mod/types-parsers.hxx index f10100c..d48ae0b 100644 --- a/mod/types-parsers.hxx +++ b/mod/types-parsers.hxx @@ -99,6 +99,13 @@ namespace brep static void parse (build_order&, bool&, scanner&); }; + + template <> + struct parser<build_email> + { + static void + parse (build_email&, bool&, scanner&); + }; } } |