aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2023-01-12 14:00:49 +0200
committerKaren Arutyunov <karen@codesynthesis.com>2023-01-16 16:22:15 +0300
commit4e1978b3d65e22b96e0c4ff47ebae1a6de4de283 (patch)
tree0f47c814d749e0ec00d6aeba97d938beaa53a46e
parent1e61496d9c5f4943c320a0fccd36a6ab3da45248 (diff)
Initial system package manager infrastructure
-rw-r--r--bpkg/bpkg.cxx1
-rw-r--r--bpkg/buildfile8
-rw-r--r--bpkg/pkg-build.cxx86
-rw-r--r--bpkg/system-package-manager.cxx31
-rw-r--r--bpkg/system-package-manager.hxx34
-rw-r--r--bpkg/types.hxx5
-rw-r--r--bpkg/utility.cxx2
-rw-r--r--bpkg/utility.hxx4
8 files changed, 141 insertions, 30 deletions
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 <bpkg/pkg-disfigure.hxx>
#include <bpkg/package-query.hxx>
#include <bpkg/package-skeleton.hxx>
+
#include <bpkg/system-repository.hxx>
+#include <bpkg/system-package-manager.hxx>
#include <bpkg/pkg-build-collect.hxx>
@@ -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<unique_ptr<system_package_manager>> ()] // Create lazy.
+ (database* db,
+ const package_name& nm,
+ optional<version_constraint> 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 <bpkg/system-package-manager.hxx>
+
+#include <bpkg/diagnostics.hxx>
+
+namespace bpkg
+{
+ system_package_manager::
+ ~system_package_manager ()
+ {
+ // vtable
+ }
+
+ unique_ptr<system_package_manager>
+ make_system_package_manager (const target_triplet& host,
+ const string& type)
+ {
+ unique_ptr<system_package_manager> 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 <libbpkg/manifest.hxx> // version
+//#include <libbpkg/package-name.hxx>
+
+#include <bpkg/types.hxx>
+#include <bpkg/utility.hxx>
+
+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<system_package_manager>
+ 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 <libbutl/optional.hxx>
#include <libbutl/fdstream.hxx>
#include <libbutl/small-vector.hxx>
+#include <libbutl/target-triplet.hxx>
#include <libbutl/default-options.hxx>
namespace bpkg
@@ -127,6 +128,10 @@ namespace bpkg
using butl::ofdstream;
using butl::fdstream_mode;
+ // <libbutl/target-triplet.hxx>
+ //
+ using butl::target_triplet;
+
// <libbutl/default-options.hxx>
//
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<dir_path, dir_path> 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 <cfg-dir> to <cfg-dir>/.bpkg/tmp/ but can also map