From d3f62eb0cbdd6080a26d4e9013bf9f6671cee9d9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 4 Sep 2015 14:09:51 +0200 Subject: Split manifests into package_manifests and repository_manifests --- bpkg/manifest | 23 +++++++++++++---- bpkg/manifest.cxx | 62 +++++++++++++++++++++++++++------------------ tests/manifest/.gitignore | 2 ++ tests/manifest/buildfile | 20 +++++++++++++-- tests/manifest/driver.cxx | 9 +++++-- tests/manifest/manifest | 50 ------------------------------------ tests/manifest/packages | 47 ++++++++++++++++++++++++++++++++++ tests/manifest/repositories | 5 ++++ 8 files changed, 135 insertions(+), 83 deletions(-) create mode 100644 tests/manifest/.gitignore delete mode 100644 tests/manifest/manifest create mode 100644 tests/manifest/packages create mode 100644 tests/manifest/repositories diff --git a/bpkg/manifest b/bpkg/manifest index 0f03371..d5b036f 100644 --- a/bpkg/manifest +++ b/bpkg/manifest @@ -303,6 +303,19 @@ namespace bpkg serialize (manifest_serializer&) const; }; + class package_manifests: public std::vector + { + public: + using base_type = std::vector; + + using base_type::base_type; + + package_manifests (manifest_parser&); + + void + serialize (manifest_serializer&) const; + }; + class repository_location { public: @@ -425,14 +438,14 @@ namespace bpkg serialize (manifest_serializer&) const; }; - class manifests + class repository_manifests: public std::vector { public: - std::vector repositories; - std::vector packages; + using base_type = std::vector; - public: - manifests (manifest_parser&); + using base_type::base_type; + + repository_manifests (manifest_parser&); void serialize (manifest_serializer&) const; diff --git a/bpkg/manifest.cxx b/bpkg/manifest.cxx index d080fbb..4cbaad5 100644 --- a/bpkg/manifest.cxx +++ b/bpkg/manifest.cxx @@ -773,6 +773,24 @@ namespace bpkg s.next ("", ""); // End of manifest. } + // package_manifests + // + package_manifests:: + package_manifests (parser& p) + { + for (name_value nv (p.next ()); !nv.empty (); nv = p.next ()) + push_back (package_manifest (p, nv)); + } + + void package_manifests:: + serialize (serializer& s) const + { + for (const package_manifest& p: *this) + p.serialize (s); + + s.next ("", ""); // End of stream. + } + // repository_location // // Location parameter type is fully qualified as compiler gets confused with @@ -1089,42 +1107,38 @@ namespace bpkg s.next ("", ""); // End of manifest. } - // manifests + // repository_manifests // - manifests:: - manifests (parser& p) + repository_manifests:: + repository_manifests (parser& p) { - bool rep (true); // Parsing repository list. - - for (name_value nv (p.next ()); !nv.empty (); nv = p.next ()) + name_value nv (p.next ()); + while (!nv.empty ()) { - if (rep) - { - repositories.push_back (repository_manifest (p, nv)); + push_back (repository_manifest (p, nv)); + nv = p.next (); - // Manifest for local repository signals the end of the - // repository list. - // - if (repositories.back ().location.empty ()) - rep = false; - } - else - packages.push_back (package_manifest (p, nv)); + // Make sure there is location in all except the last entry. + // + if (back ().location.empty () && !nv.empty ()) + throw parsing (p.name (), nv.name_line, nv.name_column, + "repository location expected"); } + + if (empty () || !back ().location.empty ()) + throw parsing (p.name (), nv.name_line, nv.name_column, + "base repository manifest expected"); } - void manifests:: + void repository_manifests:: serialize (serializer& s) const { - if (repositories.empty () || !repositories.back ().location.empty ()) - throw serialization (s.name (), "local repository manifest expected"); + if (empty () || !back ().location.empty ()) + throw serialization (s.name (), "base repository manifest expected"); - for (const repository_manifest& r: repositories) + for (const repository_manifest& r: *this) r.serialize (s); - for (const package_manifest& p: packages) - p.serialize (s); - s.next ("", ""); // End of stream. } } diff --git a/tests/manifest/.gitignore b/tests/manifest/.gitignore new file mode 100644 index 0000000..d0bb148 --- /dev/null +++ b/tests/manifest/.gitignore @@ -0,0 +1,2 @@ +pdriver +rdriver diff --git a/tests/manifest/buildfile b/tests/manifest/buildfile index 9dc2258..76041c6 100644 --- a/tests/manifest/buildfile +++ b/tests/manifest/buildfile @@ -2,7 +2,23 @@ # copyright : Copyright (c) 2014-2015 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -exe{driver}: cxx{driver} ../../bpkg/lib{bpkg} -exe{driver}: test.roundtrip = manifest +#exe{driver}: cxx{driver} ../../bpkg/lib{bpkg} +#exe{driver}: test.roundtrip = manifest + +# @@ Hack until build2 supports multiple tests. Also remove .gitignore. +# +./: exe{pdriver} exe{rdriver} + +exe{pdriver}: obj{pdriver} +exe{pdriver}: test.roundtrip = packages + +exe{rdriver}: obj{rdriver} +exe{rdriver}: test.roundtrip = repositories + +obj{pdriver rdriver}: cxx{driver} +exe{pdriver rdriver} obj{pdriver rdriver}: ../../bpkg/lib{bpkg} + +obj{pdriver}: cxx.poptions += -DTEST_PACKAGES +obj{rdriver}: cxx.poptions += -DTEST_REPOSITORIES include ../../bpkg/ diff --git a/tests/manifest/driver.cxx b/tests/manifest/driver.cxx index f3b5abf..4722425 100644 --- a/tests/manifest/driver.cxx +++ b/tests/manifest/driver.cxx @@ -25,10 +25,15 @@ main (int argc, char* argv[]) { ifstream ifs; ifs.exceptions (ifstream::badbit | ifstream::failbit); - ifs.open (argv[1], ifstream::in | ifstream::binary); + ifs.open (argv[1]); manifest_parser p (ifs, argv[1]); - manifests ms (p); + +#ifdef TEST_PACKAGES + package_manifests ms (p); +#else + repository_manifests ms (p); +#endif manifest_serializer s (cout, "stdout"); ms.serialize (s); diff --git a/tests/manifest/manifest b/tests/manifest/manifest deleted file mode 100644 index 902a7ac..0000000 --- a/tests/manifest/manifest +++ /dev/null @@ -1,50 +0,0 @@ -: 1 -location: http://pkg.example.org/1/math -: -: -name: libfoo -version: 1.2.3-2 -priority: high; Due to critical bug fix. -summary: Modern XML parser -license: LGPLv2, MIT; Both required. -license: BSD -tags: c++, xml, parser, serializer, pull, streaming, modern -description: libfoo is a very modern C++ XML parser. -changes: 1.2.3-2: applied upstream patch for critical bug bar -changes: 1.2.3-1: applied upstream patch for critical bug foo -changes-file: NEWS -url: http://www.example.org/projects/libfoo/; libfoo project page url -package-url: http://www.example.org/projects/libbar/1.2.3-2; package url -email: libfoo-users@example.org; Public mailing list, posts by non-members\ - are allowed but moderated. -package-email: libfoo-1.2.3-2@example.org; Bug reports are welcome. -depends: libz -depends: libgnutls <= 1.2.3 | libopenssl >= 2.3.4 -depends: ? libboost-regex >= 1.52.0; Only if C++ compiler doesn't support\ - C++11 . -depends: ? libqtcore >= 5.0.0; Only if GUI is enabled. -requires: linux | windows | macosx; symbian is coming. -requires: c++11 -requires: ? ; VC++ 12.0 or later if targeting Windows. -requires: ? ; libc++ standard library if using Clang on Mac OS X. -requires: zlib; Most Linux/UNIX systems already have one; or get it at\ - www.zlib.net. -location: libfoo-1.2.3-2.tar.bz2 -: -name: libbar -version: 3.4A.5-6 -summary: Modern bar management framework -license: LGPLv2 -tags: c++, xml, modern -description-file: README; Comprehensive description -url: http://www.example.org/projects/libbar/ -email: libbar-users@example.org -location: bar/libbar-3.4A.5-6.tbz -: -name: libbaz -version: 2+3.4A.5-3 -summary: Modern baz system -license: LGPLv2 -url: http://www.example.org/projects/libbar/ -email: libbaz-users@example.org -location: libbaz/libbaz-2+3.4A.5-3.tar.gz diff --git a/tests/manifest/packages b/tests/manifest/packages new file mode 100644 index 0000000..9ae65bc --- /dev/null +++ b/tests/manifest/packages @@ -0,0 +1,47 @@ +: 1 +name: libfoo +version: 1.2.3-2 +priority: high; Due to critical bug fix. +summary: Modern XML parser +license: LGPLv2, MIT; Both required. +license: BSD +tags: c++, xml, parser, serializer, pull, streaming, modern +description: libfoo is a very modern C++ XML parser. +changes: 1.2.3-2: applied upstream patch for critical bug bar +changes: 1.2.3-1: applied upstream patch for critical bug foo +changes-file: NEWS +url: http://www.example.org/projects/libfoo/; libfoo project page url +package-url: http://www.example.org/projects/libbar/1.2.3-2; package url +email: libfoo-users@example.org; Public mailing list, posts by non-members\ + are allowed but moderated. +package-email: libfoo-1.2.3-2@example.org; Bug reports are welcome. +depends: libz +depends: libgnutls <= 1.2.3 | libopenssl >= 2.3.4 +depends: ? libboost-regex >= 1.52.0; Only if C++ compiler doesn't support\ + C++11 . +depends: ? libqtcore >= 5.0.0; Only if GUI is enabled. +requires: linux | windows | macosx; symbian is coming. +requires: c++11 +requires: ? ; VC++ 12.0 or later if targeting Windows. +requires: ? ; libc++ standard library if using Clang on Mac OS X. +requires: zlib; Most Linux/UNIX systems already have one; or get it at\ + www.zlib.net. +location: libfoo-1.2.3-2.tar.bz2 +: +name: libbar +version: 3.4A.5-6 +summary: Modern bar management framework +license: LGPLv2 +tags: c++, xml, modern +description-file: README; Comprehensive description +url: http://www.example.org/projects/libbar/ +email: libbar-users@example.org +location: bar/libbar-3.4A.5-6.tbz +: +name: libbaz +version: 2+3.4A.5-3 +summary: Modern baz system +license: LGPLv2 +url: http://www.example.org/projects/libbar/ +email: libbaz-users@example.org +location: libbaz/libbaz-2+3.4A.5-3.tar.gz diff --git a/tests/manifest/repositories b/tests/manifest/repositories new file mode 100644 index 0000000..b446dd4 --- /dev/null +++ b/tests/manifest/repositories @@ -0,0 +1,5 @@ +: 1 +location: http://pkg.example.org/1/math +: +location: ../stable +: -- cgit v1.1