# Generated by rust2rpm 25
# XXX: sccache_cargo and system test sets are failing
%bcond_with check
%ifarch x86_64
%bcond_without dist_server
%endif

%global crate sccache
%global __cargo_is_lib() 0

Name:           rust-sccache
Version:        0.7.4
Release:        0.1%{?dist}
Summary:        Ccache-like tool

License:        Apache-2.0
URL:            https://crates.io/crates/sccache
Source:         %{crates_source}

Source100:      %{crate}-scheduler.service
Source101:      %{crate}-server.service
Source102:      scheduler.conf
Source103:      server.conf
# Automatically generated patch to strip dependencies and normalize metadata
Patch:          sccache-fix-metadata-auto.diff
# Manually created patch for downstream crate metadata changes
Patch:          sccache-fix-metadata.diff

BuildRequires:  cargo-rpm-macros >= 24
BuildRequires:  systemd-rpm-macros

%global _description %{expand:
Sccache is a ccache-like tool. It is used as a compiler wrapper and
avoids compilation when possible, storing a cache in a remote storage
using various cloud storage.}

%description %{_description}

%package     -n %{crate}
Summary:        %{summary}
# (Apache-2.0 OR MIT) AND BSD-3-Clause
# (MIT OR Apache-2.0) AND Unicode-DFS-2016
# 0BSD OR MIT OR Apache-2.0
# Apache-2.0
# Apache-2.0 OR BSL-1.0
# Apache-2.0 OR ISC OR MIT
# Apache-2.0 OR MIT
# Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT
# BSD-2-Clause
# BSD-3-Clause
# CC0-1.0
# CC0-1.0 OR Apache-2.0
# CC0-1.0 OR MIT-0 OR Apache-2.0
# ISC
# ISC AND MIT AND OpenSSL
# MIT
# MIT OR Apache-2.0
# MIT OR Apache-2.0 OR Zlib
# MIT OR Zlib OR Apache-2.0
# MPL-2.0
# Unlicense OR MIT
# Zlib
# Zlib OR Apache-2.0 OR MIT
License:        Apache-2.0 AND (0BSD OR MIT OR Apache-2.0) AND (Apache-2.0 OR BSL-1.0) AND (Apache-2.0 OR ISC OR MIT) AND (Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT) AND BSD-2-Clause AND BSD-3-Clause AND CC0-1.0 AND (CC0-1.0 OR Apache-2.0) AND (CC0-1.0 OR MIT-0 OR Apache-2.0) AND ISC AND MIT AND (MIT OR Apache-2.0) AND (MIT OR Apache-2.0 OR Zlib) AND (MIT OR Zlib OR Apache-2.0) AND MPL-2.0 AND OpenSSL AND Unicode-DFS-2016 AND (Unlicense OR MIT) AND Zlib
# LICENSE.dependencies contains a full license breakdown

%description -n %{crate} %{_description}

%files       -n %{crate}
%license LICENSE
%license LICENSE.dependencies
%doc CODE_OF_CONDUCT.md
%doc README.md
%doc docs/*
%{_bindir}/sccache

%if %{with dist_server}
%package     -n %{crate}-dist
Summary:        %{summary}
Requires:       bubblewrap

%description -n %{crate}-dist %{_description}
This package contains distributed compilation server and scheduler part of sccache.

%files       -n %{crate}-dist
%license LICENSE
%doc README.md
%doc docs/*
%{_bindir}/sccache-dist
%dir %{_sharedstatedir}/%{crate}
%dir %{_sysconfdir}/%{crate}
%config(noreplace) %{_sysconfdir}/%{crate}/scheduler.conf
%config(noreplace) %{_sysconfdir}/%{crate}/server.conf
%{_unitdir}/%{crate}-scheduler.service
%{_unitdir}/%{crate}-server.service

%post -n %{crate}-dist
%systemd_post %{crate}-scheduler.service %{crate}-server.service

%preun -n %{crate}-dist
%systemd_preun %{crate}-scheduler.service %{crate}-server.service

%postun -n %{crate}-dist
%systemd_postun %{crate}-scheduler.service %{crate}-server.service
%endif

%prep
%autosetup -n %{crate}-%{version} -p1
%cargo_prep

%generate_buildrequires
%cargo_generate_buildrequires %{?with_dist_server:-f dist-server}

%build
%if %{with dist_server}
%cargo_build -f dist-server
%{cargo_license_summary -f dist-server}
%{cargo_license -f dist-server} > LICENSE.dependencies
%else
%cargo_build
%{cargo_license_summary}
%{cargo_license} > LICENSE.dependencies
%endif

%install
%cargo_install %{?with_dist_server:-f dist-server}

%if %{with dist_server}
install -d -m 750 -pv %{buildroot}%{_sharedstatedir}/%{crate}
install -D -m 644 -pv %{SOURCE100} %{buildroot}%{_unitdir}/%{crate}-scheduler.service
install -D -m 644 -pv %{SOURCE101} %{buildroot}%{_unitdir}/%{crate}-server.service
# configs contain secret keys and tokens, thus 0600
install -D -m 600 -pv %{SOURCE102} %{buildroot}%{_sysconfdir}/%{crate}/scheduler.conf
install -D -m 600 -pv %{SOURCE103} %{buildroot}%{_sysconfdir}/%{crate}/server.conf
%endif

%if %{with check}
%check
%cargo_test %{?with_dist_server:-f dist-server}
%endif

%changelog
* Fri Dec 22 2023 Aleksei Bavshin <alebastr@fedoraproject.org> - 0.7.4-0.1
- Update to 0.7.4

* Mon Mar 27 2023 Aleksei Bavshin <alebastr@fedoraproject.org> - 0.4.1-0.1
- Update to 0.4.1

* Sat Mar 25 2023 Aleksei Bavshin <alebastr@fedoraproject.org> - 0.4.0-0.1
- Initial package