build script: add .git fallback

This commit is contained in:
boppyt 2021-08-28 22:37:02 -07:00 committed by Francesco
parent ab6eac399c
commit 08e4e5275f
1 changed files with 24 additions and 6 deletions

View File

@ -10,7 +10,16 @@ copy_directory_from_repo () {
fi fi
local dirname="$1" local dirname="$1"
local destdir="$2" local destdir="$2"
git archive "$use_branch" "$dirname" --format=tar | tar xf - -C "$destdir" "${tar_options[@]}" _archive "$use_branch" "$dirname" "$destdir" "${tar_options[@]}"
}
_archive () {
if [[ -d ".git" ]]; then
git archive "$1" "$2" --format=tar | tar xf - -C "$3" "$4"
else
echo ".git not found, falling back to UNIX operation"
cp -r "$2" "$3"
fi
} }
# Check if build directory is ok to be used to build. # Check if build directory is ok to be used to build.
@ -20,11 +29,15 @@ build_dir_is_usable () {
echo "invalid build directory, no path allowed: \"$build\"" echo "invalid build directory, no path allowed: \"$build\""
return 1 return 1
fi fi
if [[ -d ".git" ]]; then
git ls-files --error-unmatch "$build" &> /dev/null git ls-files --error-unmatch "$build" &> /dev/null
if [ $? == 0 ]; then if [ $? == 0 ]; then
echo "invalid path, \"$build\" is under revision control" echo "invalid path, \"$build\" is under revision control"
return 1 return 1
fi fi
else
echo ".git not found, skipping check for revision control"
fi
} }
# Ordinary release build # Ordinary release build
@ -214,7 +227,12 @@ if [ -z ${arch+set} ]; then
fi fi
if [ -z ${use_branch+set} ]; then if [ -z ${use_branch+set} ]; then
if [[ -d ".git" ]]; then
use_branch="$(git rev-parse --abbrev-ref HEAD)" use_branch="$(git rev-parse --abbrev-ref HEAD)"
else
# it really doesn't matter if git isn't present
use_branch="master"
fi
fi fi
build_dir=".build-$arch" build_dir=".build-$arch"