forked from isc-projects/kea
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeson.sh
More file actions
executable file
·136 lines (119 loc) · 4.1 KB
/
meson.sh
File metadata and controls
executable file
·136 lines (119 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/sh
# Pulls the latest meson that has fix https://github.com/mesonbuild/meson/pull/13532
# for issue https://github.com/mesonbuild/meson/issues/11322.
#
# Usage: just like meson
# Example: ./meson.sh setup build
set -eu
meson_version=1.10.0
# Check if ${1} <= ${2}.
le() {
# Sort numerically and check the first item.
lesser=$(printf '%s\n%s\n' "${1}" "${2}" | sort -V | head -n 1)
if test "${lesser}" = "${1}"; then
# ${1} <= ${2}
return 0
fi
# ${1} > ${2}
return 1
}
# Print usage.
print_usage() {
printf \
'Usage: %s {{options}}
Options:
[-i|--install] install meson and ninja to gobal scope. attempts to acquire root privileges
[-l|--latest] use latest meson instead of %s
[-v|--venv] use venv instead of pyinstaller
[-h|--help] print usage (this text)
' \
"$(basename "${0}")" "${meson_version}"
}
# Parse parameters.
while test ${#} -gt 0; do
case "${1}" in
'-i'|'--install') install=true ;;
'-l'|'--latest') latest=true ;;
'-v'|'--venv') use_venv=true ;;
'-h'|'--help') print_usage; exit 0 ;;
*) break ;;
esac; shift
done
# Default parameters
test -z "${install+x}" && install=false
test -z "${latest+x}" && latest=false
test -z "${use_venv+x}" && use_venv=false
if "${install}" && "${use_venv}"; then
sudo='sudo'
venv='/usr/local/share/.venv'
else
sudo=
venv='.venv'
fi
# Change directory to Kea's top level directory.
top_level=$(cd "$(dirname "${0}")" && pwd)
cd "${top_level}" || exit 1
if command -v meson > /dev/null 2>&1 && ! "${latest}" && le "${meson_version}" "$(meson --version)"; then
# Good to be used. Does not suffer from endless transitional dependency iteration fixed in 1.8.0.
meson='meson'
else
meson='.meson/meson'
if test ! -f "${meson}"; then
# Starting with Meson 0.62, Python 3.7 is required.
python3=python3
v=$(python3 -c 'import platform; print(platform.python_version())')
if ! le 3.7.0 "${v}"; then
# Search for a newer Python.
if command -V compgen >/dev/null; then
# shellcheck disable=SC3044
# SC3044 (warning): In POSIX sh, 'compgen' is undefined.
newer=$(compgen -c python3 | grep -E '^python3.[0-9]+$' | sort -V | tail -n 1)
if test -n "${newer}"; then
python3="${newer}"
fi
fi
fi
v=$("${python3}" -c 'import platform; print(platform.python_version())')
printf 'Python version: %s\n' "${v}"
${sudo} "${python3}" -m venv "${venv}"
${sudo} "${venv}/bin/pip" install --upgrade pip
${sudo} "${venv}/bin/pip" install ninja
mkdir -p .meson
${sudo} cp "${venv}/bin/ninja" .meson/ninja
if "${use_venv}"; then
if "${latest}"; then
${sudo} "${venv}/bin/pip" install git+https://github.com/mesonbuild/meson.git
else
${sudo} "${venv}/bin/pip" install "meson==${meson_version}"
fi
${sudo} cp "${venv}/bin/meson" .meson/meson
else
if test ! -d .meson-src; then
git clone https://github.com/mesonbuild/meson .meson-src
fi
if ! "${latest}"; then
(
cd .meson-src || exit 1
git checkout "${meson_version}"
)
fi
${sudo} "${venv}/bin/pip" install pyinstaller
(
cd .meson-src || exit 1
"${top_level}/${venv}/bin/pyinstaller" --additional-hooks-dir=packaging --clean --dist "${top_level}/.meson" --onefile ./meson.py
)
rm -fr .meson-src "${venv}"
fi
fi
fi
if "${install}"; then
sudo cp .meson/meson /usr/local/bin/meson
sudo cp .meson/ninja /usr/local/bin/ninja
rm -fr .meson
exit 0
fi
if test -f "${top_level}/.meson/ninja"; then
# To find ninja in case it went with the pyinstalled version.
export PATH="${top_level}/.meson:${PATH}"
fi
"${meson}" "${@}"