diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2018-08-30 23:17:15 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2018-08-31 18:18:03 +0300 |
commit | 2a362e8f024c032e14cff13cbca2a27a47c79448 (patch) | |
tree | 39b5ec44d69e24c85c047ff69c4649c85066ec58 | |
parent | 0f50af28d1cfb0c22f5b88e2bf674ab732e058d9 (diff) |
Add package manifest flags
-rw-r--r-- | libbpkg/manifest.cxx | 50 | ||||
-rw-r--r-- | libbpkg/manifest.hxx | 70 |
2 files changed, 101 insertions, 19 deletions
diff --git a/libbpkg/manifest.cxx b/libbpkg/manifest.cxx index 31c5ce0..9751e12 100644 --- a/libbpkg/manifest.cxx +++ b/libbpkg/manifest.cxx @@ -893,8 +893,8 @@ namespace bpkg static void parse_package_manifest (parser& p, name_value nv, - bool il, bool iu, + package_manifest_flags fl, package_manifest& m) { auto bad_name ([&p, &nv](const string& d) { @@ -954,6 +954,11 @@ namespace bpkg return email (move (p.first), move (p.second)); }; + auto flag = [fl] (package_manifest_flags f) + { + return (fl & f) != package_manifest_flags::none; + }; + for (nv = p.next (); !nv.empty (); nv = p.next ()) { string& n (nv.name); @@ -1052,7 +1057,7 @@ namespace bpkg } else if (n == "description-file") { - if (il) + if (flag (package_manifest_flags::forbid_file)) bad_name ("package description-file not allowed"); if (m.description) @@ -1084,7 +1089,7 @@ namespace bpkg } else if (n == "changes-file") { - if (il) + if (flag (package_manifest_flags::forbid_file)) bad_name ("package changes-file not allowed"); auto vc (parser::split_comment (v)); @@ -1294,7 +1299,7 @@ namespace bpkg } else if (n == "location") { - if (!il) + if (flag (package_manifest_flags::forbid_location)) bad_name ("package location not allowed"); if (m.location) @@ -1319,7 +1324,7 @@ namespace bpkg } else if (n == "sha256sum") { - if (!il) + if (flag (package_manifest_flags::forbid_sha256sum)) bad_name ("package sha256sum not allowed"); if (m.sha256sum) @@ -1332,7 +1337,7 @@ namespace bpkg } else if (n == "fragment") { - if (!il) + if (flag (package_manifest_flags::forbid_fragment)) bad_name ("package repository fragment not allowed"); if (m.fragment) @@ -1358,30 +1363,30 @@ namespace bpkg else if (m.license_alternatives.empty ()) bad_value ("no project license specified"); - if (il) - { - if (!m.location) - bad_name ("no package location specified"); + if (!m.location && flag (package_manifest_flags::require_location)) + bad_name ("no package location specified"); - if (!m.sha256sum) - bad_name ("no package sha256sum specified"); - } + if (!m.sha256sum && flag (package_manifest_flags::require_sha256sum)) + bad_name ("no package sha256sum specified"); } package_manifest pkg_package_manifest (parser& p, name_value nv, bool iu) { - package_manifest r; - parse_package_manifest (p, nv, true, iu, r); - return r; + return package_manifest (p, + move (nv), + iu, + package_manifest_flags::forbid_file | + package_manifest_flags::require_location | + package_manifest_flags::forbid_fragment); } // package_manifest // package_manifest:: - package_manifest (manifest_parser& p, bool iu) + package_manifest (manifest_parser& p, bool iu, package_manifest_flags fl) { - parse_package_manifest (p, p.next (), false, iu, *this); + parse_package_manifest (p, p.next (), iu, fl, *this); // Make sure this is the end. // @@ -1391,6 +1396,15 @@ namespace bpkg "single package manifest expected"); } + package_manifest:: + package_manifest (manifest_parser& p, + name_value nv, + bool iu, + package_manifest_flags fl) + { + parse_package_manifest (p, move (nv), iu, fl, *this); + } + static void serialize_package_manifest (manifest_serializer& s, const package_manifest& m, diff --git a/libbpkg/manifest.hxx b/libbpkg/manifest.hxx index 20ff344..42e1a24 100644 --- a/libbpkg/manifest.hxx +++ b/libbpkg/manifest.hxx @@ -378,6 +378,56 @@ namespace bpkg comment (std::move (c)) {} }; + // Package manifest value forbid/require flags. + // + // Some package manifest values can be forbidden or required for certain + // repository types and in specific contexts (for example, when parsing an + // individual manifest, a manifest list, etc). + // + // Also note that, naturally, the forbid_* and require_* flags are mutually + // exclusive for the same value. + // + enum class package_manifest_flags: std::uint16_t + { + none = 0x0, + + forbid_file = 0x1, // Forbid *-file manifest values. + forbid_location = 0x2, + forbid_sha256sum = 0x4, + forbid_fragment = 0x8, + + require_location = 0x10, + require_sha256sum = 0x20 + }; + + inline package_manifest_flags + operator&= (package_manifest_flags& x, package_manifest_flags y) + { + return x = static_cast<package_manifest_flags> ( + static_cast<std::uint16_t> (x) & + static_cast<std::uint16_t> (y)); + } + + inline package_manifest_flags + operator|= (package_manifest_flags& x, package_manifest_flags y) + { + return x = static_cast<package_manifest_flags> ( + static_cast<std::uint16_t> (x) | + static_cast<std::uint16_t> (y)); + } + + inline package_manifest_flags + operator& (package_manifest_flags x, package_manifest_flags y) + { + return x &= y; + } + + inline package_manifest_flags + operator| (package_manifest_flags x, package_manifest_flags y) + { + return x |= y; + } + class LIBBPKG_EXPORT package_manifest { public: @@ -418,7 +468,25 @@ namespace bpkg public: package_manifest () = default; // VC export. - package_manifest (butl::manifest_parser&, bool ignore_unknown = false); + + // Create individual manifest. + // + // The default package_manifest_flags value corresponds to a valid + // individual package manifest. + // + package_manifest (butl::manifest_parser&, + bool ignore_unknown = false, + package_manifest_flags = + package_manifest_flags::forbid_location | + package_manifest_flags::forbid_sha256sum | + package_manifest_flags::forbid_fragment); + + // Create an element of the list manifest. + // + package_manifest (butl::manifest_parser&, + butl::manifest_name_value start, + bool ignore_unknown, + package_manifest_flags); void serialize (butl::manifest_serializer&) const; |