%global libsolv_version 0.7.21
%global libmodulemd_version 2.13.0
%global librepo_version 1.13.1
%global dnf_conflict 4.11.0
%global swig_version 3.0.12

%global requires_python3_sphinx python3-sphinx

%bcond_with valgrind
%bcond_with rhsm
%bcond_with zchunk
%bcond_with sanitizers


%global _cmake_opts \\\
    -DENABLE_RHSM_SUPPORT=%{?with_rhsm:ON}%{!?with_rhsm:OFF} \\\
    %{nil}

Name:                      libdnf
Version:                   0.70.2
Release:                   5
Summary:                   Library providing simplified C and Python API to libsolv
License:                   LGPL-2.1-or-later
URL:                       https://github.com/rpm-software-management/libdnf
Source0:                   %{url}/archive/%{version}/%{name}-%{version}.tar.gz                    

BuildRequires:             cmake gcc gcc-c++ libsolv-devel >= %{libsolv_version} gettext
BuildRequires:             pkgconfig(librepo) >= %{librepo_version} pkgconfig(check)              
BuildRequires:             pkgconfig(gio-unix-2.0) >= 2.46.0 pkgconfig(gtk-doc) gpgme-devel
BuildRequires:             rpm-devel >= 4.15.0 pkgconfig(sqlite3) pkgconfig(smartcols)
BuildRequires:             pkgconfig(json-c) pkgconfig(cppunit) pkgconfig(libcrypto)
BuildRequires:             pkgconfig(modulemd-2.0) >= %{libmodulemd_version} 

Requires:                  libmodulemd >= %{libmodulemd_version}
Requires:                  libsolv >= %{libsolv_version}
Requires:                  librepo >= %{librepo_version}

Obsoletes:                 python2-%{name} < %{version}-%{release}
Obsoletes:                 python2-hawkey < %{version}-%{release}
Obsoletes:                 python2-hawkey-debuginfo < %{version}-%{release}
Obsoletes:                 python2-libdnf-debuginfo < %{version}-%{release}

%ifarch loongarch64
Patch6001:                 0001-libdnf-0.65.0-add-loongarch-support.patch 
%endif

Patch6002:                 backport-python-bindings-Load-all-modules-with-RTLD_GLOBAL.patch
Patch6003:                 backport-Avoid-reinstalling-installonly-packages-marked-for-ERASE.patch
Patch6004:                 backport-dnf-repo-do-not-download-repository-if-our-local-cache-is-up-to-date.patch
Patch6005:                 backport-dnf-repo-Fix-utimes-error-messages.patch
Patch6006:                 backport-subject-py-Fix-memory-leak.patch 
Patch6007:                 backport-MergedTransaction-Calculate-RPM-difference-between-two-same-versions-as-no-op.patch
Patch6008:                 backport-MergedTransaction-Fix-invalid-memory-access-when-dropping.patch
Patch6009:                 backport-Fix-countme-bucket-calculation.patch
Patch6010:                 backport-Fix-up-some-comments-in-addCountmeFlag.patch

%description
A Library providing simplified C and Python API to libsolv.

%package devel
Summary:                   Development files for %{name}
Requires:                  %{name} = %{version}-%{release}
Requires:                  libsolv-devel >= %{libsolv_version}

%description devel
Development files for %{name}.

%package -n                python3-%{name}
%{?python_provide:%python_provide python3-%{name}}
Summary:                   Python 3 bindings for the libdnf library.
Requires:                  %{name} = %{version}-%{release}
BuildRequires:             python3-devel %{requires_python3_sphinx} swig >= %{swig_version}

%description -n python3-%{name}
Python 3 bindings for the libdnf library.

%package -n                python3-hawkey
Summary:                   Python 3 bindings for the hawkey library
%{?python_provide:%python_provide python3-hawkey}
BuildRequires:             python3-devel
Requires:                  %{name} = %{version}-%{release}
Requires:                  python3-%{name} = %{version}-%{release}
Conflicts:                 python3-dnf < %{dnf_conflict}
Obsoletes:                 platform-python-hawkey < %{version}-%{release}

%description -n python3-hawkey
Python 3 bindings for the hawkey library.

%prep
%autosetup -p1
mkdir build-py3

%build
pushd build-py3
  %cmake -DPYTHON_DESIRED:FILEPATH=%{__python3} -DWITH_GIR=0 -DWITH_MAN=0 -Dgtkdoc=0 ../ %{!?with_zchunk:-DWITH_ZCHUNK=OFF} %{!?with_valgrind:-DDISABLE_VALGRIND=1} %{_cmake_opts} \
  -DWITH_SANITIZERS=%{?with_sanitizers:ON}%{!?with_sanitizers:OFF}
  %make_build
popd

%check
pushd build-py3
  make ARGS="-V" test
popd

%install
pushd build-py3
  %make_install
popd

%find_lang %{name}

%ldconfig_scriptlets

%files -f %{name}.lang 
%license COPYING
%doc README.md AUTHORS
%{_libdir}/%{name}.so.*
%dir %{_libdir}/libdnf/
%dir %{_libdir}/libdnf/plugins/
%{_libdir}/libdnf/plugins/README

%files devel
%doc %{_datadir}/gtk-doc/html/%{name}/
%{_libdir}/%{name}.so
%{_libdir}/pkgconfig/%{name}.pc
%{_includedir}/%{name}/

%files -n python3-%{name}
%{python3_sitearch}/%{name}/

%files -n python3-hawkey
%{python3_sitearch}/hawkey/

%changelog
* Tue Jul 02 2024 wangziliang <wangziliang@kylinos.cn> - 0.70.2-5
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC: Fix countme bucket calculation

* Fri Jun 14 2024 hanhuihui <hanhuihui5@huawei.com> - 0.70.2-4
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:Fix history rollback cmd not meet the expectation

* Thu May 16 2024 xiaozai <xiaozai@kylinos.cn> - 0.70.2-3
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC: Fix memory leak detected in get_best_solution() method 

* Tue Jan 02 2024 chenhaixing <chenhaixing@huawei.com> - 0.70.2-2
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:libdnf:Avoid reinstalling installonly packages marked for ERASE
              Fix utimes error message in dnf-repo
              Do not download repository if our local cache is up to date in dnf-repo
              python bindings:Load all modules with RTLD_GLOBAL

* Sat Jul 29 2023 zhangrui <zhangrui182@huawei.com> - 0.70.2-1
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:upgrade to 0.70.2

* Tue Jun 27 2023 chenhaixing <chenhaixing@huawei.com> - 0.69.0-5
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:libdnf:fix libdnf no downgrade when downgrade dnf

* Fri Apr 21 2023 zhangrui <zhangrui182@huawei.com> - 0.69.0-4
- DESC:add check after malloc allocation

* Thu Jan 5 2023 zhangrui <zhangrui182@huawei.com> - 0.69.0-3
- DESC:add loongarch

* Fri Dec 9 2022 zhangrui <zhangrui182@huawei.com> - 0.69.0-2
- DESC:backport patch to ensure reldep is from the same sack

* Sat Nov 5 2022 zhangrui <zhangrui182@huawei.com> - 0.69.0-1
- DES:Update libdnf to 0.69.0

* Tue Sep 20 2022 zhangrui <zhangrui182@huawei.com> - 0.65.0-3
- DESC:backport patches fix listing a repository without cpeid

* Tue Dec 28 2021 hanhui <hanhui15@huawei.com> - 0.65.0-2
- DESC:fix libdnf upgrade failed

* Sat Dec 25 2021 hanhui <hanhui15@huawei.com> - 0.65.0-1
- DESC:upgrade to libdnf-0.65.0

* Thu Jul 15 2021 gaihuiying <gaihuiying1@huawei.com> - 0.48.0-3
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:dnf and libdnf upgrade downgrade together

* Tue Jun 8 2021 seuzw <930zhaowei@163.com> - 0.48.0-2
- Type:CVE
- ID:CVE-2021-3445
- SUG:NA
- DESC:fix CVE-2021-3445

* Tue Apr 28 2020 zhouyihang <zhouyihang3@huawei.com> - 0.48.0-1
- Type:requirement
- ID:NA
- SUG:NA
- DESC:update libdnf version to 0.48.0

* Tue Jan 7 2020 openEuler Buildteam <buildteam@openeuler.org> - 0.37.2-2 
- Package init.
