From edef9a9c861691f44346b1fa10c398700a1aa726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 29 Jul 2021 10:59:26 +0200 Subject: [PATCH] Add script to make source tarball with `.git/HEAD` This allows to generate the `VERSION_HASH` constant with the Git commit hash even when building from a source tarball which is not a Git repository (and without dependency on Git itself). (cherry picked from commit 9a71038e346aa01480e2379e1f3caadfa5692b2b) --- misc/scripts/make_tarball.sh | 66 ++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 misc/scripts/make_tarball.sh diff --git a/misc/scripts/make_tarball.sh b/misc/scripts/make_tarball.sh new file mode 100755 index 0000000000..9e02b80af1 --- /dev/null +++ b/misc/scripts/make_tarball.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +if [ ! -e "version.py" ]; then + echo "This script should be ran from the root folder of the Godot repository." + exit 1 +fi + +while getopts "h?sv:g:" opt; do + case "$opt" in + h|\?) + echo "Usage: $0 [OPTIONS...]" + echo + echo " -s script friendly file name (godot.tar.gz)" + echo " -v godot version for file name (e.g. 4.0-stable)" + echo " -g git treeish to archive (e.g. master)" + echo + exit 1 + ;; + s) + script_friendly_name=1 + ;; + v) + godot_version=$OPTARG + ;; + g) + git_treeish=$OPTARG + ;; + esac +done + +if [ ! -z "$git_treeish" ]; then + HEAD=$(git rev-parse $git_treeish) +else + HEAD=$(git rev-parse HEAD) +fi + +if [ ! -z "$script_friendly_name" ]; then + NAME=godot +else + if [ ! -z "$godot_version" ]; then + NAME=godot-$godot_version + else + NAME=godot-$HEAD + fi +fi + +CURDIR=$(pwd) +TMPDIR=$(mktemp -d -t godot-XXXXXX) + +echo "Generating tarball for revision $HEAD with folder name '$NAME'." +echo +echo "The tarball will be written to the parent folder:" +echo " $(dirname $CURDIR)/$NAME.tar.gz" + +git archive $HEAD --prefix=$NAME/ -o $TMPDIR/$NAME.tar + +# Adding custom .git/HEAD to tarball so that we can generate VERSION_HASH. +cd $TMPDIR +mkdir -p $NAME/.git +echo $HEAD > $NAME/.git/HEAD +tar -uf $NAME.tar $NAME + +cd $CURDIR +gzip -c $TMPDIR/$NAME.tar > ../$NAME.tar.gz + +rm -rf $TMPDIR