forked from Qorvo/QMatter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
271 lines (227 loc) · 7.79 KB
/
bootstrap.sh
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/bin/bash
set -ex
SCRIPT_PATH="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
VENV_PATH=$(realpath "${SCRIPT_PATH}/../.python_venv")
QMATTER_ROOT_PATH=$(realpath "${SCRIPT_PATH}/..")
trap 'on_error $? $LINENO' ERR
on_error() {
echo "!!! $SCRIPT_PATH failed with error $1 on line $2"
exit "$1"
}
DEFAULT_TOOLCHAIN_DIR=/opt/TOOL_ARMGCCEMB/gcc-arm-none-eabi-9-2019-q4-major
export PATH=$PATH:$DEFAULT_TOOLCHAIN_DIR/bin:${SCRIPT_PATH}/../Tools/FactoryData
export MAKEFLAGS=-s
/proc/self/exe --version 2>/dev/null | grep -q 'GNU bash' || (\
echo "!!!!! This is a BASH script !!!!!"; \
echo "The shell you are running is $(/proc/self/exe --version)"; \
echo "Please start bash first by running the 'bash' command"; \
echo "Press Ctrl-C to abort"; \
read -r \
)
log() {
echo "$(realpath "${BASH_SOURCE[0]}") ========= ${1} ============"
}
bootstrap_sh_failure() {
echo "========= ${1} ============"
}
check_installed_dependency ()
{
$1 --version foo >/dev/null 2>&1 || {
echo >&2 "$1 not installed. installing........"
return 1
}
return 0
}
install_node_npm ()
{
sudo apt-get update
### Node.js v16 ###
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo bash -
sudo apt install -y nodejs
# the 'installed-check' package checks package.json is fulfilled
if ! npm list installed-check &>/dev/null; then
npm install installed-check
fi
if ! ./node_modules/.bin/installed-check -c &>/dev/null; then
npm install
fi
}
install_zap_dependencies ()
{
sudo apt-get update
sudo apt-get install -y clang-format npm
sudo apt-get install -y --fix-missing libpixman-1-dev libcairo-dev libsdl-pango-dev libjpeg-dev libgif-dev
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo bash -
sudo apt install -y nodejs
if ! npm list installed-check &>/dev/null; then
npm install installed-check
fi
if ! ./node_modules/.bin/installed-check -c &>/dev/null; then
npm install
fi
}
install_arm_gcc_emb ()
{
sudo apt install bzip2
wget -P /tmp --progress=dot:giga https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2
sudo mkdir -p /opt/TOOL_ARMGCCEMB
sudo tar -xf /tmp/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2 -C /opt/TOOL_ARMGCCEMB
rm /tmp/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2
}
install_gn ()
{
git clone https://gn.googlesource.com/gn /tmp/gn
python3 /tmp/gn/build/gen.py --out-path=/tmp/gn/out
ninja -C /tmp/gn/out
sudo cp /tmp/gn/out/gn /usr/local/bin/gn
sudo chmod +x /usr/local/bin/gn
}
install_rsync ()
{
sudo apt-get install -y --no-install-recommends rsync
}
setup_venv ()
{
Var=$(lsb_release -r)
NumOnly=$(cut -f2 <<< "$Var")
#check ubuntu version
if [[ "$NumOnly" == 22.04 ]]; then
sudo apt-get install --yes software-properties-common
sudo apt-get update
sudo add-apt-repository --yes ppa:deadsnakes/ppa
sudo apt-get update
fi
sudo apt install -y python3.9
# required for gn exec_script
sudo apt install -y python-is-python3
#check openssl minversion
export openssl_minversion=1.1.1
# if minversion is not the first in the result, install the deb file
if ! echo -e "$(openssl version|awk '{print $2}')\n${openssl_minversion}" | sort -V | head -1 | grep -q ${openssl_minversion}
then
rm libssl1.1_1.1.1f-1ubuntu2.16_amd64.deb || true
wget http://nz2.archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.16_amd64.deb
sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2.16_amd64.deb
rm libssl1.1_1.1.1f-1ubuntu2.16_amd64.deb
fi
python3.9 -m venv --help >/dev/null 2>&1 || sudo apt-get install -y python3.9-venv
python3.9 -m ensurepip --help >/dev/null 2>&1 || sudo apt-get install -y python3.9-venv
if [[ ! -d ${VENV_PATH} ]]; then
mkdir -p "${VENV_PATH}"
fi
python3.9 -m venv "${VENV_PATH}"
export VENV_PATH
# shellcheck source=/dev/null
source "${VENV_PATH}"/bin/activate
log "$(python -V)"
# Install additional modules
pip3 install wheel dataclasses intelhex click ecdsa cryptography lark jinja2 stringcase pigweed PrettyTable Cheetah3
}
setup_submodules ()
{
# QMatter '-libs' variant lacks the matter submodule to avoid
# a recursive dependency in project-chip/connectedhomeip
# For Qorvo-internal CI testing, we add this at validation time
if test -e "${SCRIPT_PATH}/git_add_submodules.sh" && test ! -e "${QMATTER_ROOT_PATH}/Components/ThirdParty/Matter/repo/.gitmodules"
then
log "Adding submodules to allow package validation"
# shellcheck source=/dev/null
source "${SCRIPT_PATH}/git_add_submodules.sh"
fi
log "Updating submodules"
git submodule update --init --depth=1 Components/ThirdParty/Matter/repo
cd Components/ThirdParty/Matter/repo || (bootstrap_sh_failure "chdir to matter repo failed"; exit 1)
# TODO: use Components/ThirdParty/Matter/repo/scripts/checkout_submodules.py --platform qpg
for module_path in \
third_party/nlfaultinjection \
third_party/jsoncpp \
third_party/libwebsockets \
third_party/editline \
third_party/mbedtls \
third_party/nlassert \
third_party/nlio \
third_party/nlunit-test \
third_party/freertos \
third_party/openthread \
third_party/pigweed \
third_party/qpg_sdk
do
git submodule update --init --depth=1 -- "${module_path}"
done
log "submodules successfully initialized"
}
install_spake2p ()
{
log "Installing spake2p build requirements"
cd "${QMATTER_ROOT_PATH}/Components/ThirdParty/Matter/repo" || (echo chdir to matter repo failed; exit 1)
# shellcheck source=/dev/null
source "${SCRIPT_PATH}/build_install_spake2p.sh"
}
install_zap()
{
ZAP_VERSION_FILE="${QMATTER_ROOT_PATH}/Components/ThirdParty/Matter/repo/scripts/setup/zap.json"
ZAP_VERSION=$(grep -E "v[0-9]+\.[0-9]+\.[0-9]+-nightly" -o "$ZAP_VERSION_FILE")
echo "found version: ${ZAP_VERSION}"
ZAP_INSTALL_PATH="/opt/zap-${ZAP_VERSION}"
if test -e "${ZAP_INSTALL_PATH}"
then
return
fi
sudo mkdir -p "${ZAP_INSTALL_PATH}"
cd "${ZAP_INSTALL_PATH}"
sudo wget --progress=dot:giga "https://github.com/project-chip/zap/releases/download/${ZAP_VERSION}/zap-linux.zip"
sudo apt install unzip
sudo unzip -o zap-linux.zip
sudo rm zap-linux.zip
# keep zap UI (don't delete it)
sudo rm /usr/bin/zap-cli || true
sudo ln -s "${ZAP_INSTALL_PATH}/zap-cli" /usr/bin/
# additional symlink to do the version check
sudo rm "/usr/bin/zap-cli-${ZAP_VERSION}" || true
sudo ln -s "${ZAP_INSTALL_PATH}/zap-cli" "/usr/bin/zap-cli-${ZAP_VERSION}"
}
command -v sudo || (
echo "Please enter your root password to install sudo."
su -c 'apt-get update; apt-get install -y sudo'
)
command sudo apt-get update
for tool_name in \
git \
clang \
make \
ninja \
curl \
wget
do
command -v "$tool_name" || sudo apt-get install -y "${tool_name}" || sudo apt-get install -y "${tool_name}-build"
done
if ! check_installed_dependency node; then
install_node_npm
fi
if check_installed_dependency arm-none-eabi-gcc
then
if ! arm-none-eabi-gcc --version | grep -F "9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599]" >/dev/null
then
echo "Invalid armgcc version detected"
exit 1
fi
else
install_arm_gcc_emb
fi
if ! check_installed_dependency gn; then
install_gn
fi
if ! check_installed_dependency npm; then
install_zap_dependencies
fi
if ! check_installed_dependency rsync; then
install_rsync
fi
setup_venv
setup_submodules
# requires setup_submodules
install_zap
if test ! -e /usr/bin/spake2p
then
install_spake2p
fi