build deb packages using debbuild

Signed-off-by: Lokesh Mandvekar <lsm5@fedoraproject.org>
This commit is contained in:
Lokesh Mandvekar 2022-05-19 15:51:00 -04:00
parent edd7fe37d1
commit 842aa411fb

View File

@ -1,3 +1,7 @@
%if "%{_vendor}" == "debbuild"
%define gobuild(o:) GO111MODULE=off go build -buildmode pie -tags=" ${BUILDTAGS:-}" -a -v -x %{?**};
%endif
%global with_debug 1
%if 0%{?with_debug}
@ -16,22 +20,40 @@
%global git0 https://%{import_path}
%global built_tag v1.26.1
%global built_tag_strip %(b=%{built_tag}; echo ${b:1})
%global gen_version %(b=%{built_tag_strip}; echo ${b/-/"~"})
Name: %{repo}
Version: %{gen_version}
Release: %autorelease
Summary: A command line tool used for creating OCI Images
Version: 1.26.1
%if "%{_vendor}" == "debbuild"
Maintainer: Lokesh Mandvekar <lsm5@fedoraproject.org>
License: ASL-2.0+
Release: 0%{?dist}
%else
License: ASL 2.0 and BSD and MIT and MPLv2.0
Release: %autorelease
%endif
Summary: A command line tool used for creating OCI Images
URL: https://%{name}.io
Source: %{git0}/archive/%{built_tag}.tar.gz
BuildRequires: go-md2man
%if "%{_vendor}" == "debbuild"
BuildRequires: git
BuildRequires: golang
BuildRequires: libassuan-dev
BuildRequires: libbtrfs-dev
BuildRequires: libdevmapper-dev
BuildRequires: libglib2.0-dev
BuildRequires: libgpg-error-dev
BuildRequires: libgpgme-dev
BuildRequires: libseccomp-dev
BuildRequires: libsystemd-dev
BuildRequires: pkg-config
Requires: containers-common >= 4:1
%else
BuildRequires: device-mapper-devel
BuildRequires: git-core
BuildRequires: golang >= 1.16.6
BuildRequires: glib2-devel
BuildRequires: glibc-static
BuildRequires: go-md2man
BuildRequires: go-rpm-macros
BuildRequires: gpgme-devel
BuildRequires: libassuan-devel
@ -80,6 +102,7 @@ Provides: bundled(golang(github.com/spf13/cobra)) = v1.3.0
Provides: bundled(golang(github.com/spf13/pflag)) = v1.0.5
Provides: bundled(golang(github.com/stretchr/testify)) = v1.7.0
Provides: bundled(golang(github.com/syndtr/gocapability)) = v0.0.0_20200815063812_42c35b437635
%endif
%description
The %{name} package provides a command line tool which can be used to
@ -110,12 +133,11 @@ Requires: git-daemon
This package contains system tests for %{name}
%prep
%autosetup -Sgit -n %{name}-%{built_tag_strip}
%autosetup -Sgit
%build
%if "%{_vendor}" != "debbuild"
%set_build_flags
export GOPATH=$(pwd)/_build:$(pwd)
export CGO_CFLAGS=$CFLAGS
# These extra flags present in $CFLAGS have been skipped for now as they break the build
CGO_CFLAGS=$(echo $CGO_CFLAGS | sed 's/-flto=auto//g')
CGO_CFLAGS=$(echo $CGO_CFLAGS | sed 's/-Wp,D_GLIBCXX_ASSERTIONS//g')
@ -124,29 +146,43 @@ CGO_CFLAGS=$(echo $CGO_CFLAGS | sed 's/-specs=\/usr\/lib\/rpm\/redhat\/redhat-an
%ifarch x86_64
export CGO_CFLAGS+=" -m64 -mtune=generic -fcf-protection=full"
%endif
%endif
export GOPATH=$(pwd)/_build:$(pwd)
export CGO_CFLAGS=$CFLAGS
mkdir _build
pushd _build
cd _build
mkdir -p src/%{provider}.%{provider_tld}/%{project}
ln -s $(dirs +1 -l) src/%{import_path}
popd
ln -s ../../../../ src/%{import_path}
cd ..
mv vendor src
export CNI_VERSION=`grep '^# github.com/containernetworking/cni ' src/modules.txt | sed 's,.* ,,'`
export LDFLAGS="-X main.buildInfo=`date +%s` -X main.cniVersion=${CNI_VERSION}"
export BUILDTAGS='seccomp selinux'
export BUILDTAGS='seccomp exclude_graphdriver_devicemapper'
%if "%{_vendor}" != "debbuild"
export BUILDTAGS+=' selinux'
%endif
%gobuild -o bin/%{name} %{import_path}/cmd/%{name}
%gobuild -o bin/imgtype %{import_path}/tests/imgtype
%gobuild -o bin/copy %{import_path}/tests/copy
%gobuild -o bin/copy %{import_path}/tests/copy
GOMD2MAN=go-md2man %{__make} -C docs
%install
export GOPATH=$(pwd)/_build:$(pwd):%{gopath}
export GOPATH=$(pwd)/_build:$(pwd)
%if "%{_vendor}" != "debbuild"
make DESTDIR=%{buildroot} PREFIX=%{_prefix} install install.completions
make DESTDIR=%{buildroot} PREFIX=%{_prefix} -C docs install
%else
install -D -m0755 bin/%{name} %{buildroot}%{_bindir}/%{name}
install -m 644 -D contrib/completions/bash/%{name} %{buildroot}%{_datadir}/bash-completion/completions/%{name}
install -d %{buildroot}/%{_mandir}/man1
install -m 0644 docs/%{name}*.1 %{buildroot}%{_mandir}/man1
install -m 0644 docs/links/%{name}*.1 %{buildroot}%{_mandir}/man1
%endif
install -d -p %{buildroot}/%{_datadir}/%{name}/test/system
cp -pav tests/. %{buildroot}/%{_datadir}/%{name}/test/system
@ -172,4 +208,6 @@ cp bin/copy %{buildroot}/%{_bindir}/%{name}-copy
%{_datadir}/%{name}/test
%changelog
%if "%{_vendor}" != "debbuild"
%autochangelog
%endif