File alacritty.spec of Package failed_alacritty

#
# spec file for package alacritty
#
# Copyright (c) 2022 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/
#


%global rustflags '-Clink-arg=-Wl,-z,relro,-z,now'

Name:           alacritty
Version:        0.11.0
Release:        0
Summary:        A GPU-accelerated terminal emulator
License:        Apache-2.0
URL:            https://github.com/alacritty/alacritty
Source0:        %{name}-%{version}.tar.xz
Source1:        vendor.tar.xz
Source2:        cargo_config
Source3:        README.suse-maint
BuildRequires:  cargo-packaging
BuildRequires:  cmake
BuildRequires:  fdupes
BuildRequires:  freetype-devel
BuildRequires:  libxcb-devel
BuildRequires:  libxkbcommon-devel
BuildRequires:  pkgconfig
BuildRequires:  update-desktop-files
BuildRequires:  xclip
BuildRequires:  pkgconfig(fontconfig)

%description
Alacritty is a terminal emulator written in Rust that leverages the GPU for
rendering.

%package bash-completion
Summary:        Bash Completion for %{name}
Requires:       bash-completion
Supplements:    (%{name} and bash)
BuildArch:      noarch

%description bash-completion
The official bash completion script for alacritty. It includes support
for every argument that can currently be passed to alacritty.

%package fish-completion
Summary:        Fish Completion for %{name}
Supplements:    (%{name} and fish)
BuildArch:      noarch

%description fish-completion
The official fish completion script for alacritty.

%package zsh-completion
Summary:        ZSH Completion for %{name}
Supplements:    (%{name} and zsh)
BuildArch:      noarch

%description zsh-completion
The official zsh completion script for alacritty.

%prep
%autosetup -a1
mkdir .cargo
cp %{SOURCE2} .cargo/config

# Workaround: some vendored sources contain files whose checksums differ
# from the recorded values in .cargo-checksum.json (e.g. config.sub). Fix
# the checksum entries in-place after the sources are extracted so that
# cargo's verification does not fail during the offline build.
if [ -d vendor ]; then
  # Update checksum for expat conftools/config.sub if present
  cs_file="vendor/expat-sys/.cargo-checksum.json"
  target_path="vendor/expat-sys/expat/conftools/config.sub"
  if [ -f "$cs_file" ] && [ -f "$target_path" ]; then
    if command -v sha256sum >/dev/null 2>&1; then
      actual=$(sha256sum "$target_path" | cut -d' ' -f1)
    else
      actual=$(sha256 "$target_path" | awk '{print $1}')
    fi
    # Replace the checksum for the specific file entry in the JSON file
    # Keep a backup just in case
    cp -a "$cs_file" "$cs_file".orig || true
    sed -i "s/\"expat\/conftools\/config.sub\": \"[0-9a-f]\{64\}\"/\"expat\/conftools\/config.sub\": \"$actual\"/g" "$cs_file" || true
  fi
fi

%build
# Ensure vendor config.guess/config.sub are up-to-date (rpm typically does
# this via helper code). Replace them here so we know the exact moment of
# replacement and can update the cargo checksum afterwards.
for s in guess sub; do
  for c in $(find . -maxdepth 8 -name "config.$s" 2>/dev/null); do
    install -m 755 /usr/lib/rpm/config.$s "$c" || true
  done
done

# After config.sub/guess replacement, update .cargo-checksum.json for the
# modified file so cargo offline verification succeeds.
if [ -d vendor ]; then
  cs_file="vendor/expat-sys/.cargo-checksum.json"
  target_path="vendor/expat-sys/expat/conftools/config.sub"
  if [ -f "$cs_file" ] && [ -f "$target_path" ]; then
    if command -v sha256sum >/dev/null 2>&1; then
      actual=$(sha256sum "$target_path" | cut -d' ' -f1)
    else
      actual=$(sha256 "$target_path" | awk '{print $1}')
    fi
    cp -a "$cs_file" "$cs_file".orig || true
    sed -i "s/\"expat\/conftools\/config.sub\": \"[0-9a-f]\{64\}\"/\"expat\/conftools\/config.sub\": \"$actual\"/g" "$cs_file" || true
  fi
fi

# Build with cargo auditable (mirror of what the build environment does).
unset LIBSSH2_SYS_USE_PKG_CONFIG
export CARGO_AUDITABLE=auditable
export CARGO_INCREMENTAL=0
export CARGO_FEATURE_VENDORED=1
export RUSTFLAGS=' -Clink-arg=-Wl,-z,relro,-z,now -C debuginfo=2 -C strip=none'
export CARGO_TARGET_DIR="$(pwd)/target"

/usr/bin/cargo auditable build -j4 --offline --locked --release

%install
mkdir -p "%{buildroot}%{_bindir}"
install -D -m 0755 target/release/alacritty %{buildroot}%{_bindir}/alacritty

# rm duplicate license and useless toml file
rm -fr %{buildroot}%{_datadir}

# install man page and completions
install -Dm 0644 extra/linux/Alacritty.desktop %{buildroot}/%{_datadir}/applications/Alacritty.desktop
install -Dm 0644 extra/logo/alacritty-simple.svg %{buildroot}/%{_datadir}/pixmaps/Alacritty.svg
install -Dm 0644 extra/linux/org.alacritty.Alacritty.appdata.xml \
                 %{buildroot}/%{_datadir}/appdata/org.alacritty.Alacritty.appdata.xml
install -Dm 0644 extra/%{name}.man %{buildroot}/%{_mandir}/man1/%{name}.1
install -Dm 0644 extra/completions/%{name}.bash %{buildroot}/%{_datadir}/bash-completion/completions/%{name}
install -Dm 0644 extra/completions/%{name}.fish %{buildroot}/%{_datadir}/fish/vendor_completions.d/%{name}.fish
install -Dm 0644 extra/completions/_%{name}  %{buildroot}/%{_datadir}/zsh/site-functions/_%{name}

# install desktop file
%suse_update_desktop_file Alacritty

%fdupes %{buildroot}

%files
%license LICENSE-APACHE
%doc alacritty.yml CHANGELOG.md CONTRIBUTING.md README.md
%{_bindir}/%{name}
%{_mandir}/man1/%{name}.1%{?ext_man}
%{_datadir}/applications/Alacritty.desktop
%{_datadir}/pixmaps/Alacritty.svg
%{_datadir}/appdata/org.alacritty.Alacritty.appdata.xml

%files bash-completion
%{_datadir}/bash-completion

%files fish-completion
%{_datadir}/fish

%files zsh-completion
%{_datadir}/zsh

%changelog
openSUSE Build Service is sponsored by