# HG changeset patch
# User Georges Racinet <georges.racinet@octobus.net>
# Date 1682331675 -7200
#      Mon Apr 24 12:21:15 2023 +0200
# Node ID b80d12146e7a65910e997ee8347ed03b4f1bf51b
# Parent  0a957277827854c05820ba29d60c22168fa2fedf
RHGitaly: src-tarball make target

diff --git a/rust/Makefile b/rust/Makefile
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -1,5 +1,6 @@
 all: help
 
+HGITALY_VERSION := $(shell cat ../hgitaly/VERSION)
 MERCURIAL_SOURCE_REPO = dependencies/mercurial
 MERCURIAL_SOURCE_REV := $(shell cat mercurial.rev)
 MERCURIAL_SOURCE_REMOTE ?= https://foss.heptapod.net/mercurial/mercurial-devel
@@ -11,6 +12,9 @@
 	@echo "Available commands: "
 	@echo "  make dev-dependencies:  prepare development dependencies"
 	@echo "                          (hg-core, various resources)"
+	@echo "  make src-tarball:       package the workspace as a tarball,"
+	@echo "                          including all dependencies that "
+	@echo "                          cannot be obtained from crates.io"
 	@echo
 	@echo "Interesting variables: "
 	@echo "  MERCURIAL_SHARE_FROM: if set, Mercurial sources repository"
@@ -28,3 +32,7 @@
 else
 	hg clone --noupdate $(MERCURIAL_SOURCE_REMOTE) $(MERCURIAL_SOURCE_REPO)
 endif
+
+.PHONY: src-tarball
+src-tarball: dev-dependencies
+	./src-tarball.sh ${HGITALY_VERSION}
diff --git a/rust/src-tarball.sh b/rust/src-tarball.sh
new file mode 100755
--- /dev/null
+++ b/rust/src-tarball.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+set -e
+
+if [ -z "$1" ]; then
+    echo "usage: $0 HGITALY_VERSION";
+    exit 1
+fi
+
+HGITALY_VERSION=$1
+
+set -u
+
+DIST_HGITALY=hgitaly-${HGITALY_VERSION}
+DIST_RHGITALY=rhgitaly-${HGITALY_VERSION}
+TARBALL=${DIST_RHGITALY}.tgz
+
+cd `dirname $0`
+
+mkdir -p dist
+cd dist
+
+rm -rf ${DIST_HGITALY} ${DIST_RHGITALY}
+
+echo "Performing extractions"
+hg archive ${DIST_HGITALY}
+
+rm -f ${DIST_HGITALY}/rust/dependencies/hg-core # cp -Lrf cannot do this
+cp -Lr ../dependencies/hg-core ${DIST_HGITALY}/rust/dependencies
+
+mkdir -p ${DIST_RHGITALY}/hgitaly
+for path in hgitaly/VERSION protos rust; do
+    cp -r ${DIST_HGITALY}/${path} ${DIST_RHGITALY}/${path}
+done
+
+echo "Creating tarball"
+tar czf ${TARBALL} ${DIST_RHGITALY}
+
+echo "Removing temporary directories ${DIST_HGITALY} and ${DIST_RHGITALY}"
+rm -rf ${DIST_HGITALY} ${DIST_RHGITALY}
+
+echo "tarball available in `realpath ${TARBALL}`"