From 651c01a92dbbec65674fe3c73a6c82a936e73d91 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 26 May 2023 13:18:46 +0300 Subject: Add support for package-description, package-description-type, and changes-type package manifest values --- load/load.cxx | 91 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 27 deletions(-) (limited to 'load') diff --git a/load/load.cxx b/load/load.cxx index a201785..0468565 100644 --- a/load/load.cxx +++ b/load/load.cxx @@ -450,50 +450,87 @@ load_packages (const shared_ptr& rp, // Create internal package object. // - optional dsc; - optional dst; - - if (pm.description) + // Return nullopt if the text is in a file (can happen if the + // repository is of a type other than pkg) or if the type is not + // recognized (can only happen in the "ignore unknown" mode). + // + auto to_typed_text = [&cl, &p, ignore_unknown] (typed_text_file&& v) { + optional r; + // The description value should not be of the file type if the // package manifest comes from the pkg repository. // - assert (!pm.description->file || cl.type () != repository_type::pkg); + assert (!v.file || cl.type () != repository_type::pkg); - if (!pm.description->file) + if (!v.file) { - dst = pm.effective_description_type (ignore_unknown); + // Cannot throw since the manifest parser has already verified the + // effective type in the same "ignore unknown" mode. + // + optional t (v.effective_type (ignore_unknown)); // If the description type is unknown (which may be the case for // some "transitional" period and only if --ignore-unknown is // specified) we just silently drop the description. // - assert (dst || ignore_unknown); + assert (t || ignore_unknown); - if (dst) - dsc = move (pm.description->text); + if (t) + r = typed_text {move (v.text), *t}; } - } - string chn; + return r; + }; + + // Convert descriptions. + // + optional ds ( + pm.description + ? to_typed_text (move (*pm.description)) + : optional ()); + + optional pds ( + pm.package_description + ? to_typed_text (move (*pm.package_description)) + : optional ()); + + // Merge changes into a single typed text object. + // + // If the text type is not recognized for any changes entry or some + // entry refers to a file, then assume that no changes are specified. + // + optional chn; + for (auto& c: pm.changes) { - // The changes value should not be of the file type if the package - // manifest comes from the pkg repository. - // - assert (!c.file || cl.type () != repository_type::pkg); + optional tc (to_typed_text (move (c))); - if (!c.file) + if (!tc) { - if (chn.empty ()) - chn = move (c.text); - else - { - if (chn.back () != '\n') - chn += '\n'; // Always have a blank line as a separator. + chn = nullopt; + break; + } - chn += "\n" + c.text; - } + if (!chn) + { + chn = move (*tc); + } + else + { + // Should have failed while parsing the manifest otherwise. + // + assert (tc->type == chn->type); + + string& v (chn->text); + + assert (!v.empty ()); // Changes manifest value cannot be empty. + + if (v.back () != '\n') + v += '\n'; // Always have a blank line as a separator. + + v += '\n'; + v += tc->text; } } @@ -566,8 +603,8 @@ load_packages (const shared_ptr& rp, move (pm.license_alternatives), move (pm.topics), move (pm.keywords), - move (dsc), - move (dst), + move (ds), + move (pds), move (chn), move (pm.url), move (pm.doc_url), -- cgit v1.1