Merge pull request #3962 from lightmare/bootstrap-manners

bootstrap.sh improvements
This commit is contained in:
talaj 2018-08-07 09:28:33 +02:00 committed by GitHub
commit 1a87e920da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,8 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -eu
set -o pipefail
: ' : '
todo todo
@ -15,13 +12,15 @@ MASON_VERSION="e4c1746"
function setup_mason() { function setup_mason() {
if [[ ! -d ./.mason ]]; then if [[ ! -d ./.mason ]]; then
git clone https://github.com/mapbox/mason.git ./.mason git clone https://github.com/mapbox/mason.git .mason || return
(cd ./.mason && git checkout ${MASON_VERSION}) elif ! git -C .mason rev-parse -q --verify "$MASON_VERSION" >/dev/null; then
else git -C .mason fetch --all || true # non-fatal
echo "Updating to latest mason"
(cd ./.mason && git fetch && git checkout ${MASON_VERSION} && git pull origin ${MASON_VERSION})
fi fi
export PATH=$(pwd)/.mason:$PATH git -C .mason checkout --detach "$MASON_VERSION" -- || return
case ":$PATH:" in
*":$PWD/.mason:"*) : already there ;;
*) export PATH="$PWD/.mason:$PATH" ;;
esac
export CXX=${CXX:-clang++} export CXX=${CXX:-clang++}
export CC=${CC:-clang} export CC=${CC:-clang}
} }
@ -130,22 +129,47 @@ function setup_runtime_settings() {
echo "export PROJ_LIB=${MASON_LINKED_ABS}/share/proj" > mapnik-settings.env echo "export PROJ_LIB=${MASON_LINKED_ABS}/share/proj" > mapnik-settings.env
echo "export ICU_DATA=${MASON_LINKED_ABS}/share/icu/${ICU_VERSION}" >> mapnik-settings.env echo "export ICU_DATA=${MASON_LINKED_ABS}/share/icu/${ICU_VERSION}" >> mapnik-settings.env
echo "export GDAL_DATA=${MASON_LINKED_ABS}/share/gdal" >> mapnik-settings.env echo "export GDAL_DATA=${MASON_LINKED_ABS}/share/gdal" >> mapnik-settings.env
source mapnik-settings.env }
# turn arguments of the form NAME=VALUE into exported variables;
# any other arguments are reported and cause error return status
function export_variables() {
local arg= ret=0
for arg
do
if [[ "$arg" =~ [[:alpha:]][_[:alnum:]]*= ]]
then
local -n var="${arg%%=*}"
export var="${arg#*=}"
else
printf >&2 "bootstrap.sh: invalid argument: %s\n" "$arg"
ret=1
fi
done
return $ret
} }
function main() { function main() {
setup_mason export_variables "$@" || return
install_mason_deps # setup_mason must not run in subshell, because it sets default
make_config > ./config.py # values of CC, CXX and adds mason to PATH, which we want to keep
setup_runtime_settings # when sourced
echo "Ready, now run:" setup_mason || return
echo "" (
echo " ./configure && make" # this is wrapped in subshell to allow sourcing this script
# without having the terminal closed on error
set -eu
set -o pipefail
install_mason_deps
make_config > ./config.py
setup_runtime_settings
printf "\n\e[1;32m%s\e[m\n" "bootstrap successful, now run:"
echo ""
echo " ./configure && make"
echo ""
)
} }
main main "$@"
# allow sourcing of script without
# causing the terminal to bail on error
set +eu
set +o pipefail