# Created by pyp2rpm-3.3.5
%if 0%{?rhel}
%bcond_with docs
%else
%bcond_without docs
%endif
%bcond_without tests

%global pypi_name drgn

%global _description %{expand:
drgn (pronounced "dragon") is a debugger with an emphasis on programmability.
drgn exposes the types and variables in a program for easy, expressive
scripting in Python.}

Name:           python-%{pypi_name}
Version:        0.0.29+39.gfb6c32cf
Release:        1.20241122191831971212.main.39.gfb6c32cf%{?dist}
Summary:        Programmable debugger

License:        LGPL-2.1-or-later
URL:            https://github.com/osandov/drgn
Source0:        drgn-0.0.29+39.gfb6c32cf.tar.gz

BuildRequires:  python3-devel
BuildRequires:  python3dist(setuptools)
%if %{with docs}
BuildRequires:  sed
BuildRequires:  python3dist(sphinx)
BuildRequires:  python3-docs
%endif
%if %{with tests}
BuildRequires:  python3dist(pytest)
%endif
BuildRequires:  gcc-c++
BuildRequires:  make
BuildRequires:  bzip2-devel
BuildRequires:  elfutils-devel
BuildRequires:  libkdumpfile-devel
BuildRequires:  zlib-devel
BuildRequires:  xz-devel
# These are needed when building from git snapshots
BuildRequires:  autoconf
BuildRequires:  automake
BuildRequires:  libtool

%description %{_description}

%package -n     %{pypi_name}
Summary:        %{summary}

%description -n %{pypi_name} %{_description}

%if %{with docs}
%package -n %{pypi_name}-doc
Summary:        %{pypi_name} documentation
BuildArch:      noarch
Requires:       python3-docs

%description -n %{pypi_name}-doc %{_description}

This package contains additional documentation for %{pypi_name}.
%endif

%prep
%autosetup -n drgn-0.0.29+39.gfb6c32cf -p1
# Remove bundled egg-info
rm -rf %{pypi_name}.egg-info
%if %{with docs}
# Use local intersphinx inventory
sed -r \
    -e 's|https://docs.python.org/3|%{_docdir}/python3-docs/html|' \
    -i docs/conf.py
%endif
# Ensure version is always set, even when building from git snapshots
if [ ! -f drgn/internal/version.py ]; then
  echo '__version__ = "%{version}"' > drgn/internal/version.py
fi

%build
# verbose build
V=1 %py3_build

%if %{with docs}
# generate html docs
PYTHONPATH=${PWD} sphinx-build-3 docs html
# remove the sphinx-build leftovers
rm -rf html/.{doctrees,buildinfo}
%endif

%install
%py3_install
mkdir -p %{buildroot}%{_datadir}/drgn
cp -PR contrib tools %{buildroot}%{_datadir}/drgn

%if %{with tests}
%check
%pytest
%endif

%files -n %{pypi_name}
%license COPYING
%license LICENSES
%doc README.rst
%{_bindir}/drgn
%{_datadir}/drgn
%{python3_sitearch}/_%{pypi_name}.pyi
%{python3_sitearch}/_%{pypi_name}.cpython*.so
%{python3_sitearch}/%{pypi_name}
%{python3_sitearch}/_%{pypi_name}_util
%{python3_sitearch}/%{pypi_name}-%{version}-py%{python3_version}.egg-info

%if %{with docs}
%files -n %{pypi_name}-doc
%license COPYING
%license LICENSES
%doc html
%endif

%changelog
* Fri Nov 22 2024 Packit <hello@packit.dev> - 0.0.29+39.gfb6c32cf-1.20241122191831971212.main.39.gfb6c32cf
- contrib/cgroup.py: fix bpf subcommand on Linux >= 5.15 (Omar Sandoval)
- contrib/cgroup: Print counts of subsys state structs (Michal Koutný)
- contrib/cgroup: Rework for generic argument parsing (Michal Koutný)
- helpers/cgroup: Iterate offlined css objects too (Michal Koutný)
- libdrgn: orc_info: prefer ORC stack switching entries over DWARF CFI (Omar Sandoval)
- libdrgn: orc_info: stop pretending ORC support isn't x86-64-specific (Omar Sandoval)
- libdrgn: orc_info: refactor remove_fdes_from_orc() (Omar Sandoval)
- libdrgn: orc_info: use _cleanup_ in drgn_debug_info_parse_orc() (Omar Sandoval)
- libdrgn: elf_file: fail read_elf_section() for SHT_NOBITS sections (Omar Sandoval)
- libdrgn: linux_kernel: cache value of MOD_TEXT (Omar Sandoval)
- python: fix double decref in init_type_kind_set() (Omar Sandoval)
- drgndoc: handle removal of deprecated ast nodes in Python 3.14 (Omar Sandoval)
- libdrgn: program: improve checks for userspace programs (Omar Sandoval)
- libdrgn: program: reorganize userspace-/Linux kernel-specific parts of struct drgn_program (Omar Sandoval)
- libdrgn: rename cache_core_dump_notes -> cache_core_dump_threads (Omar Sandoval)
- contrib/bpf_inspect.py: fix BpfProg repr (Ze Gao)
- tests: move jiffies object finder test case to test_special_objects.py (Omar Sandoval)
- python: use _cleanup_ in Program_load_debug_info() (Omar Sandoval)
- python: add automatic cleanup macro for path_arg (Omar Sandoval)
- libdrgn: python: allow nesting blocking callbacks (Omar Sandoval)
- vmtest.kbuild: add patch to fix 9p slab cache naming on Linux 6.12 (Omar Sandoval)
- vmtest.config: skip RAID 6 algorithm benchmarking (Omar Sandoval)
- contrib: ptdrgn: remove copied run_interactive() (Stephen Brennan)
- cli: Add support for Python 3.13 enhanced REPL (Stephen Brennan)
- kallsyms: remove docstring of _module_kallsyms() (Stephen Brennan)
- libdrgn: add lifetime to drgn_symbol, reduce copying (Stephen Brennan)
- helpers: linux: add module kallsyms helpers (Stephen Brennan)
- helpers: linux: add vmlinux kallsyms helpers (Stephen Brennan)
- libdrgn, python: add SymbolIndex (Stephen Brennan)
- python: Add helper for returning list of Symbols (Stephen Brennan)
- libdrgn: util: add qsort_arg() helper function (Stephen Brennan)
- README: sort libkdumpfile alphabetically in Arch instructions (Omar Sandoval)
- docs: Add instructions for debuginfo on Oracle Linux (Stephen Brennan)
- README: include Oracle Linux instructions (Stephen Brennan)
- README: libkdumpfile is now also packaged in arch (Stephen Brennan)
- cli: catch FaultError when displaying objects (Omar Sandoval)
- contrib: ptdrgn: fix FaultError when displaying objects (Stephen Brennan)
- README.rst: the Arch Package was moved to [extra] (Christian Heusel)
- packit: drop _drgn_util patch for RPM spec (Omar Sandoval)