#!/bin/bash

# Upstream's last release is 1.5.0 from 2023, which predates the fixes for
# building with boost >= 1.89 and C23; this packs a snapshot of the git master
# branch instead. Pass a commit to pack that instead of HEAD.

COMMIT=${1:-master}

rm -rf heaptrack-*

git clone https://invent.kde.org/sdk/heaptrack.git heaptrack || exit 1

cd heaptrack
git checkout -q $COMMIT || exit 1
VERSION=$(git log -1 --pretty=format:"git_%cd_%h" --date=format:"%Y%m%d")
cd ..

mv heaptrack heaptrack-$VERSION

tar --exclude-vcs -cf heaptrack-$VERSION.tar heaptrack-$VERSION
plzip -9 heaptrack-$VERSION.tar

rm -rf heaptrack-$VERSION
