From 5127ca351f9cde23a01f563c2c11e346cc90a0c0 Mon Sep 17 00:00:00 2001 From: Martchus Date: Mon, 8 Feb 2021 23:19:52 +0100 Subject: [PATCH] Allow ignoring certain dependencies/libraries when checking for problems --- libpkg/data/database.cpp | 32 +++++++++++++++------ libpkg/data/database.h | 6 ++-- librepomgr/buildactions/buildactionmeta.cpp | 13 ++++++++- librepomgr/buildactions/buildactionmeta.h | 1 + librepomgr/buildactions/repomanagement.cpp | 14 +++++++-- 5 files changed, 52 insertions(+), 14 deletions(-) diff --git a/libpkg/data/database.cpp b/libpkg/data/database.cpp index 2295daa..eb9e9ca 100644 --- a/libpkg/data/database.cpp +++ b/libpkg/data/database.cpp @@ -191,14 +191,18 @@ void Database::replacePackages(const std::vector> &newP } /*! - * \brief Determines which packages are unresolvable. + * \brief Determines which packages are unresolvable assuming new packages are added to the database and certain provides are removed. * \param config The configuration supposed to contain database dependencies. - * \param newPackages Packages which should be added to the database. - * \param removedProvides Provides which will be removed from the database. - * \remarks "Resolvable" means here (so far) just that all dependencies are present. It does not mean "installable". + * \param newPackages Packages which are assumed to be added to the database. + * \param removedProvides Provides which are assumed to be removed from the database. + * \param depsToIgnore Specifies dependencies to be ignored if missing (version constraints not supported). + * \param libsToIgnore Specifies libraries to be ignored if missing. + * \remarks "Resolvable" means here (so far) just that all dependencies are present. It does not mean a package is "installable" because + * conflicts between dependencies might still prevent that. */ -std::unordered_map, UnresolvedDependencies> Database::detectUnresolvedPackages( - Config &config, const std::vector> &newPackages, const DependencySet &removedProvides) +std::unordered_map, UnresolvedDependencies> Database::detectUnresolvedPackages(Config &config, + const std::vector> &newPackages, const DependencySet &removedProvides, + const std::unordered_set &depsToIgnore, const std::unordered_set &libsToIgnore) { std::unordered_map, UnresolvedDependencies> unresolvedPackages; @@ -220,6 +224,11 @@ std::unordered_map, UnresolvedDependencies> Database::d const auto &[dependencyName, dependencyDetail] = requiredDep; const auto &affectedPackages = dependencyDetail.relevantPackages; + // skip dependencies to ignore + if (depsToIgnore.find(dependencyName) != depsToIgnore.end()) { + continue; + } + // skip if new packages provide dependency if (newProvides.provides(dependencyName, dependencyDetail)) { continue; @@ -263,20 +272,25 @@ std::unordered_map, UnresolvedDependencies> Database::d // check whether all required libraries are still provided for (const auto &[requiredLib, affectedPackages] : requiredLibs) { + // skip libs to ignore + if (libsToIgnore.find(requiredLib) != libsToIgnore.end()) { + continue; + } + // skip if new packages provide dependency - if (newLibProvides.count(requiredLib)) { + if (newLibProvides.find(requiredLib) != newLibProvides.end()) { continue; } // skip if db provides dependency - if (providedLibs.count(requiredLib)) { + if (providedLibs.find(requiredLib) != providedLibs.end()) { continue; } // skip if dependency is provided by a database this database depends on const auto checkDb = [this, &config, &requiredLib = requiredLib](const std::string &dbName) { if (const auto *const db = config.findDatabase(dbName, arch)) { - if (db->providedLibs.count(requiredLib)) { + if (db->providedLibs.find(requiredLib) != db->providedLibs.end()) { return true; } } diff --git a/libpkg/data/database.h b/libpkg/data/database.h index 1c255f8..9a5424c 100644 --- a/libpkg/data/database.h +++ b/libpkg/data/database.h @@ -113,8 +113,10 @@ struct LIBPKG_EXPORT Database : public ReflectiveRapidJSON::JsonSerializable &package); void forceUpdatePackage(const std::shared_ptr &package); void replacePackages(const std::vector> &newPackages, CppUtilities::DateTime lastModified); - std::unordered_map, UnresolvedDependencies> detectUnresolvedPackages( - Config &config, const std::vector> &newPackages, const DependencySet &removedPackages); + std::unordered_map, UnresolvedDependencies> detectUnresolvedPackages(Config &config, + const std::vector> &newPackages, const DependencySet &removedPackages, + const std::unordered_set &depsToIgnore = std::unordered_set(), + const std::unordered_set &libsToIgnore = std::unordered_set()); PackageUpdates checkForUpdates(const std::vector &updateSources, UpdateCheckOptions options = UpdateCheckOptions::None); PackageLocation locatePackage(const std::string &packageName) const; std::string filesPathFromRegularPath() const; diff --git a/librepomgr/buildactions/buildactionmeta.cpp b/librepomgr/buildactions/buildactionmeta.cpp index eb7ec07..eb4f850 100644 --- a/librepomgr/buildactions/buildactionmeta.cpp +++ b/librepomgr/buildactions/buildactionmeta.cpp @@ -246,7 +246,18 @@ BuildActionMetaInfo::BuildActionMetaInfo() .name = "Check for problems", .type = "check-for-problems", .flags = {}, - .settings = {}, + .settings = { + BuildActionSettingMetaInfo{ + .name = "Dependencies to ignore", + .desc = "A white-space separated list of dependencies not to care about if missing (version constraints not supported)", + .param = "ignore-optdepts", + }, + BuildActionSettingMetaInfo{ + .name = "Libraries to ignore", + .desc = "A white-space separated list of library dependencies not to care about if missing", + .param = "ignore-libdeps", + }, + }, .directory = true, .sourceDb = false, .destinationDb = true, diff --git a/librepomgr/buildactions/buildactionmeta.h b/librepomgr/buildactions/buildactionmeta.h index a35f437..2b165f9 100644 --- a/librepomgr/buildactions/buildactionmeta.h +++ b/librepomgr/buildactions/buildactionmeta.h @@ -78,6 +78,7 @@ enum class CleanRepositoryFlags : BuildActionFlagType { None, DryRun = (1 << 0), }; +enum class CheckForProblemsSettings : std::size_t { IgnoreDeps, IgnoreLibDeps }; enum class PrepareBuildSettings : std::size_t { PKGBUILDsDirs }; enum class ConductBuildSettings : std::size_t { ChrootDir, ChrootDefaultUser, CCacheDir, PackageCacheDir, TestFilesDir }; enum class CustomCommandSettings : std::size_t { Command }; diff --git a/librepomgr/buildactions/repomanagement.cpp b/librepomgr/buildactions/repomanagement.cpp index feb1297..739136e 100644 --- a/librepomgr/buildactions/repomanagement.cpp +++ b/librepomgr/buildactions/repomanagement.cpp @@ -378,6 +378,16 @@ CheckForProblems::CheckForProblems(ServiceSetup &setup, const std::shared_ptr(CheckForProblemsSettings::IgnoreDeps)].param; + const auto ignoreLibDepsSetting = typeInfo.settings[static_cast(CheckForProblemsSettings::IgnoreLibDeps)].param; + metaInfoLock.unlock(); + const auto ignoreDeps = splitStringSimple>(std::string_view(findSetting(ignoreDepsSetting)), " "); + const auto ignoreLibDeps = splitStringSimple>(std::string_view(findSetting(ignoreLibDepsSetting)), " "); + // initialize build action auto configReadLock = init(BuildActionAccess::ReadConfig, RequiredDatabases::OneOrMoreDestinations, RequiredParameters::None); if (std::holds_alternative(configReadLock)) { @@ -419,8 +429,8 @@ void CheckForProblems::run() } // check for unresolved dependencies and missing libraries checkForUnresolvedPackages: - auto unresolvedPackages - = db->detectUnresolvedPackages(m_setup.config, std::vector>(), LibPkg::DependencySet()); + auto unresolvedPackages = db->detectUnresolvedPackages( + m_setup.config, std::vector>(), LibPkg::DependencySet(), ignoreDeps, ignoreLibDeps); for (auto &[package, unresolvedDeps] : unresolvedPackages) { problems.emplace_back(RepositoryProblem{ .desc = std::move(unresolvedDeps), .pkg = package->name }); }