aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2023-01-26 07:39:54 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2023-01-26 07:39:54 +0200
commit80f8b0d7653a9445c74aaf67d2ad87b8ebf7503a (patch)
tree6a48801c424e1e27fc2bd27b6b0e505321fa5ef8
parent64654832a7bcd735f3581d254b18bf724a9cc0a7 (diff)
Test parse_name_value() (used to be parse_debian_name())
-rw-r--r--bpkg/system-package-manager-debian.cxx44
-rw-r--r--bpkg/system-package-manager-debian.hxx36
-rw-r--r--bpkg/system-package-manager-debian.test.cxx30
-rw-r--r--bpkg/system-package-manager-debian.test.testscript54
4 files changed, 122 insertions, 42 deletions
diff --git a/bpkg/system-package-manager-debian.cxx b/bpkg/system-package-manager-debian.cxx
index a7da2c0..c19ebb4 100644
--- a/bpkg/system-package-manager-debian.cxx
+++ b/bpkg/system-package-manager-debian.cxx
@@ -13,41 +13,15 @@ namespace bpkg
// Parse the debian-name (or alike) value.
//
- // The format of this value is a comma-separated list of one or more package
- // groups:
+ // Note that for now we treat all the packages from the non-main groups as
+ // extras omitting the -common package (assuming it's pulled by the main
+ // package) as well as -doc and -dbg unless requested with the
+ // extra_{doc,dbg} arguments.
//
- // <package-group> [, <package-group>...]
- //
- // Where each <package-group> is the space-separated list of one or more
- // package names:
- //
- // <package-name> [ <package-name>...]
- //
- // All the packages in the group should be "package components" (for the
- // lack of a better term) of the same "logical package", such as -dev, -doc,
- // -common packages. They usually have the same version.
- //
- // The first group is called the main group and the first package in the
- // group is called the main package.
- //
- // We allow/recommend specifying the -dev package instead of the main
- // package for libraries (the name starts with lib), seeing that we are
- // capable of detecting the main package automatically. If the library name
- // happens to end with -dev (which poses an ambiguity), then the -dev
- // package should be specified explicitly as the second package to
- // disambiguate this situation (if a non-library name happened to start with
- // lib and end with -dev, well, you are out of luck, I guess).
- //
- // Note also that for now we treat all the packages from the non-main groups
- // as extras (but in the future we may decide to sort them out like the main
- // group). For now we omit the -common package (assuming it's pulled by the
- // main package) as well as -doc and -dbg unless requested (the
- // extra_{doc,dbg} arguments).
- //
- static package_status
- parse_debian_name (const string& nv,
- bool extra_doc,
- bool extra_dbg)
+ package_status system_package_manager_debian::
+ parse_name_value (const string& nv,
+ bool extra_doc,
+ bool extra_dbg)
{
auto split = [] (const string& s, char d) -> strings
{
@@ -932,7 +906,7 @@ namespace bpkg
//
for (const string& n: ns)
{
- package_status s (parse_debian_name (n, need_doc, need_dbg));
+ package_status s (parse_name_value (n, need_doc, need_dbg));
// Suppress duplicates for good measure based on the main package
// name (and falling back to -dev if empty).
diff --git a/bpkg/system-package-manager-debian.hxx b/bpkg/system-package-manager-debian.hxx
index d3b9f02..7f91d38 100644
--- a/bpkg/system-package-manager-debian.hxx
+++ b/bpkg/system-package-manager-debian.hxx
@@ -16,7 +16,6 @@ namespace bpkg
// The system package manager implementation for Debian and alike (Ubuntu,
// etc) using the APT frontend.
//
-
// For background, a library in Debian is normally split up into several
// packages: the shared library package (e.g., libfoo1 where 1 is the ABI
// version), the development files package (e.g., libfoo-dev), the
@@ -40,12 +39,38 @@ namespace bpkg
// shared library package with the same version and its name should normally
// start with the -dev package's stem.
//
- // For a manual mapping we will require the user to always specify the
- // shared library package and the -dev package names explicitly.
- //
// For executable packages there is normally no -dev packages but -dbg,
// -doc, and -common are plausible.
//
+ // The format of the debian-name (or alike) manifest value value is a comma-
+ // separated list of one or more package groups:
+ //
+ // <package-group> [, <package-group>...]
+ //
+ // Where each <package-group> is the space-separated list of one or more
+ // package names:
+ //
+ // <package-name> [ <package-name>...]
+ //
+ // All the packages in the group should be "package components" (for the
+ // lack of a better term) of the same "logical package", such as -dev, -doc,
+ // -common packages. They normally have the same version.
+ //
+ // The first group is called the main group and the first package in the
+ // group is called the main package.
+ //
+ // We allow/recommend specifying the -dev package instead of the main
+ // package for libraries (the name starts with lib), seeing that we are
+ // capable of detecting the main package automatically. If the library name
+ // happens to end with -dev (which poses an ambiguity), then the -dev
+ // package should be specified explicitly as the second package to
+ // disambiguate this situation (if a non-library name happened to start with
+ // lib and end with -dev, well, you are out of luck, I guess).
+ //
+ // Note also that for now we treat all the packages from the non-main groups
+ // as extras but in the future we may decide to sort them out like the main
+ // group (see parse_name_value() for details).
+ //
struct system_package_status_debian: system_package_status
{
string main;
@@ -117,6 +142,9 @@ namespace bpkg
pair<cstrings, const process_path&>
apt_get_common (const char*);
+ static package_status
+ parse_name_value (const string&, bool, bool);
+
static string
main_from_dev (const string&, const string&, const string&);
diff --git a/bpkg/system-package-manager-debian.test.cxx b/bpkg/system-package-manager-debian.test.cxx
index dc5f418..b44fdc1 100644
--- a/bpkg/system-package-manager-debian.test.cxx
+++ b/bpkg/system-package-manager-debian.test.cxx
@@ -26,6 +26,8 @@ namespace bpkg
//
// apt-cache-show <pkg> <ver> result comes from stdin
//
+ // parse_name_value debian-name value from from stdin
+ //
// main-from-dev <dev-pkg> <dev-ver> depends comes from stdin
//
int
@@ -80,7 +82,29 @@ namespace bpkg
s.apt_cache_show_.emplace (key, path ("-"));
- cout << m.apt_cache_show (key.first, key.second) << "\n";
+ cout << m.apt_cache_show (key.first, key.second) << '\n';
+ }
+ else if (cmd == "parse-name-value")
+ {
+ assert (argc == 2);
+
+ string v;
+ getline (cin, v);
+
+ package_status s (m.parse_name_value (v, false, false));
+
+ if (!s.main.empty ()) cout << "main: " << s.main << '\n';
+ if (!s.dev.empty ()) cout << "dev: " << s.dev << '\n';
+ if (!s.doc.empty ()) cout << "doc: " << s.doc << '\n';
+ if (!s.dbg.empty ()) cout << "dbg: " << s.dbg << '\n';
+ if (!s.common.empty ()) cout << "common: " << s.common << '\n';
+ if (!s.extras.empty ())
+ {
+ cout << "extras:";
+ for (const string& e: s.extras)
+ cout << ' ' << e;
+ cout << '\n';
+ }
}
else if (cmd == "main-from-dev")
{
@@ -89,9 +113,9 @@ namespace bpkg
string n (argv[2]);
string v (argv[3]);
string d;
- getline (cin, d, '\0');
+ getline (cin, d);
- cout << m.main_from_dev (n, v, d) << "\n";
+ cout << m.main_from_dev (n, v, d) << '\n';
}
else
fail << "unknown command '" << cmd << "'";
diff --git a/bpkg/system-package-manager-debian.test.testscript b/bpkg/system-package-manager-debian.test.testscript
index 290919f..b2cb933 100644
--- a/bpkg/system-package-manager-debian.test.testscript
+++ b/bpkg/system-package-manager-debian.test.testscript
@@ -138,6 +138,60 @@
EOE
}
+: parse-name-value
+:
+{
+ test.arguments += parse-name-value
+
+ : basics
+ :
+ $* <<EOI >>EOO
+ libssl3 libssl-common libssl-doc libssl-dev libssl-dbg libssl-extras, libc6 libc-dev libc-common libc-doc, libz-dev
+ EOI
+ main: libssl3
+ dev: libssl-dev
+ doc: libssl-doc
+ dbg: libssl-dbg
+ common: libssl-common
+ extras: libssl-extras libc6 libc-dev libz-dev
+ EOO
+
+ : non-lib
+ :
+ $* <<EOI >>EOO
+ sqlite3 sqlite3-common sqlite3-doc
+ EOI
+ main: sqlite3
+ doc: sqlite3-doc
+ common: sqlite3-common
+ EOO
+
+ : lib-dev
+ :
+ $* <<EOI >>EOO
+ libssl-dev
+ EOI
+ dev: libssl-dev
+ EOO
+
+ : non-lib-dev
+ :
+ $* <<EOI >>EOO
+ ssl-dev
+ EOI
+ main: ssl-dev
+ EOO
+
+ : lib-custom-dev
+ :
+ $* <<EOI >>EOO
+ libfoo-dev libfoo-dev-dev
+ EOI
+ main: libfoo-dev
+ dev: libfoo-dev-dev
+ EOO
+}
+
: main-from-dev
:
{