blob: 5994191026b65890098356997e658e09b17f690d [file] [log] [blame]
#!/bin/bash
# Copyright 2024 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Bash launcher for regenerator.py. For performance reasons, do not invoke
# any sub-command before the final "exec" call.
set -e
function die {
echo >&2 "ERROR: $*"
exit 1
}
# Compute parent directory without invoking any subcommand.
function parent_dir {
printf %s "${1%/[^/]*}"
}
# Compute Fuchsia host tag without invoking any subcommand.
function fuchsia_host_tag {
local host_os host_arch
case "${OSTYPE}" in
linux*)
host_os=linux
;;
darwin*)
host_os=mac
;;
*)
die "Unknown host operating system: $OSTYPE"
;;
esac
case "${HOSTTYPE}" in
x86_64|amd64)
host_arch=x64
;;
aarch64|arm64)
host_arch=arm64
;;
*)
die "Unknown host CPU architecture: $HOSTTYPE"
;;
esac
echo "${host_os}-${host_arch}"
}
script_dir="$(parent_dir "${BASH_SOURCE[0]}")"
readonly script_dir
readonly fuchsia_dir="${script_dir}/.."
host_tag="$(fuchsia_host_tag)"
readonly host_tag
readonly python_prebuilt_dir="${fuchsia_dir}/prebuilt/third_party/python3/${host_tag}"
exec "${python_prebuilt_dir}/bin/python3" -S "${script_dir}/regenerator.py" "--host-tag=${host_tag}" "$@"