From 60698e1786782a834dcc293968c15ecd8821f548 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 25 May 2023 21:29:41 +0300 Subject: Add package-description, package-description-type, and changes-type package manifest values --- libbpkg/manifest.hxx | 119 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 45 deletions(-) (limited to 'libbpkg/manifest.hxx') diff --git a/libbpkg/manifest.hxx b/libbpkg/manifest.hxx index c922cc4..dce0870 100644 --- a/libbpkg/manifest.hxx +++ b/libbpkg/manifest.hxx @@ -206,11 +206,6 @@ namespace bpkg language (std::string n, bool i): name (std::move (n)), impl (i) {} }; - // description - // description-file - // change - // change-file - // class LIBBPKG_EXPORT text_file { public: @@ -244,6 +239,72 @@ namespace bpkg ~text_file (); }; + enum class text_type + { + plain, + common_mark, + github_mark + }; + + LIBBPKG_EXPORT std::string + to_string (text_type); + + // Throw std::invalid_argument if the argument is not a well-formed text + // type. Otherwise, return nullopt for an unknown text variant. + // + LIBBPKG_EXPORT butl::optional + to_text_type (const std::string&); + + inline std::ostream& + operator<< (std::ostream& os, text_type t) + { + return os << to_string (t); + } + + // description + // description-file + // description-type + // package-description + // package-description-file + // package-description-type + // change + // change-file + // change-type + // + class LIBBPKG_EXPORT typed_text_file: public text_file + { + public: + butl::optional type; + + // File text constructor. + // + explicit + typed_text_file (std::string s = "", + butl::optional t = butl::nullopt) + : text_file (std::move (s)), type (std::move (t)) {} + + // File reference constructor. + // + typed_text_file (path_type p, + std::string c, + butl::optional t = butl::nullopt) + : text_file (std::move (p), std::move (c)), type (std::move (t)) {} + + // Return the type value if present, text_type::github_mark if it refers + // to a file with the .md or .markdown extension and text_type::plain if + // it refers to a file with the .txt extension or no extension or the text + // does not come from a file. Depending on the ignore_unknown value either + // throw std::invalid_argument or return nullopt if the type value or the + // file extension is unknown. + // + // Note: also throws std::invalid_argument if the type is not well-formed. + // This, however, may not happen for an object created by the package + // manifest parser since it has already verified that. + // + butl::optional + effective_type (bool ignore_unknown = false) const; + }; + // license // class licenses: public butl::small_vector @@ -774,7 +835,7 @@ namespace bpkg require_location = 0x020, require_sha256sum = 0x040, - require_description_type = 0x080, + require_text_type = 0x080, // description-type, changes-type, etc. require_bootstrap_build = 0x100 }; @@ -965,28 +1026,6 @@ namespace bpkg } }; - enum class text_type - { - plain, - common_mark, - github_mark - }; - - LIBBPKG_EXPORT std::string - to_string (text_type); - - // Throw std::invalid_argument if the argument is not a well-formed text - // type. Otherwise, return nullopt for an unknown text variant. - // - LIBBPKG_EXPORT butl::optional - to_text_type (const std::string&); // May throw std::invalid_argument. - - inline std::ostream& - operator<< (std::ostream& os, text_type t) - { - return os << to_string (t); - } - enum class test_dependency_type { tests, @@ -1115,9 +1154,9 @@ namespace bpkg butl::small_vector topics; butl::small_vector keywords; - butl::optional description; - butl::optional description_type; - butl::small_vector changes; + butl::optional description; + butl::optional package_description; + butl::small_vector changes; butl::optional url; butl::optional doc_url; butl::optional src_url; @@ -1208,17 +1247,6 @@ namespace bpkg const package_name& effective_project () const noexcept {return project ? *project : name;} - // Return the description type value if present, text_type::github_mark if - // the description refers to a file with the .md or .markdown extension - // and text_type::plain if it refers to a file with the .txt extension or - // no extension or the description does not come from a file. Depending on - // the ignore_unknown value either throw std::invalid_argument or return - // nullopt if the description value or the file extension is unknown. - // Throw std::logic_error if the description value is nullopt. - // - butl::optional - effective_description_type (bool ignore_unknown = false) const; - public: package_manifest () = default; @@ -1368,9 +1396,10 @@ namespace bpkg // Load the *-file manifest values using the specified load function that // returns the file contents passing through any exception it may throw. // If nullopt is returned, then the respective *-file value is left - // unexpanded. Set the potentially absent description type value to the - // effective description type. If the effective type is nullopt then - // assign a synthetic unknown type. + // unexpanded. Set the potentially absent project description, package + // description, and changes type values to their effective types. If an + // effective type is nullopt then assign a synthetic unknown type if the + // ignore_unknown argument is true and throw manifest_parsing otherwise. // // Note that if the returned file contents is empty, load_files() makes // sure that this is allowed by the value's semantics throwing -- cgit v1.1