2022-12-19 14:19:26 +00:00
|
|
|
# shellcheck shell=bash
|
2022-10-16 19:46:42 +00:00
|
|
|
# shellcheck disable=SC2034
|
|
|
|
# SC2034: "Variable appears unused. Verify it or export it."
|
|
|
|
# Those are intentional here, as the file is meant to be included elsewhere.
|
|
|
|
|
2023-10-02 14:26:32 +00:00
|
|
|
# NOTE: If using another privilege escalation binary make sure it is configured or has the appropriate flag
|
2022-11-23 20:01:11 +00:00
|
|
|
# to keep the current environment variables in the launched process (in sudo's case this is achieved
|
|
|
|
# through the -E flag described in sudo(8).
|
2022-10-16 19:46:42 +00:00
|
|
|
die() {
|
|
|
|
echo "die: $*"
|
|
|
|
exit 1
|
|
|
|
}
|
2022-12-06 17:17:41 +00:00
|
|
|
|
2023-04-24 19:09:23 +00:00
|
|
|
exit_if_running_as_root() {
|
|
|
|
if [ "$(id -u)" -eq 0 ]; then
|
|
|
|
die "$*"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-08-18 12:42:38 +00:00
|
|
|
# Usage: check_program_version_at_least <Display Name> <Program Name> <Version String>
|
|
|
|
check_program_version_at_least()
|
|
|
|
{
|
|
|
|
echo -n "Checking for $1 version at least $3... "
|
|
|
|
if ! command -v "$2" > /dev/null 2>&1; then
|
|
|
|
echo "ERROR: Cannot find $2 ($1)"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
v=$("$2" --version 2>&1 | grep -E -o '[0-9]+\.[0-9\.]+[a-z]*' | head -n1)
|
|
|
|
if printf '%s\n' "$3" "$v" | sort --version-sort --check &>/dev/null; then
|
|
|
|
echo "ok, found $v"
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
echo "ERROR: found version $v, too old!"
|
|
|
|
return 1;
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-05-02 19:04:35 +00:00
|
|
|
get_number_of_processing_units() {
|
|
|
|
number_of_processing_units="nproc"
|
|
|
|
SYSTEM_NAME="$(uname -s)"
|
|
|
|
|
|
|
|
if [ "$SYSTEM_NAME" = "OpenBSD" ]; then
|
|
|
|
number_of_processing_units="sysctl -n hw.ncpuonline"
|
|
|
|
elif [ "$SYSTEM_NAME" = "FreeBSD" ]; then
|
|
|
|
number_of_processing_units="sysctl -n hw.ncpu"
|
|
|
|
elif [ "$SYSTEM_NAME" = "Darwin" ]; then
|
|
|
|
number_of_processing_units="sysctl -n hw.ncpu"
|
|
|
|
fi
|
|
|
|
|
|
|
|
($number_of_processing_units)
|
|
|
|
}
|
2024-10-09 05:23:42 +00:00
|
|
|
|
|
|
|
get_top_dir() {
|
|
|
|
git rev-parse --show-toplevel
|
|
|
|
}
|
|
|
|
|
|
|
|
ensure_ladybird_source_dir() {
|
|
|
|
if [ -z "$LADYBIRD_SOURCE_DIR" ] || [ ! -d "$LADYBIRD_SOURCE_DIR" ]; then
|
|
|
|
LADYBIRD_SOURCE_DIR="$(get_top_dir)"
|
|
|
|
export LADYBIRD_SOURCE_DIR
|
|
|
|
fi
|
|
|
|
}
|
2024-10-09 05:32:11 +00:00
|
|
|
|
|
|
|
get_build_dir() {
|
|
|
|
ensure_ladybird_source_dir
|
|
|
|
|
|
|
|
# Note: Keep in sync with buildDir defaults in CMakePresets.json
|
|
|
|
case "$1" in
|
|
|
|
"default")
|
2024-09-30 13:55:48 +00:00
|
|
|
BUILD_DIR="${LADYBIRD_SOURCE_DIR}/Build/release"
|
2024-10-09 05:32:11 +00:00
|
|
|
;;
|
|
|
|
"Debug")
|
2024-09-30 13:55:48 +00:00
|
|
|
BUILD_DIR="${LADYBIRD_SOURCE_DIR}/Build/debug"
|
2024-10-09 05:32:11 +00:00
|
|
|
;;
|
|
|
|
"Sanitizer")
|
2024-09-30 13:55:48 +00:00
|
|
|
BUILD_DIR="${LADYBIRD_SOURCE_DIR}/Build/sanitizers"
|
2024-10-09 05:32:11 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown BUILD_PRESET: '$1'" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
echo "${BUILD_DIR}"
|
|
|
|
}
|
2024-10-29 08:45:59 +00:00
|
|
|
|
|
|
|
absolutize_path() {
|
|
|
|
directory="$(eval echo "$(dirname "$1")")"
|
|
|
|
if [ -d "$directory" ]; then
|
|
|
|
resolved_directory="$(cd "$directory" && pwd)"
|
|
|
|
echo "${resolved_directory%/}/$(basename "$1")"
|
|
|
|
else
|
|
|
|
echo "No such directory: '$directory'" >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|