From d956e69e8b55dc2248b902490a138a46f02f9e55 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 1 Feb 2023 14:32:04 +0200 Subject: Add --sys-no-stub bpkg-pkg-build option to allow sys: packages without stubs --- bpkg/pkg-build.cli | 10 +++++++++- bpkg/pkg-build.cxx | 16 +++++++++++++--- bpkg/system-package-manager-debian.cxx | 23 +++++++++++++---------- bpkg/system-package-manager.cxx | 2 ++ 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/bpkg/pkg-build.cli b/bpkg/pkg-build.cli index 740764b..41a8432 100644 --- a/bpkg/pkg-build.cli +++ b/bpkg/pkg-build.cli @@ -107,7 +107,8 @@ namespace bpkg manager is supported, then the automatic installation of an available package can be requested with the \cb{--sys-install} option. Note that if the version is not explicitly specified, then at least a stub package - must be available from one of the repositories. + must be available from one of the repositories unless the + \cb{--sys-no-stub} option is specified. Finally, a package can be specified as either the path to the package archive () or to the package directory (\cb{/}; note that it @@ -437,6 +438,13 @@ namespace bpkg This option only makes sense together with \cb{--sys-install}." } + bool --sys-no-stub + { + "Do no require a stub for packages specified with the \cb{sys} scheme. + Note that this option has effect only if the system package manager + interactions are supported and not disabled." + } + bool --sys-yes { "Assume the answer to the system package manager prompts is \cb{yes}. diff --git a/bpkg/pkg-build.cxx b/bpkg/pkg-build.cxx index 4d90df2..9e5e1bb 100644 --- a/bpkg/pkg-build.cxx +++ b/bpkg/pkg-build.cxx @@ -1714,11 +1714,21 @@ namespace bpkg aps = find_available_all (current_configs, nm); // If no source/stub for the package (and thus no mapping), issue - // diagnostics consistent with other such places. + // diagnostics consistent with other such places unless explicitly + // allowed by the user. // if (aps.empty ()) - fail << "unknown package " << nm << - info << "consider specifying " << nm << "/*"; + { + if (!o.sys_no_stub ()) + fail << "unknown package " << nm << + info << "consider specifying --sys-no-stub or " << nm << "/*"; + + // Add the stub package to the imaginary system repository (like + // the user-specified case below). + // + if (stubs != nullptr) + stubs->push_back (make_shared (nm)); + } } // This covers both our diagnostics below as well as anything that diff --git a/bpkg/system-package-manager-debian.cxx b/bpkg/system-package-manager-debian.cxx index 06b5060..998c4f4 100644 --- a/bpkg/system-package-manager-debian.cxx +++ b/bpkg/system-package-manager-debian.cxx @@ -891,10 +891,12 @@ namespace bpkg << os_release_.name_id << " package name"; }); - strings ns (system_package_names (*aps, - os_release_.name_id, - os_release_.version_id, - os_release_.like_ids)); + strings ns; + if (!aps->empty ()) + ns = system_package_names (*aps, + os_release_.name_id, + os_release_.version_id, + os_release_.like_ids); if (ns.empty ()) { // Attempt to automatically translate our package name (see above for @@ -1231,12 +1233,13 @@ namespace bpkg // string sv (r->system_version, 0, r->system_version.rfind ('-')); - optional v ( - downstream_package_version (sv, - *aps, - os_release_.name_id, - os_release_.version_id, - os_release_.like_ids)); + optional v; + if (!aps->empty ()) + v = downstream_package_version (sv, + *aps, + os_release_.name_id, + os_release_.version_id, + os_release_.like_ids); if (!v) { diff --git a/bpkg/system-package-manager.cxx b/bpkg/system-package-manager.cxx index 9f5dad0..5089db1 100644 --- a/bpkg/system-package-manager.cxx +++ b/bpkg/system-package-manager.cxx @@ -280,6 +280,8 @@ namespace bpkg const string& version_id, const vector& like_ids) { + assert (!aps.empty ()); + semantic_version vid (parse_version_id (version_id, name_id)); // Iterate over the passed available packages (in version descending -- cgit v1.1