# 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.30+63.g73ea07ad
Release:        1.20250307211531702246.pr476.63.g73ea07ad%{?dist}
Summary:        Programmable debugger

License:        LGPL-2.1-or-later
URL:            https://github.com/osandov/drgn
Source0:        drgn-0.0.30+63.g73ea07ad.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.30+63.g73ea07ad -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 Mar 07 2025 Packit <hello@packit.dev> - 0.0.30+63.g73ea07ad-1.20250307211531702246.pr476.63.g73ea07ad
- Fix exception handling in for_each_child_dentry (Nils K)
- tests: linux_kernel: test built-in ORC unwinding (Stephen Brennan)
- orc_info: use a constant for size of the ORC version header (Stephen Brennan)
- orc_info: store biased pc_base (Stephen Brennan)
- orc_info: enable the use of built-in ORC (Stephen Brennan)
- module: add object (Stephen Brennan)
- libdrgn: python: add Module_prog (Stephen Brennan)
- orc_info: don't use ELF_Data when processing orc header (Stephen Brennan)
- tests: remove leftover debugging code in symbols test (Omar Sandoval)
- tests: don't run TC tests with old pyroute2 (Omar Sandoval)
- libdrgn: dwarf_info: fix DWARF index error handling (Omar Sandoval)
- tests: skip slow test_mtree_load_three_levels* tests under emulation (Omar Sandoval)
- libdrgn: dwarf_info: use uintptr_t for DIE addresses in DWARF index (Omar Sandoval)
- drgn.helpers.experimental.kmodify: sign-extend <32-bit arguments (Omar Sandoval)
- drgn.helpers.experimental.kmodify: apply conversions to literal arguments (Omar Sandoval)
- libdrgn: dwarf_info: add bias to DW_OP_addr in the middle of an expression (Omar Sandoval)
- README: exclude unsupported repositories from Repology badge (Omar Sandoval)
- docs: add video to blk-rq-qos crash tutorial (Omar Sandoval)
- docs: add a hands-on tutorial for a blk-rq-qos crash (Omar Sandoval)
- Add 6.14 to supported kernels (Omar Sandoval)
- Add plugin system (Omar Sandoval)
- libdrgn: replace blocking callbacks with hard-coded functions (Omar Sandoval)
- libdrgn: always make drgn_program available to Python (Omar Sandoval)
- libdrgn: combine libdrgn and _drgn Python extension into one .so (Omar Sandoval)
- libdrgn: linux_kernel: handle module section/note changes in Linux 6.14 (Omar Sandoval)
- Build manylinux wheels with debuginfod support (Omar Sandoval)
- Support searching for kernel modules without depmod metadata (Omar Sandoval)
- libdrgn: debug_info: clean up drgn_module_standard_files_state (Omar Sandoval)
- Add a debug info option for kernel directories (Omar Sandoval)
- Add debug info options for disabling search methods (Omar Sandoval)
- Add Program.find_standard_debug_info() (Omar Sandoval)
- Replace debug_info_path with debug_info_options (Omar Sandoval)
- libdrgn/python: factor path sequence argument parsing out of Program_load_debug_info() (Omar Sandoval)
- libdrgn: hash_table: add hash_table_for_each() (Omar Sandoval)
- libdrgn: debug_info: match vmlinux by version if build ID is not available (Omar Sandoval)
- libdrgn: add VECTOR and HASH_TABLE scope guards (Omar Sandoval)
- libdrgn/python: fix segfault on del prog.language and more (Omar Sandoval)
- libdrgn/python: remove dead misspelled ifdef block (Omar Sandoval)
- libdrgn: stack_trace: give hint when stack_trace(0) fails (Omar Sandoval)
- contrib/stack_trace_call_fault.py: support AArch64 (Omar Sandoval)
- libdrgn: aarch64: implement bad call unwinding (Omar Sandoval)
- libdrgn: register_state: add drgn_register_state_unset_has_register() (Omar Sandoval)
- libdrgn: stack_trace: make bad call unwinding an architecture callback (Omar Sandoval)
- libdrgn/python: unexport set_drgn_error() (Omar Sandoval)
- docs: use envvar directive for environment variables (Omar Sandoval)
- Make StackFrame.name fall back to symbol/PC and add StackFrame.function_name (Omar Sandoval)
- libdrgn: kdump: prepare for incompatible changes in libkdumpfile-0.5.5 (Petr Tesarik)
- libdrgn: kdump: simplify getting the PRSTATUS attributes (Petr Tesarik)
- Update Ubuntu instructions (Michel Lind)
- tests: drop leftover debugging print (Omar Sandoval)
- libdrgn: don't bother getting program language to initialize object (Omar Sandoval)
- tests: don't clobber file in use by libelf (Omar Sandoval)
- Introduce module and debug info finder APIs (Omar Sandoval)
- libdrgn: add API for choosing file to write progress bars to (Omar Sandoval)
- libdrgn: debug_info: add debuginfod client scaffolding (Omar Sandoval)
- libdrgn: linux_kernel: move depmod index code (Omar Sandoval)
- libdrgn: linux_kernel: parse build ID in VMCOREINFO (Omar Sandoval)
- libdrgn: binary_search_tree: add delete_entry (Omar Sandoval)
- libdrgn: add functions for deserializing 64- or 32-bit structures (Omar Sandoval)
- libdrgn: add hexadecimal encoding/decoding functions (Omar Sandoval)
- libdrgn: add CRC-32 implementation (Omar Sandoval)
- libdrgn: elf_notes: add helper function for looking up notes (Omar Sandoval)
- libdrgn: enable -Wformat-security (Omar Sandoval)