From 4e1978b3d65e22b96e0c4ff47ebae1a6de4de283 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 12 Jan 2023 14:00:49 +0200 Subject: Initial system package manager infrastructure --- bpkg/bpkg.cxx | 1 + bpkg/buildfile | 8 ++-- bpkg/pkg-build.cxx | 86 ++++++++++++++++++++++++++++------------- bpkg/system-package-manager.cxx | 31 +++++++++++++++ bpkg/system-package-manager.hxx | 34 ++++++++++++++++ bpkg/types.hxx | 5 +++ bpkg/utility.cxx | 2 + bpkg/utility.hxx | 4 ++ 8 files changed, 141 insertions(+), 30 deletions(-) create mode 100644 bpkg/system-package-manager.cxx create mode 100644 bpkg/system-package-manager.hxx diff --git a/bpkg/bpkg.cxx b/bpkg/bpkg.cxx index 3ede99e..76b2533 100644 --- a/bpkg/bpkg.cxx +++ b/bpkg/bpkg.cxx @@ -611,6 +611,7 @@ try cout << "bpkg " << BPKG_VERSION_ID << endl << "libbpkg " << LIBBPKG_VERSION_ID << endl << "libbutl " << LIBBUTL_VERSION_ID << endl + << "host " << host_triplet << endl << "Copyright (c) " << BPKG_COPYRIGHT << "." << endl << "This is free software released under the MIT license." << endl; return 0; diff --git a/bpkg/buildfile b/bpkg/buildfile index b3b2ba7..ca78218 100644 --- a/bpkg/buildfile +++ b/bpkg/buildfile @@ -97,8 +97,10 @@ for t: cxx{**.test...} # Build options. # -obj{utility}: cxx.poptions += -DBPKG_EXE_PREFIX='"'$bin.exe.prefix'"' \ --DBPKG_EXE_SUFFIX='"'$bin.exe.suffix'"' +obj{utility}: cxx.poptions += \ +"-DBPKG_EXE_PREFIX=\"$bin.exe.prefix\"" \ +"-DBPKG_EXE_SUFFIX=\"$bin.exe.suffix\"" \ +"-DBPKG_HOST_TRIPLET=\"$cxx.target\"" # Pass the copyright notice extracted from the LICENSE file. # @@ -107,7 +109,7 @@ copyright = $process.run_regex( \ 'Copyright \(c\) (.+) \(see the AUTHORS and LEGAL files\)\.', \ '\1') -obj{bpkg}: cxx.poptions += -DBPKG_COPYRIGHT=\"$copyright\" +obj{bpkg}: cxx.poptions += "-DBPKG_COPYRIGHT=\"$copyright\"" # Disable "unknown pragma" warnings. # diff --git a/bpkg/pkg-build.cxx b/bpkg/pkg-build.cxx index aa34594..437e080 100644 --- a/bpkg/pkg-build.cxx +++ b/bpkg/pkg-build.cxx @@ -32,7 +32,9 @@ #include #include #include + #include +#include #include @@ -1652,23 +1654,68 @@ namespace bpkg return r; }; - // Add the system package authoritative information to the database's - // system repository, unless it already contains authoritative information - // for this package. + // Figure out the system package version unless explicitly specified and + // add the system package authoritative information to the database's + // system repository unless the database is NULL or it already contains + // authoritative information for this package. Return the figured out + // system package version as constraint. // // Note that it is assumed that all the possible duplicates are handled // elsewhere/later. // - auto add_system_package = [] (database& db, - const package_name& nm, - const version& v) + auto add_system_package = + [spm = optional> ()] // Create lazy. + (database* db, + const package_name& nm, + optional vc) mutable { - assert (db.system_repository); + if (!vc) + { + // @@ Where do we check that this package should have available_ + // package (source or stub)? We will need to drag all such + // available packages into this call in order to get the + // name/version mappings. - const system_package* sp (db.system_repository->find (nm)); + // See if we should query the system package manager. + // + // @@ TODO: --sys-no-query + // + if (!spm) + spm = /*ops.sys_no_query ()*/ false + ? nullptr + : make_system_package_manager (host_triplet, "" /* type */); - if (sp == nullptr || !sp->authoritative) - db.system_repository->insert (nm, v, true /* authoritative */); + if (*spm != nullptr) + { + // @@ TODO: query the version + // + //system_package_manager& m (**spm); + } + else + vc = version_constraint (wildcard_version); + } + else + // The system package may only have an exact/wildcard version + // specified. + // + assert (vc->min_version == vc->max_version); + + if (db != nullptr) + { + assert (db->system_repository); + + const system_package* sp (db->system_repository->find (nm)); + + if (sp == nullptr || !sp->authoritative) + db->system_repository->insert (nm, + *vc->min_version, + true /* authoritative */); + + // @@ If it is authoritative, wouldn't it be a good idea to check that + // the versions match? + } + + return vc; }; // Create the parsed package argument. Issue diagnostics and fail if the @@ -1707,17 +1754,7 @@ namespace bpkg { case package_scheme::sys: { - if (!r.constraint) - r.constraint = version_constraint (wildcard_version); - - // The system package may only have an exact/wildcard version - // specified. - // - assert (r.constraint->min_version == r.constraint->max_version); - - if (db != nullptr) - add_system_package (*db, r.name, *r.constraint->min_version); - + r.constraint = add_system_package (db, r.name, move (r.constraint)); break; } case package_scheme::none: break; // Nothing to do. @@ -3180,12 +3217,7 @@ namespace bpkg // The system package may only have an exact/wildcard version // specified. // - add_system_package (db, - p.name, - (p.constraint - ? *p.constraint->min_version - : wildcard_version)); - + add_system_package (&db, p.name, p.constraint); enter (db, p); }; diff --git a/bpkg/system-package-manager.cxx b/bpkg/system-package-manager.cxx new file mode 100644 index 0000000..1503c32 --- /dev/null +++ b/bpkg/system-package-manager.cxx @@ -0,0 +1,31 @@ +// file : bpkg/system-package-manager.cxx -*- C++ -*- +// license : MIT; see accompanying LICENSE file + +#include + +#include + +namespace bpkg +{ + system_package_manager:: + ~system_package_manager () + { + // vtable + } + + unique_ptr + make_system_package_manager (const target_triplet& host, + const string& type) + { + unique_ptr r; + + if (r == nullptr) + { + if (!type.empty ()) + fail << "unsupported package manager type '" << type << "' for host " + << host; + } + + return r; + } +} diff --git a/bpkg/system-package-manager.hxx b/bpkg/system-package-manager.hxx new file mode 100644 index 0000000..122b181 --- /dev/null +++ b/bpkg/system-package-manager.hxx @@ -0,0 +1,34 @@ +// file : bpkg/system-package-manager.hxx -*- C++ -*- +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_SYSTEM_PACKAGE_MANAGER_HXX +#define BPKG_SYSTEM_PACKAGE_MANAGER_HXX + +//#include // version +//#include + +#include +#include + +namespace bpkg +{ + // The system package manager interface. Used by both pkg-build (to query + // and install system packages) and by pkg-bindist (to build them). + // + class system_package_manager + { + public: + virtual + ~system_package_manager (); + }; + + // Create a package manager instance corresponding to the specified host + // target and optional manager type. If type is empty, return NULL if there + // is no support for this platform. + // + unique_ptr + make_system_package_manager (const target_triplet&, + const string& type); +} + +#endif // BPKG_SYSTEM_PACKAGE_MANAGER_HXX diff --git a/bpkg/types.hxx b/bpkg/types.hxx index 2b6a1f8..7a7b2c7 100644 --- a/bpkg/types.hxx +++ b/bpkg/types.hxx @@ -33,6 +33,7 @@ #include #include #include +#include #include namespace bpkg @@ -127,6 +128,10 @@ namespace bpkg using butl::ofdstream; using butl::fdstream_mode; + // + // + using butl::target_triplet; + // // using butl::default_options_files; diff --git a/bpkg/utility.cxx b/bpkg/utility.cxx index 52114df..b79c85b 100644 --- a/bpkg/utility.cxx +++ b/bpkg/utility.cxx @@ -46,6 +46,8 @@ namespace bpkg const dir_path current_dir ("."); + const target_triplet host_triplet (BPKG_HOST_TRIPLET); + map tmp_dirs; bool keep_tmp; diff --git a/bpkg/utility.hxx b/bpkg/utility.hxx index 8e7260a..04c7c94 100644 --- a/bpkg/utility.hxx +++ b/bpkg/utility.hxx @@ -99,6 +99,10 @@ namespace bpkg extern const dir_path current_dir; // ./ + // Host target triplet for which we were built. + // + extern const target_triplet host_triplet; + // Temporary directory facility. // // An entry normally maps to /.bpkg/tmp/ but can also map -- cgit v1.1