From 9733790c2096ea6a8cb0d3da08f6b11fb4ed9bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= Date: Mon, 27 Jan 2025 10:10:11 +0100 Subject: [PATCH] Add runtime warning to `stderr` when calling deprecated API --- common/utils/deprecate.hpp | 30 ++++++++++++++++++++++++++++++ libdnf5/conf/config_main.cpp | 7 +++++++ libdnf5/repo/config_repo.cpp | 3 +++ libdnf5/repo/repo_sack.cpp | 2 ++ 4 files changed, 42 insertions(+) create mode 100644 common/utils/deprecate.hpp diff --git a/common/utils/deprecate.hpp b/common/utils/deprecate.hpp new file mode 100644 index 00000000..6f2dbec1 --- /dev/null +++ b/common/utils/deprecate.hpp @@ -0,0 +1,30 @@ +/* +Copyright Contributors to the libdnf project. + +This file is part of libdnf: https://github.com/rpm-software-management/libdnf/ + +Libdnf is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2.1 of the License, or +(at your option) any later version. + +Libdnf is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with libdnf. If not, see . +*/ + +#ifndef LIBDNF5_UTILS_DEPRACATE_HPP +#define LIBDNF5_UTILS_DEPRACATE_HPP + +#include + +#define LIBDNF5_DEPRECATED(msg) \ + { \ + std::cerr << __PRETTY_FUNCTION__ << " is deprecated: " << msg << std::endl; \ + } + +#endif // LIBDNF5_UTILS_DEPRACATE_HPP diff --git a/libdnf5/conf/config_main.cpp b/libdnf5/conf/config_main.cpp index 5a438e13..302bde6a 100644 --- a/libdnf5/conf/config_main.cpp +++ b/libdnf5/conf/config_main.cpp @@ -21,6 +21,7 @@ along with libdnf. If not, see . #include "config.h" #include "config_utils.hpp" +#include "utils/deprecate.hpp" #include "utils/system.hpp" #include "libdnf5/common/xdg.hpp" @@ -475,9 +476,11 @@ const OptionNumber & ConfigMain::get_debuglevel_option() const { } OptionNumber & ConfigMain::get_errorlevel_option() { + LIBDNF5_DEPRECATED("The option does nothing"); return p_impl->errorlevel; } const OptionNumber & ConfigMain::get_errorlevel_option() const { + LIBDNF5_DEPRECATED("The option does nothing"); return p_impl->errorlevel; } @@ -912,9 +915,11 @@ const OptionString & ConfigMain::get_rpmverbosity_option() const { } OptionBool & ConfigMain::get_strict_option() { + LIBDNF5_DEPRECATED("Use get_skip_broken_option() and get_skip_unavailable_option()"); return p_impl->strict; } const OptionBool & ConfigMain::get_strict_option() const { + LIBDNF5_DEPRECATED("Use get_skip_broken_option() const and get_skip_unavailable_option() const"); return p_impl->strict; } @@ -1142,9 +1147,11 @@ const OptionString & ConfigMain::get_password_option() const { } OptionBool & ConfigMain::get_gpgcheck_option() { + LIBDNF5_DEPRECATED("Use get_pkg_gpgcheck_option()"); return p_impl->pkg_gpgcheck; } const OptionBool & ConfigMain::get_gpgcheck_option() const { + LIBDNF5_DEPRECATED("Use get_pkg_gpgcheck_option() const"); return p_impl->pkg_gpgcheck; } diff --git a/libdnf5/repo/config_repo.cpp b/libdnf5/repo/config_repo.cpp index a2c57c74..23c9a892 100644 --- a/libdnf5/repo/config_repo.cpp +++ b/libdnf5/repo/config_repo.cpp @@ -20,6 +20,7 @@ along with libdnf. If not, see . #include "libdnf5/repo/config_repo.hpp" #include "conf/config_utils.hpp" +#include "utils/deprecate.hpp" #include "libdnf5/conf/const.hpp" #include "libdnf5/utils/bgettext/bgettext-mark-domain.h" @@ -324,9 +325,11 @@ const OptionChild & ConfigRepo::get_protected_packages_o } OptionChild & ConfigRepo::get_gpgcheck_option() { + LIBDNF5_DEPRECATED("Use get_pkg_gpgcheck_option()"); return p_impl->pkg_gpgcheck; } const OptionChild & ConfigRepo::get_gpgcheck_option() const { + LIBDNF5_DEPRECATED("Use get_pkg_gpgcheck_option() const"); return p_impl->pkg_gpgcheck; } diff --git a/libdnf5/repo/repo_sack.cpp b/libdnf5/repo/repo_sack.cpp index 5d09408b..a504032b 100644 --- a/libdnf5/repo/repo_sack.cpp +++ b/libdnf5/repo/repo_sack.cpp @@ -31,6 +31,7 @@ along with libdnf. If not, see . #include "solv/solver.hpp" #include "solv_repo.hpp" #include "utils/auth.hpp" +#include "utils/deprecate.hpp" #include "utils/fs/utils.hpp" #include "utils/on_scope_exit.hpp" #include "utils/string.hpp" @@ -607,6 +608,7 @@ void RepoSack::Impl::update_and_load_repos(libdnf5::repo::RepoQuery & repos, boo void RepoSack::update_and_load_enabled_repos(bool load_system) { + LIBDNF5_DEPRECATED("Use load_repos() which allows specifying repo type."); if (load_system) { load_repos(); } else {