Make setup/configure scripts common between Linux/macOS

This commit is contained in:
Dan Paulat 2025-06-13 00:21:03 -05:00
parent d4b3c1869b
commit 9f7f1bf860
4 changed files with 31 additions and 17 deletions

View file

@ -1,8 +1,19 @@
#!/bin/bash
script_dir="$(dirname "$(readlink -f "$0")")"
script_source="${BASH_SOURCE[0]:-$0}"
script_dir="$(cd "$(dirname "${script_source}")" && pwd)"
# Assign user-specified Python Virtual Environment
[ "${1:-}" = "none" ] && unset venv_path || export venv_path="$(readlink -f "${1:-${script_dir}/../.venv}")"
if [ "${1:-}" = "none" ]; then
unset venv_path
else
venv_arg="${1:-${script_dir}/../.venv}"
# Portable way to get absolute path without requiring the directory to exist
case "${venv_arg}" in
/*) venv_path="${venv_arg}" ;;
*) venv_path="$(cd "$(dirname "${venv_arg}")" && pwd)/$(basename "${venv_arg}")" ;;
esac
export venv_path
fi
# Load custom build settings
if [ -f "${script_dir}/lib/user-setup.sh" ]; then
@ -11,12 +22,12 @@ fi
# Activate Python Virtual Environment
if [ -n "${venv_path:-}" ]; then
python -m venv "${venv_path}"
python3 -m venv "${venv_path}"
source "${venv_path}/bin/activate"
fi
# Detect if a Python Virtual Environment was specified above, or elsewhere
IN_VENV=$(python -c 'import sys; print(sys.prefix != getattr(sys, "base_prefix", sys.prefix))')
IN_VENV=$(python3 -c 'import sys; print(sys.prefix != getattr(sys, "base_prefix", sys.prefix))')
if [ "${IN_VENV}" = "True" ]; then
# In a virtual environment, don't use --user
@ -27,8 +38,8 @@ else
fi
# Install Python packages
python -m pip install ${PIP_FLAGS} --upgrade pip
pip install ${PIP_FLAGS} -r "${script_dir}/../requirements.txt"
python3 -m pip install ${PIP_FLAGS} --upgrade pip
python3 -m pip install ${PIP_FLAGS} -r "${script_dir}/../requirements.txt"
# Configure default Conan profile
conan profile detect -e

View file

@ -1,5 +1,6 @@
#!/bin/bash
script_dir="$(dirname "$(readlink -f "$0")")"
script_source="${BASH_SOURCE[0]:-$0}"
script_dir="$(cd "$(dirname "${script_source}")" && pwd)"
cmake_args=(
-B "${build_dir}"

View file

@ -1,5 +1,6 @@
#!/bin/bash
script_dir="$(dirname "$(readlink -f "$0")")"
script_source="${BASH_SOURCE[0]:-$0}"
script_dir="$(cd "$(dirname "${script_source}")" && pwd)"
# Import common paths
source "${script_dir}/common-paths.sh"
@ -9,14 +10,14 @@ if [ -f "${script_dir}/user-setup.sh" ]; then
source "${script_dir}/user-setup.sh"
fi
# Activate Python Virtual Environment
# Activate python3 Virtual Environment
if [ -n "${venv_path:-}" ]; then
python -m venv "${venv_path}"
python3 -m venv "${venv_path}"
source "${venv_path}/bin/activate"
fi
# Detect if a Python Virtual Environment was specified above, or elsewhere
IN_VENV=$(python -c 'import sys; print(sys.prefix != getattr(sys, "base_prefix", sys.prefix))')
# Detect if a python3 Virtual Environment was specified above, or elsewhere
IN_VENV=$(python3 -c 'import sys; print(sys.prefix != getattr(sys, "base_prefix", sys.prefix))')
if [ "${IN_VENV}" = "True" ]; then
# In a virtual environment, don't use --user
@ -26,9 +27,9 @@ else
PIP_FLAGS="--upgrade --user"
fi
# Install Python packages
python -m pip install ${PIP_FLAGS} pip
pip install ${PIP_FLAGS} -r "${script_dir}/../../requirements.txt"
# Install python3 packages
python3 -m pip install ${PIP_FLAGS} pip
python3 -m pip install ${PIP_FLAGS} -r "${script_dir}/../../requirements.txt"
if [[ -n "${build_type}" ]]; then
# Install Conan profile and packages
@ -49,7 +50,7 @@ fi
# Run CMake Configure
"${script_dir}/run-cmake-configure.sh"
# Deactivate Python Virtual Environment
# Deactivate python3 Virtual Environment
if [ -n "${venv_path:-}" ]; then
deactivate
fi

View file

@ -1,5 +1,6 @@
#!/bin/bash
script_dir="$(dirname "$(readlink -f "$0")")"
script_source="${BASH_SOURCE[0]:-$0}"
script_dir="$(cd "$(dirname "${script_source}")" && pwd)"
# Configure default Conan profile
conan profile detect -e