mirror of https://github.com/mamba-org/mamba.git
Building MRepo objects through static function that register the repo into the pool (#1547)
This commit is contained in:
parent
5ce0c38b39
commit
6b195b423a
|
@ -6,10 +6,5 @@
|
|||
|
||||
namespace mamba
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
MRepo& create_repo_from_pkgs_dir(MPool& pool, const fs::path& pkgs_dir);
|
||||
}
|
||||
|
||||
void load_channels(MPool& pool, MultiPackageCache& package_caches, int is_retry);
|
||||
}
|
||||
|
|
|
@ -52,51 +52,6 @@ namespace mamba
|
|||
class MRepo
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
* @param pool ``libsolv`` pool wrapper
|
||||
* @param prefix_data prefix data
|
||||
*/
|
||||
MRepo(MPool& pool, const PrefixData& prefix_data);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param pool ``libsolv`` pool wrapper
|
||||
* @param name Name of the subdirectory (<channel>/<subdir>)
|
||||
* @param index Path to the index file
|
||||
* @param url Subdirectory URL
|
||||
*/
|
||||
MRepo(MPool& pool,
|
||||
const std::string& name,
|
||||
const std::string& filename,
|
||||
const std::string& url);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param pool ``libsolv`` pool wrapper
|
||||
* @param name Name of the subdirectory (<channel>/<subdir>)
|
||||
* @param index Path to the index file
|
||||
* @param meta Metadata of the repo
|
||||
*/
|
||||
MRepo(MPool& pool,
|
||||
const std::string& name,
|
||||
const fs::path& filename,
|
||||
const RepoMetadata& meta);
|
||||
|
||||
MRepo(MPool& pool,
|
||||
const std::string& name,
|
||||
const fs::path& filename,
|
||||
const RepoMetadata& meta,
|
||||
const Channel& channel);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param pool ``libsolv`` pool wrapper
|
||||
* @param name Name
|
||||
* @param uris Matchspecs pointing to unique resources (URL or files)
|
||||
*/
|
||||
MRepo(MPool& pool, const std::string& name, const std::vector<PackageInfo>& uris);
|
||||
|
||||
~MRepo();
|
||||
|
||||
MRepo(const MRepo&) = delete;
|
||||
|
@ -122,7 +77,65 @@ namespace mamba
|
|||
|
||||
bool clear(bool reuse_ids);
|
||||
|
||||
/**
|
||||
* Static constructor.
|
||||
* @param pool ``libsolv`` pool wrapper
|
||||
* @param name Name of the subdirectory (<channel>/<subdir>)
|
||||
* @param filename Name of the index file
|
||||
* @param url Subdirectory URL
|
||||
*/
|
||||
static MRepo& create(MPool& pool,
|
||||
const std::string& name,
|
||||
const std::string& filename,
|
||||
const std::string& url);
|
||||
|
||||
/**
|
||||
* Static constructor.
|
||||
* @param pool ``libsolv`` pool wrapper
|
||||
* @param name Name of the subdirectory (<channel>/<subdir>)
|
||||
* @param index Path to the index file
|
||||
* @param meta Metadata of the repo
|
||||
* @param channel Channel of the repo
|
||||
*/
|
||||
static MRepo& create(MPool& pool,
|
||||
const std::string& name,
|
||||
const fs::path& filename,
|
||||
const RepoMetadata& meta,
|
||||
const Channel& channel);
|
||||
|
||||
/**
|
||||
* Static constructor.
|
||||
* @param pool ``libsolv`` pool wrapper
|
||||
* @param prefix_data prefix data
|
||||
*/
|
||||
static MRepo& create(MPool& pool, const PrefixData& prefix_data);
|
||||
|
||||
/**
|
||||
* Static constructor.
|
||||
* @param pool ``libsolv`` pool wrapper
|
||||
* @param name Name
|
||||
* @param uris Matchspecs pointing to unique resources (URL or files)
|
||||
*/
|
||||
static MRepo& create(MPool& pool,
|
||||
const std::string& name,
|
||||
const std::vector<PackageInfo>& uris);
|
||||
|
||||
private:
|
||||
MRepo(MPool& pool,
|
||||
const std::string& name,
|
||||
const std::string& filename,
|
||||
const std::string& url);
|
||||
|
||||
MRepo(MPool& pool,
|
||||
const std::string& name,
|
||||
const fs::path& filename,
|
||||
const RepoMetadata& meta,
|
||||
const Channel& channel);
|
||||
|
||||
MRepo(MPool& pool, const PrefixData& prefix_data);
|
||||
|
||||
MRepo(MPool& pool, const std::string& name, const std::vector<PackageInfo>& uris);
|
||||
|
||||
bool read_file(const fs::path& filename);
|
||||
|
||||
fs::path m_json_file, m_solv_file;
|
||||
|
@ -133,6 +146,7 @@ namespace mamba
|
|||
Repo* m_repo;
|
||||
const Channel* p_channel = nullptr;
|
||||
};
|
||||
|
||||
} // namespace mamba
|
||||
|
||||
#endif // MAMBA_REPO_HPP
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace mamba
|
|||
}
|
||||
prefix_data.load_single_record(repodata_record_json);
|
||||
}
|
||||
return pool.add_repo(MRepo(pool, prefix_data));
|
||||
return MRepo::create(pool, prefix_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -368,7 +368,7 @@ namespace mamba
|
|||
|
||||
prefix_data.add_virtual_packages(get_virtual_packages());
|
||||
|
||||
pool.add_repo(MRepo(pool, prefix_data));
|
||||
MRepo::create(pool, prefix_data);
|
||||
|
||||
MSolver solver(pool,
|
||||
{ { SOLVER_FLAG_ALLOW_UNINSTALL, ctx.allow_uninstall },
|
||||
|
@ -472,7 +472,7 @@ namespace mamba
|
|||
|
||||
prefix_data.load();
|
||||
prefix_data.add_virtual_packages(get_virtual_packages());
|
||||
MRepo(pool, prefix_data);
|
||||
MRepo::create(pool, prefix_data);
|
||||
|
||||
if (ctx.json)
|
||||
transaction.log_json();
|
||||
|
|
|
@ -71,7 +71,7 @@ namespace mamba
|
|||
PrefixData prefix_data(ctx.target_prefix);
|
||||
prefix_data.load();
|
||||
MPool pool;
|
||||
pool.add_repo(MRepo(pool, prefix_data));
|
||||
MRepo::create(pool, prefix_data);
|
||||
|
||||
const fs::path pkgs_dirs(ctx.root_prefix / "pkgs");
|
||||
MultiPackageCache package_caches({ pkgs_dirs });
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace mamba
|
|||
{
|
||||
auto prefix_data = PrefixData(ctx.target_prefix);
|
||||
prefix_data.load();
|
||||
pool.add_repo(MRepo(pool, prefix_data));
|
||||
MRepo::create(pool, prefix_data);
|
||||
Console::stream() << "Loaded current active prefix: " << ctx.target_prefix << std::endl;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace mamba
|
|||
|
||||
prefix_data.add_virtual_packages(get_virtual_packages());
|
||||
|
||||
pool.add_repo(MRepo(pool, prefix_data));
|
||||
MRepo::create(pool, prefix_data);
|
||||
|
||||
MSolver solver(pool,
|
||||
{ { SOLVER_FLAG_ALLOW_DOWNGRADE, ctx.allow_downgrade },
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace mamba
|
|||
|
||||
// TODO check prereq marker to `pip` if it's part of the installed packages
|
||||
// so that it gets installed after Python.
|
||||
auto repo = MRepo(pool, *this);
|
||||
auto& repo = MRepo::create(pool, *this);
|
||||
|
||||
Queue q;
|
||||
queue_init(&q);
|
||||
|
|
|
@ -33,22 +33,14 @@ namespace mamba
|
|||
MRepo::MRepo(MPool& pool,
|
||||
const std::string& name,
|
||||
const fs::path& index,
|
||||
const RepoMetadata& metadata)
|
||||
const RepoMetadata& metadata,
|
||||
const Channel& channel)
|
||||
: m_metadata(metadata)
|
||||
{
|
||||
m_url = rsplit(metadata.url, "/", 1)[0];
|
||||
m_repo = repo_create(pool, m_url.c_str());
|
||||
m_repo->appdata = this;
|
||||
read_file(index);
|
||||
}
|
||||
|
||||
MRepo::MRepo(MPool& pool,
|
||||
const std::string& name,
|
||||
const fs::path& index,
|
||||
const RepoMetadata& metadata,
|
||||
const Channel& channel)
|
||||
: MRepo(pool, name, index, metadata)
|
||||
{
|
||||
p_channel = &channel;
|
||||
}
|
||||
|
||||
|
@ -63,70 +55,6 @@ namespace mamba
|
|||
read_file(index);
|
||||
}
|
||||
|
||||
void MRepo::add_package_info(Repodata* data, const PackageInfo& info)
|
||||
{
|
||||
LOG_INFO << "Adding package record to repo " << info.name;
|
||||
Pool* pool = m_repo->pool;
|
||||
|
||||
static Id real_repo_key = pool_str2id(pool, "solvable:real_repo_url", 1);
|
||||
static Id noarch_repo_key = pool_str2id(pool, "solvable:noarch_type", 1);
|
||||
|
||||
Id handle = repo_add_solvable(m_repo);
|
||||
Solvable* s;
|
||||
s = pool_id2solvable(pool, handle);
|
||||
repodata_set_str(
|
||||
data, handle, SOLVABLE_BUILDVERSION, std::to_string(info.build_number).c_str());
|
||||
repodata_add_poolstr_array(data, handle, SOLVABLE_BUILDFLAVOR, info.build_string.c_str());
|
||||
s->name = pool_str2id(pool, info.name.c_str(), 1);
|
||||
s->evr = pool_str2id(pool, info.version.c_str(), 1);
|
||||
repodata_set_num(data, handle, SOLVABLE_DOWNLOADSIZE, info.size);
|
||||
repodata_set_checksum(data, handle, SOLVABLE_PKGID, REPOKEY_TYPE_MD5, info.md5.c_str());
|
||||
|
||||
solvable_set_str(s, real_repo_key, info.url.c_str());
|
||||
|
||||
if (!info.noarch.empty())
|
||||
solvable_set_str(s, noarch_repo_key, info.noarch.c_str());
|
||||
|
||||
repodata_set_checksum(
|
||||
data, handle, SOLVABLE_CHECKSUM, REPOKEY_TYPE_SHA256, info.sha256.c_str());
|
||||
|
||||
if (strcmp(m_repo->name, "__explicit_specs__") == 0)
|
||||
{
|
||||
repodata_set_location(data, handle, 0, nullptr, info.url.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
repodata_set_location(data, handle, 0, info.subdir.c_str(), info.fn.c_str());
|
||||
}
|
||||
|
||||
if (!info.depends.empty())
|
||||
{
|
||||
for (std::string dep : info.depends)
|
||||
{
|
||||
Id dep_id = pool_conda_matchspec(pool, dep.c_str());
|
||||
if (dep_id)
|
||||
{
|
||||
s->requires = repo_addid_dep(m_repo, s->requires, dep_id, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!info.constrains.empty())
|
||||
{
|
||||
for (std::string cst : info.constrains)
|
||||
{
|
||||
Id constrains_id = pool_conda_matchspec(pool, cst.c_str());
|
||||
if (constrains_id)
|
||||
{
|
||||
repodata_add_idarray(data, handle, SOLVABLE_CONSTRAINS, constrains_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s->provides
|
||||
= repo_addid_dep(m_repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
|
||||
}
|
||||
|
||||
MRepo::MRepo(MPool& pool,
|
||||
const std::string& name,
|
||||
const std::vector<PackageInfo>& package_infos)
|
||||
|
@ -212,6 +140,70 @@ namespace mamba
|
|||
m_repo->subpriority = subpriority;
|
||||
}
|
||||
|
||||
void MRepo::add_package_info(Repodata* data, const PackageInfo& info)
|
||||
{
|
||||
LOG_INFO << "Adding package record to repo " << info.name;
|
||||
Pool* pool = m_repo->pool;
|
||||
|
||||
static Id real_repo_key = pool_str2id(pool, "solvable:real_repo_url", 1);
|
||||
static Id noarch_repo_key = pool_str2id(pool, "solvable:noarch_type", 1);
|
||||
|
||||
Id handle = repo_add_solvable(m_repo);
|
||||
Solvable* s;
|
||||
s = pool_id2solvable(pool, handle);
|
||||
repodata_set_str(
|
||||
data, handle, SOLVABLE_BUILDVERSION, std::to_string(info.build_number).c_str());
|
||||
repodata_add_poolstr_array(data, handle, SOLVABLE_BUILDFLAVOR, info.build_string.c_str());
|
||||
s->name = pool_str2id(pool, info.name.c_str(), 1);
|
||||
s->evr = pool_str2id(pool, info.version.c_str(), 1);
|
||||
repodata_set_num(data, handle, SOLVABLE_DOWNLOADSIZE, info.size);
|
||||
repodata_set_checksum(data, handle, SOLVABLE_PKGID, REPOKEY_TYPE_MD5, info.md5.c_str());
|
||||
|
||||
solvable_set_str(s, real_repo_key, info.url.c_str());
|
||||
|
||||
if (!info.noarch.empty())
|
||||
solvable_set_str(s, noarch_repo_key, info.noarch.c_str());
|
||||
|
||||
repodata_set_checksum(
|
||||
data, handle, SOLVABLE_CHECKSUM, REPOKEY_TYPE_SHA256, info.sha256.c_str());
|
||||
|
||||
if (strcmp(m_repo->name, "__explicit_specs__") == 0)
|
||||
{
|
||||
repodata_set_location(data, handle, 0, nullptr, info.url.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
repodata_set_location(data, handle, 0, info.subdir.c_str(), info.fn.c_str());
|
||||
}
|
||||
|
||||
if (!info.depends.empty())
|
||||
{
|
||||
for (std::string dep : info.depends)
|
||||
{
|
||||
Id dep_id = pool_conda_matchspec(pool, dep.c_str());
|
||||
if (dep_id)
|
||||
{
|
||||
s->requires = repo_addid_dep(m_repo, s->requires, dep_id, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!info.constrains.empty())
|
||||
{
|
||||
for (std::string cst : info.constrains)
|
||||
{
|
||||
Id constrains_id = pool_conda_matchspec(pool, cst.c_str());
|
||||
if (constrains_id)
|
||||
{
|
||||
repodata_add_idarray(data, handle, SOLVABLE_CONSTRAINS, constrains_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s->provides
|
||||
= repo_addid_dep(m_repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
|
||||
}
|
||||
|
||||
std::string MRepo::name() const
|
||||
{
|
||||
return m_repo->name ? m_repo->name : "";
|
||||
|
@ -274,6 +266,33 @@ namespace mamba
|
|||
}
|
||||
}
|
||||
|
||||
MRepo& MRepo::create(MPool& pool,
|
||||
const std::string& name,
|
||||
const std::string& filename,
|
||||
const std::string& url)
|
||||
{
|
||||
return pool.add_repo(MRepo(pool, name, filename, url));
|
||||
}
|
||||
|
||||
MRepo& MRepo::create(MPool& pool,
|
||||
const std::string& name,
|
||||
const fs::path& filename,
|
||||
const RepoMetadata& meta,
|
||||
const Channel& channel)
|
||||
{
|
||||
return pool.add_repo(MRepo(pool, name, filename, meta, channel));
|
||||
}
|
||||
|
||||
MRepo& MRepo::create(MPool& pool, const PrefixData& prefix_data)
|
||||
{
|
||||
return pool.add_repo(MRepo(pool, prefix_data));
|
||||
}
|
||||
|
||||
MRepo& MRepo::create(MPool& pool, const std::string& name, const std::vector<PackageInfo>& uris)
|
||||
{
|
||||
return pool.add_repo(MRepo(pool, name, uris));
|
||||
}
|
||||
|
||||
bool MRepo::read_file(const fs::path& filename)
|
||||
{
|
||||
bool is_solv = filename.extension() == ".solv";
|
||||
|
|
|
@ -593,7 +593,7 @@ namespace mamba
|
|||
m_mod_etag.value("_etag", ""),
|
||||
m_mod_etag.value("_mod", "") };
|
||||
|
||||
return pool.add_repo(MRepo(pool, m_name, cache_path(), meta, *p_channel));
|
||||
return MRepo::create(pool, m_name, cache_path(), meta, *p_channel);
|
||||
}
|
||||
|
||||
void MSubdirData::clear_cache()
|
||||
|
|
|
@ -445,7 +445,7 @@ namespace mamba
|
|||
pi_result.push_back(p);
|
||||
}
|
||||
|
||||
MRepo mrepo(pool, "__explicit_specs__", pi_result);
|
||||
MRepo& mrepo = MRepo::create(pool, "__explicit_specs__", pi_result);
|
||||
|
||||
pool.create_whatprovides();
|
||||
|
||||
|
|
|
@ -71,9 +71,17 @@ PYBIND11_MODULE(bindings, m)
|
|||
.def("get_tarball_path", &MultiPackageCache::get_tarball_path)
|
||||
.def_property_readonly("first_writable_path", &MultiPackageCache::first_writable_path);
|
||||
|
||||
py::class_<MRepo>(m, "Repo")
|
||||
.def(py::init<MPool&, const std::string&, const std::string&, const std::string&>())
|
||||
.def(py::init<MPool&, const PrefixData&>())
|
||||
py::class_<MRepo, std::unique_ptr<MRepo, py::nodelete>>(m, "Repo")
|
||||
.def(py::init(
|
||||
[](MPool& pool,
|
||||
const std::string& name,
|
||||
const std::string& filename,
|
||||
const std::string& url) {
|
||||
return std::unique_ptr<MRepo, py::nodelete>(
|
||||
&MRepo::create(pool, name, filename, url));
|
||||
}))
|
||||
.def(py::init([](MPool& pool, const PrefixData& data)
|
||||
{ return std::unique_ptr<MRepo, py::nodelete>(&MRepo::create(pool, data)); }))
|
||||
.def("add_python_noarch_info",
|
||||
[](const MRepo& self, const std::vector<std::string>& names)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue