File coverage-tools.spec of Package coverage-tools

#
# spec file for package coverage-tools
#
# Copyright (c) 2025 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/

%define dname BinaryCoverage-%{version}
Name:           coverage-tools
Version:        0.4.5
Release:        0
Summary:        Tools necessary to test binary coverage of different packages
# nonfree is ISSL - Intel Simplified Software License see intel-simplified-software-license.txt
License:        MIT AND NonFree
URL:            https://github.com/ilmanzo/CodeCoverage
Source0:        %{dname}.tar.gz
Source1:        pin-external-3.31-98869-gfa6f126a8-gcc-linux.tar.gz
Source2:        vendor.tar.gz
Source3:        https://software.intel.com/sites/landingpage/pintool/intel-simplified-software-license.txt
BuildRequires:  go
BuildRequires:  unzip
ExclusiveArch:  x86_64
# Latest GCC version 15 does not work yet with Intel PIN, thus setting version manually
%if 0%{?suse_version} >= 1560
BuildRequires:  gcc14-c++
%else
BuildRequires:  gcc12-c++
%endif
# If building on SLE
%if 0%{?sle_version} == 0
BuildRequires:  openSUSE-release
%endif

%description
This is a function-level code coverage tool using Intel Pin as a dynamic binary instrumentation engine.
It works by firstly prepending and later logging function entry points during execution of target binaries.
The output is a simple text log showing which functions were called, suitable for post-processing or coverage analysis.

%prep
%autosetup -n %{dname} -a1 -b2

%build
export PIN_ROOT=%{_builddir}/%{dname}/pin-external-3.31-98869-gfa6f126a8-gcc-linux

%if 0%{?suse_version} >= 1560
export CXX='g++-14 -std=c++20 -Wl,-z,noexecstack %{optflags}'
%else
export CXX='g++-12 -std=c++20 -Wl,-z,noexecstack %{optflags}'
%endif

%make_build
export GOFLAGS="-buildmode=pie -trimpath -mod=vendor"
mv %{_builddir}/vendor .
go build -ldflags="-s -w" -o funkoverage ./cmd

%check
pushd cmd
go test -v ./...
popd

%install
mkdir -p %{buildroot}%{_libdir}/coverage-tools/pin-root/intel64/lib
mkdir -p %{buildroot}%{_libdir}/coverage-tools/pin-root/intel64/bin
mkdir -p %{buildroot}%{_libdir}/coverage-tools/pin-root/intel64/runtime/pincrt
mkdir -p %{buildroot}%{_libdir}/coverage-tools/pin-root/extras/xed-intel64/lib
mkdir -p %{buildroot}%{_bindir}
mkdir -p %{buildroot}%{_licensedir}/%{name}/

# Install binaries and scripts
install -m 0755 obj-intel64/FuncTracer.so %{buildroot}%{_libdir}/coverage-tools/
install -m 0755 funkoverage %{buildroot}%{_bindir}/funkoverage

mv pin-external-3.31-98869-gfa6f126a8-gcc-linux pin

install -m 0644 pin/intel64/lib/libdwarf.so %{buildroot}%{_libdir}/coverage-tools/pin-root/intel64/lib/
install -m 0644 pin/intel64/lib/libpindwarf.so %{buildroot}%{_libdir}/coverage-tools/pin-root/intel64/lib/
install -m 0644 pin/intel64/runtime/pincrt/libc-dynamic.so %{buildroot}%{_libdir}/coverage-tools/pin-root/intel64/runtime/pincrt/
install -m 0644 pin/intel64/runtime/pincrt/libm-dynamic.so %{buildroot}%{_libdir}/coverage-tools/pin-root/intel64/runtime/pincrt/
install -m 0644 pin/intel64/runtime/pincrt/libunwind-dynamic.so %{buildroot}%{_libdir}/coverage-tools/pin-root/intel64/runtime/pincrt/
install -m 0644 pin/intel64/runtime/pincrt/libc++abi.so %{buildroot}%{_libdir}/coverage-tools/pin-root/intel64/runtime/pincrt/
install -m 0644 pin/intel64/runtime/pincrt/libc++.so %{buildroot}%{_libdir}/coverage-tools/pin-root/intel64/runtime/pincrt/
install -m 0644 pin/intel64/runtime/pincrt/libdl-dynamic.so %{buildroot}%{_libdir}/coverage-tools/pin-root/intel64/runtime/pincrt/
install -m 0644 pin/intel64/runtime/pincrt/linker %{buildroot}%{_libdir}/coverage-tools/pin-root/intel64/runtime/pincrt/
install -m 0644 pin/extras/xed-intel64/lib/libxed.so %{buildroot}%{_libdir}/coverage-tools/pin-root/extras/xed-intel64/lib/

install -m 0755 pin/intel64/bin/pinbin %{buildroot}%{_libdir}/coverage-tools/pin-root/intel64/bin
install -m 0755 pin/pin %{buildroot}%{_libdir}/coverage-tools/pin-root/pin

# Copy ISSL license file
install -m 0644 %{_sourcedir}/intel-simplified-software-license.txt %{buildroot}%{_licensedir}/%{name}/intel-simplified-software-license.txt

%files
%license LICENSE
%license %{_licensedir}/%{name}/intel-simplified-software-license.txt
%doc README.md
%{_libdir}/coverage-tools
%{_bindir}/funkoverage

%changelog
openSUSE Build Service is sponsored by