You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rust-below/update-vendor-tarball.sh

63 lines
2.1 KiB

#!/bin/sh
if [ "$1" == --prepare ]; then
PREPARE=1
fi
name='below'
specfile="rust-${name}.spec"
version=$(rpm -q --qf '%{VERSION}\n' --specfile "$specfile" | head -1)
nv="${name}-${version}"
crate="${nv}.crate"
vendor_tarball="${nv}-vendor.tar.gz"
if [ -f "$vendor_tarball" ]; then
echo "${vendor_tarball} already exists, aborting"
exit 1
fi
[ -f "$crate" ] || spectool -g "$specfile"
tardir="$PWD"
workdir=$(mktemp -d)
if [ ! -n "$PREPARE" ]; then
trap 'rm -rf "$workdir"' EXIT
fi
# All the below crates use edition 2021, which isn't supported by rust in el8;
# moreover, libbpf-rs and libbpf-cargo transitively depend on libbpf 0.5.0, and
# el8 ships 0.4.0.
#
# So we cheat:
# - below-fix-metadata.diff (which is applied in %prep) downgrades the edition
# for below and sets up all the other crates to be replaced with patched
# versions under patched-crates/
# - below-patched-crates.patch contains the actual modifications of the patched
# crates (mostly the edition downgrades, a few pins and a couple of build
# fixes)
#
# We then build the vendored tarball as follows:
# - unpack the below crate and vendor
# - foreach patched crate, move it from vendor/ to patched-crates/
# - delete vendor/ as it's no longer needed, and so we can vendor again later
# - apply the two patches, to fix the below metadata and the patched crates
# - run vendor again, and then tar up *both* patched-crates/ and vendor/
tar xvzf "$tardir/$crate" -C "$workdir"
(cd "${workdir}/${nv}" && cargo vendor)
mkdir "${workdir}/${nv}/patched-crates"
for c in below_derive below-common below-config below-dump below-model below-render below-store below-view cgroupfs fb_procfs libbpf-cargo libbpf-rs; do
mv "${workdir}/${nv}/vendor/${c}" "${workdir}/${nv}/patched-crates/"
done
rm -r "${workdir}/${nv}/vendor"
(cd "${workdir}/${nv}" && patch -p1 < ${tardir}/below-fix-metadata.diff)
if [ -n "$PREPARE" ]; then
echo "Go to ${workdir} and update the patch"
exit 1
else
(cd "${workdir}/${nv}" && \
patch -p1 < ${tardir}/below-patched-crates.patch && \
cargo vendor && \
tar cvzf "${tardir}/${vendor_tarball}" patched-crates/ vendor/)
fi
exit 0