2019-01-29 21:20:43 +01:00
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
2025-08-25 12:22:37 +00:00
|
|
|
|
set -e
|
|
|
|
|
|
|
2019-07-23 21:24:32 +02:00
|
|
|
|
# Set a fixed umask as this leaks into docker containers
|
|
|
|
|
|
umask 0022
|
|
|
|
|
|
|
2019-01-29 21:20:43 +01:00
|
|
|
|
RED='\033[0;31m'
|
|
|
|
|
|
BLUE='\033[0;34m'
|
|
|
|
|
|
YELLOW='\033[0;33m'
|
|
|
|
|
|
NC='\033[0m' # No Color
|
|
|
|
|
|
function info {
|
|
|
|
|
|
printf "\r💬 ${BLUE}INFO:${NC} ${1}\n"
|
|
|
|
|
|
}
|
|
|
|
|
|
function fail {
|
|
|
|
|
|
printf "\r🗯 ${RED}ERROR:${NC} ${1}\n"
|
|
|
|
|
|
exit 1
|
|
|
|
|
|
}
|
|
|
|
|
|
function warn {
|
|
|
|
|
|
printf "\r⚠️ ${YELLOW}WARNING:${NC} ${1}\n"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# based on https://superuser.com/questions/497940/script-to-verify-a-signature-with-gpg
|
|
|
|
|
|
function verify_signature() {
|
|
|
|
|
|
local file=$1 keyring=$2 out=
|
|
|
|
|
|
if out=$(gpg --no-default-keyring --keyring "$keyring" --status-fd 1 --verify "$file" 2>/dev/null) &&
|
2022-09-27 14:55:22 +00:00
|
|
|
|
echo "$out" | grep -qs "^\[GNUPG:\] VALIDSIG "; then
|
2019-01-29 21:20:43 +01:00
|
|
|
|
return 0
|
|
|
|
|
|
else
|
|
|
|
|
|
echo "$out" >&2
|
|
|
|
|
|
exit 1
|
|
|
|
|
|
fi
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function verify_hash() {
|
|
|
|
|
|
local file=$1 expected_hash=$2
|
2025-09-02 17:29:48 +00:00
|
|
|
|
actual_hash=$(sha256sum "$file" | awk '{print $1}')
|
2019-01-29 21:20:43 +01:00
|
|
|
|
if [ "$actual_hash" == "$expected_hash" ]; then
|
|
|
|
|
|
return 0
|
|
|
|
|
|
else
|
|
|
|
|
|
echo "$file $actual_hash (unexpected hash)" >&2
|
|
|
|
|
|
rm "$file"
|
|
|
|
|
|
exit 1
|
|
|
|
|
|
fi
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function download_if_not_exist() {
|
|
|
|
|
|
local file_name=$1 url=$2
|
2025-09-02 17:29:48 +00:00
|
|
|
|
if [ ! -e "$file_name" ] ; then
|
|
|
|
|
|
wget -O "$file_name" "$url"
|
2019-01-29 21:20:43 +01:00
|
|
|
|
fi
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-26 15:42:49 +02:00
|
|
|
|
# Function to clone or update a git repository to a specific commit
|
|
|
|
|
|
clone_or_update_repo() {
|
|
|
|
|
|
local repo_url=$1
|
|
|
|
|
|
local commit_hash=$2
|
|
|
|
|
|
local repo_dir=$3
|
|
|
|
|
|
|
|
|
|
|
|
if [ -z "$repo_url" ] || [ -z "$commit_hash" ] || [ -z "$repo_dir" ]; then
|
|
|
|
|
|
fail "clone_or_update_repo: invalid arguments: repo_url='$repo_url', commit_hash='$commit_hash', repo_dir='$repo_dir'"
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ -d "$repo_dir" ]; then
|
|
|
|
|
|
info "Repository $repo_url exists in $repo_dir, updating..."
|
|
|
|
|
|
git -C "$repo_dir" clean -ffxd >/dev/null 2>&1 || fail "Failed to clean repository $repo_dir"
|
|
|
|
|
|
git -C "$repo_dir" fetch --all >/dev/null 2>&1 || fail "Failed to fetch from repository"
|
|
|
|
|
|
git -C "$repo_dir" reset --hard "$commit_hash^{commit}" >/dev/null 2>&1 || fail "Failed to reset to commit $commit_hash"
|
|
|
|
|
|
else
|
|
|
|
|
|
info "Cloning repository: $repo_url to $repo_dir"
|
|
|
|
|
|
git clone "$repo_url" "$repo_dir" >/dev/null 2>&1 || fail "Failed to clone repository $repo_url"
|
|
|
|
|
|
git -C "$repo_dir" checkout "$commit_hash^{commit}" >/dev/null 2>&1 || fail "Failed to checkout commit $commit_hash"
|
|
|
|
|
|
fi
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-19 13:10:09 +02:00
|
|
|
|
apply_patch() {
|
|
|
|
|
|
local patch=$1
|
|
|
|
|
|
local path=$2
|
|
|
|
|
|
|
|
|
|
|
|
if [ -z "$patch" ] || [ -z "$path" ]; then
|
|
|
|
|
|
fail "apply_patch: invalid arguments: patch='$patch', path='$path'"
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ -d "$path" ]; then
|
|
|
|
|
|
info "Patching: $patch"
|
|
|
|
|
|
cd "$path"
|
|
|
|
|
|
patch -p1 <"$patch"
|
|
|
|
|
|
cd -
|
|
|
|
|
|
else
|
|
|
|
|
|
fail "apply_patch: path='$path' not found"
|
|
|
|
|
|
fi
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-29 21:20:43 +01:00
|
|
|
|
# https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/templates/header.sh
|
|
|
|
|
|
function retry() {
|
2022-09-27 14:55:22 +00:00
|
|
|
|
local result=0
|
|
|
|
|
|
local count=1
|
|
|
|
|
|
while [ $count -le 3 ]; do
|
|
|
|
|
|
[ $result -ne 0 ] && {
|
|
|
|
|
|
echo -e "\nThe command \"$@\" failed. Retrying, $count of 3.\n" >&2
|
|
|
|
|
|
}
|
|
|
|
|
|
! { "$@"; result=$?; }
|
|
|
|
|
|
[ $result -eq 0 ] && break
|
|
|
|
|
|
count=$(($count + 1))
|
|
|
|
|
|
sleep 1
|
|
|
|
|
|
done
|
2019-01-29 21:20:43 +01:00
|
|
|
|
|
2022-09-27 14:55:22 +00:00
|
|
|
|
[ $count -gt 3 ] && {
|
|
|
|
|
|
echo -e "\nThe command \"$@\" failed 3 times.\n" >&2
|
|
|
|
|
|
}
|
2019-01-29 21:20:43 +01:00
|
|
|
|
|
2022-09-27 14:55:22 +00:00
|
|
|
|
return $result
|
2019-01-29 21:20:43 +01:00
|
|
|
|
}
|
2020-02-10 19:20:23 +01:00
|
|
|
|
|
|
|
|
|
|
function gcc_with_triplet()
|
|
|
|
|
|
{
|
|
|
|
|
|
TRIPLET="$1"
|
|
|
|
|
|
CMD="$2"
|
|
|
|
|
|
shift 2
|
|
|
|
|
|
if [ -n "$TRIPLET" ] ; then
|
|
|
|
|
|
"$TRIPLET-$CMD" "$@"
|
|
|
|
|
|
else
|
|
|
|
|
|
"$CMD" "$@"
|
|
|
|
|
|
fi
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function gcc_host()
|
|
|
|
|
|
{
|
|
|
|
|
|
gcc_with_triplet "$GCC_TRIPLET_HOST" "$@"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function gcc_build()
|
|
|
|
|
|
{
|
|
|
|
|
|
gcc_with_triplet "$GCC_TRIPLET_BUILD" "$@"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function host_strip()
|
|
|
|
|
|
{
|
|
|
|
|
|
if [ "$GCC_STRIP_BINARIES" -ne "0" ] ; then
|
|
|
|
|
|
case "$BUILD_TYPE" in
|
|
|
|
|
|
linux|wine)
|
|
|
|
|
|
gcc_host strip "$@"
|
|
|
|
|
|
;;
|
|
|
|
|
|
darwin)
|
|
|
|
|
|
# TODO: Strip on macOS?
|
|
|
|
|
|
;;
|
|
|
|
|
|
esac
|
|
|
|
|
|
fi
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-11 16:06:32 +01:00
|
|
|
|
# on MacOS, there is no realpath by default
|
|
|
|
|
|
if ! [ -x "$(command -v realpath)" ]; then
|
|
|
|
|
|
function realpath() {
|
|
|
|
|
|
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
|
|
|
|
|
|
}
|
|
|
|
|
|
fi
|
2020-02-10 19:20:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export SOURCE_DATE_EPOCH=1530212462
|
2021-06-23 15:46:45 +02:00
|
|
|
|
export ZERO_AR_DATE=1 # for macOS
|
2020-02-10 19:20:23 +01:00
|
|
|
|
export PYTHONHASHSEED=22
|
|
|
|
|
|
# Set the build type, overridden by wine build
|
|
|
|
|
|
export BUILD_TYPE="${BUILD_TYPE:-$(uname | tr '[:upper:]' '[:lower:]')}"
|
|
|
|
|
|
# Add host / build flags if the triplets are set
|
|
|
|
|
|
if [ -n "$GCC_TRIPLET_HOST" ] ; then
|
|
|
|
|
|
export AUTOCONF_FLAGS="$AUTOCONF_FLAGS --host=$GCC_TRIPLET_HOST"
|
|
|
|
|
|
fi
|
|
|
|
|
|
if [ -n "$GCC_TRIPLET_BUILD" ] ; then
|
|
|
|
|
|
export AUTOCONF_FLAGS="$AUTOCONF_FLAGS --build=$GCC_TRIPLET_BUILD"
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
export GCC_STRIP_BINARIES="${GCC_STRIP_BINARIES:-0}"
|
2023-01-02 12:21:02 +00:00
|
|
|
|
|
|
|
|
|
|
if [ -n "$CIRRUS_CPU" ] ; then
|
|
|
|
|
|
# special-case for CI. see https://github.com/cirruslabs/cirrus-ci-docs/issues/1115
|
|
|
|
|
|
export CPU_COUNT="$CIRRUS_CPU"
|
|
|
|
|
|
else
|
|
|
|
|
|
export CPU_COUNT="$(nproc 2> /dev/null || sysctl -n hw.ncpu)"
|
|
|
|
|
|
fi
|
2022-12-03 23:46:25 +00:00
|
|
|
|
info "Found $CPU_COUNT CPUs, which we might use for building."
|
2020-02-10 19:20:23 +01:00
|
|
|
|
|
2020-12-12 02:52:38 +01:00
|
|
|
|
|
|
|
|
|
|
function break_legacy_easy_install() {
|
|
|
|
|
|
# We don't want setuptools sneakily installing dependencies, invisible to pip.
|
|
|
|
|
|
# This ensures that if setuptools calls distutils which then calls easy_install,
|
|
|
|
|
|
# easy_install will not download packages over the network.
|
|
|
|
|
|
# see https://pip.pypa.io/en/stable/reference/pip_install/#controlling-setup-requires
|
|
|
|
|
|
# see https://github.com/pypa/setuptools/issues/1916#issuecomment-743350566
|
|
|
|
|
|
info "Intentionally breaking legacy easy_install."
|
|
|
|
|
|
DISTUTILS_CFG="${HOME}/.pydistutils.cfg"
|
|
|
|
|
|
DISTUTILS_CFG_BAK="${HOME}/.pydistutils.cfg.orig"
|
|
|
|
|
|
# If we are not inside docker, we might be overwriting a config file on the user's system...
|
|
|
|
|
|
if [ -e "$DISTUTILS_CFG" ] && [ ! -e "$DISTUTILS_CFG_BAK" ]; then
|
|
|
|
|
|
warn "Overwriting python distutils config file at '$DISTUTILS_CFG'. A copy will be saved at '$DISTUTILS_CFG_BAK'."
|
|
|
|
|
|
mv "$DISTUTILS_CFG" "$DISTUTILS_CFG_BAK"
|
|
|
|
|
|
fi
|
|
|
|
|
|
cat <<EOF > "$DISTUTILS_CFG"
|
|
|
|
|
|
[easy_install]
|
|
|
|
|
|
index_url = ''
|
|
|
|
|
|
find_links = ''
|
|
|
|
|
|
EOF
|
|
|
|
|
|
}
|
|
|
|
|
|
|