diff options
-rw-r--r-- | libbpkg/manifest.cxx | 65 | ||||
-rw-r--r-- | libbpkg/manifest.hxx | 23 |
2 files changed, 53 insertions, 35 deletions
diff --git a/libbpkg/manifest.cxx b/libbpkg/manifest.cxx index 48ec383..d605176 100644 --- a/libbpkg/manifest.cxx +++ b/libbpkg/manifest.cxx @@ -1121,6 +1121,21 @@ namespace bpkg return r; } + // dependency_alternative + // + dependency_alternative:: + dependency_alternative (const std::string& s) + { + push_back (dependency (s)); // @@ DEP + } + + string dependency_alternative:: + string () const + { + assert (size () == 1); // @@ DEP + return front ().string (); + } + // dependency_alternatives // dependency_alternatives:: @@ -1153,39 +1168,24 @@ namespace bpkg list_parser lp (b, e, '|'); for (string lv (lp.next ()); !lv.empty (); lv = lp.next ()) - push_back (dependency (move (lv))); + push_back (dependency_alternative (lv)); } string dependency_alternatives:: string () const { - using std::string; - - string r; - - if (conditional) - r += '?'; - - if (buildtime) - r += '*'; - - if (conditional || buildtime) - r += ' '; + std::string r (conditional + ? (buildtime ? "?* " : "? ") + : (buildtime ? "* " : "")); bool f (true); - for (const dependency& a: *this) + for (const dependency_alternative& da: *this) { r += (f ? (f = false, "") : " | "); - r += a.string (); + r += da.string (); } - if (!comment.empty ()) - { - r += "; "; - r += comment; - } - - return r; + return serializer::merge_comment (r, comment); } // requirement_alternatives @@ -1220,7 +1220,7 @@ namespace bpkg list_parser lp (b, e, '|'); for (string lv (lp.next ()); !lv.empty (); lv = lp.next ()) - push_back (lv); + push_back (move (lv)); if (empty () && comment.empty ()) throw invalid_argument ("empty package requirement specification"); @@ -2463,15 +2463,18 @@ namespace bpkg // try { - dependency_alternatives da (v); + dependency_alternatives das (v); - if (da.empty ()) + if (das.empty ()) bad_value ("empty package dependency specification"); - for (dependency& d: da) - d = complete_constraint (move (d)); + for (dependency_alternative& da: das) + { + for (dependency& d: da) + d = complete_constraint (move (d)); + } - m.dependencies.push_back (move (da)); + m.dependencies.push_back (move (das)); } catch (const invalid_argument& e) { @@ -2937,11 +2940,7 @@ namespace bpkg m.build_error_email->comment)); for (const dependency_alternatives& d: m.dependencies) - s.next ("depends", - (d.conditional - ? (d.buildtime ? "?* " : "? ") - : (d.buildtime ? "* " : "")) + - serializer::merge_comment (concatenate (d, " | "), d.comment)); + s.next ("depends", d.string ()); for (const requirement_alternatives& r: m.requirements) s.next ("requires", r.string ()); diff --git a/libbpkg/manifest.hxx b/libbpkg/manifest.hxx index f487a90..ef44fcb 100644 --- a/libbpkg/manifest.hxx +++ b/libbpkg/manifest.hxx @@ -455,7 +455,26 @@ namespace bpkg // depends // - class dependency_alternatives: public butl::small_vector<dependency, 1> + class dependency_alternative: public butl::small_vector<dependency, 1> + { + public: + butl::optional<std::string> enable; + + dependency_alternative () = default; + dependency_alternative (butl::optional<std::string> e) + : enable (std::move (e)) {} + + // Parse the dependency alternative string representation. + // + explicit LIBBPKG_EXPORT + dependency_alternative (const std::string&); + + LIBBPKG_EXPORT std::string + string () const; + }; + + class dependency_alternatives: + public butl::small_vector<dependency_alternative, 1> { public: bool conditional; @@ -468,7 +487,7 @@ namespace bpkg // Parse the dependency alternatives string representation in the // `[?][*] <dependency> [ '|' <dependency>]* [; <comment>]` form. Throw - // std::invalid_argument if the value is invalid. + // std::invalid_argument if the value is invalid. @@ DEP @@ TMP update. // explicit LIBBPKG_EXPORT dependency_alternatives (const std::string&); |