1
1
#! /usr/bin/env bash
2
2
set -e
3
- trap restore_root ERR
4
3
ORG_PWD=" $PWD "
4
+ SELF_PATH=" $( realpath $0 ) "
5
+ SCRIPT_DIR=" $( dirname " $SELF_PATH " ) "
5
6
6
7
REPO=" $HOME /work/openpilot/openpilot"
7
8
CACHE_ROOTFS_TARBALL_PATH=" /tmp/rootfs_cache.tar"
8
9
9
- unpack_rootfs_tarball () {
10
- cd /
11
- sudo tar -xf " $CACHE_ROOTFS_TARBALL_PATH " 2> /dev/null || true
12
- cd
13
- }
14
-
15
- commit_root () {
16
- sudo mkdir -p /base /newroot /upper /work
17
-
18
- sudo unshare -f --kill-child -m $ORG_PWD /selfdrive/test/build.sh build_inside_namespace
19
- ec=$?
20
- echo " end of ns"
21
-
22
- sudo rm -rf /base /newroot /work
23
-
24
- # finally, create the rootfs diff tarball (to be pushed into the CI native cache)
25
- mkdir -p /tmp/rootfs_cache
26
- sudo rm -f " $CACHE_ROOTFS_TARBALL_PATH " # remove the old tarball from previous run, if exists
27
- cd /upper
28
- sudo tar -cf " $CACHE_ROOTFS_TARBALL_PATH " .
29
- cd
30
-
31
- sudo rm -rf /upper
32
-
33
- unpack_rootfs_tarball
34
-
35
- # before the next tasks are run, finalize the environment for them
36
- prepare_mounts
37
-
38
- exit $ec
39
- }
40
-
41
- prepare_mounts () {
42
- # create and mount the required volumes where they're expected
43
- mkdir -p /tmp/openpilot /tmp/scons_cache /tmp/comma_download_cache /tmp/openpilot_cache
44
- sudo mount --bind " $REPO " /tmp/openpilot
45
-
46
- sudo mount --bind " $REPO /.ci_cache/scons_cache" /tmp/scons_cache || true
47
- sudo mount --bind " $REPO /.ci_cache/comma_download_cache" /tmp/comma_download_cache || true
48
- sudo mount --bind " $REPO /.ci_cache/openpilot_cache" /tmp/openpilot_cache || true
49
-
50
- # needed for the unit tests not to fail
51
- sudo chmod 755 /sys/fs/pstore
52
- }
53
-
54
- restore_root () {
55
- echo failed at ${BASH_LINENO[0]}
56
- }
57
-
58
- build_inside_namespace () {
59
- mount --bind / /base
60
- mount -t overlay overlay -o lowerdir=/base,upperdir=/upper,workdir=/work /newroot
61
- rm -f /newroot/etc/resolv.conf
62
- touch /newroot/etc/resolv.conf
63
- cat /etc/resolv.conf > /newroot/etc/resolv.conf
64
-
65
- mkdir -p /newroot/old
66
- cd /newroot
67
- pivot_root . old
68
-
69
- mount -t proc proc /proc
70
- mount -t devtmpfs devtmpfs /dev
71
- mkdir -p /dev/pts
72
- mount -t devpts devpts /dev/pts
73
- mount -t proc proc /proc
74
- mount -t sysfs sysfs /sys
75
-
76
- touch /root_committed
77
- sudo -u runner /home/runner/work/openpilot/openpilot/selfdrive/test/build.sh
78
- ec=$?
79
- exit $ec
80
- }
81
-
82
- if [ " $1 " = " build_inside_namespace" ]
83
- then
84
- build_inside_namespace
85
- exit
86
- fi
10
+ source " $SCRIPT_DIR /build_common.sh"
87
11
12
+ # if the rootfs diff tarball (also created by this script) got restored from the CI native cache
88
13
if [ -f " $CACHE_ROOTFS_TARBALL_PATH " ]
89
14
then
90
- # if the rootfs diff tarball (also created by this script) got restored from the CI native cache, unpack it, upgrading the rootfs
15
+ # apply it, upgrading the rootfs
91
16
echo " restoring rootfs from the native build cache"
92
- unpack_rootfs_tarball
17
+ apply_rootfs_diff
93
18
rm " $CACHE_ROOTFS_TARBALL_PATH "
94
19
95
20
# before the next tasks are run, finalize the environment for them
96
- prepare_mounts
21
+ prepare_build
97
22
98
23
# EXITS HERE - if the rootfs could been prepared entirely from the cache, there's no need for any further action like re-building
99
24
exit 0
100
25
else
101
26
# otherwise, we'll have to install everything from scratch and build the tarball to be available for the next run
102
- echo " no native build cache entry restored, rebuilding"
27
+ if ! [ -f /root_committed ]
28
+ then
29
+ echo " no native build cache entry restored, rebuilding"
30
+ fi
103
31
fi
104
32
105
- # in order to be able to build a diff rootfs tarball, we need to commit its initial state by moving it on-the-fly to overlayfs;
106
- # below, we prepare the system and the new rootfs itself
107
-
108
- if ! [ -e /root_committed ]
109
- then
33
+ # in order to be able to build a diff rootfs tarball, we need to commit its initial state
34
+ # by moving it on-the-fly to overlayfs; below, we prepare the system and the new rootfs itself
110
35
commit_root
111
- fi
112
36
113
37
# -------- at this point, the original rootfs was committed and all the changes to it done below will be saved to the newly created rootfs diff tarball --------
114
38
@@ -118,11 +42,11 @@ DEBIAN_FRONTEND=noninteractive
118
42
119
43
mkdir -p /tmp/tools
120
44
cp " $REPO /tools/install_ubuntu_dependencies.sh" /tmp/tools/
121
- sudo /tmp/tools/install_ubuntu_dependencies.sh & > /dev/null
45
+ sudo /tmp/tools/install_ubuntu_dependencies.sh
122
46
123
47
sudo apt-get install -y --no-install-recommends \
124
48
sudo tzdata locales ssh pulseaudio xvfb x11-xserver-utils gnome-screenshot python3-tk python3-dev \
125
- apt-utils alien unzip tar curl xz-utils dbus gcc-arm-none-eabi tmux vim libx11-6 wget & > /dev/null
49
+ apt-utils alien unzip tar curl xz-utils dbus gcc-arm-none-eabi tmux vim libx11-6 wget
126
50
127
51
sudo rm -rf /var/lib/apt/lists/*
128
52
sudo apt-get clean
@@ -155,7 +79,6 @@ sudo ln -s /opt/intel/oneapi-tbb-2021.12.0/lib/intel64/gcc4.8/libtbbmalloc.so.2
155
79
sudo mkdir -p /etc/ld.so.conf.d
156
80
sudo bash -c " echo /opt/intel/oclcpuexp_2024.17.3.0.09_rel/x64 > /etc/ld.so.conf.d/libintelopenclexp.conf"
157
81
sudo ldconfig -f /etc/ld.so.conf.d/libintelopenclexp.conf
158
- cd /
159
82
rm -rf /tmp/opencl-driver-intel
160
83
cd
161
84
@@ -166,18 +89,16 @@ NVIDIA_DRIVER_CAPABILITIES=graphics,utility,compute
166
89
QTWEBENGINE_DISABLE_SANDBOX=1
167
90
168
91
# install and set up the Python dependencies needed
169
- sudo cp " /home/runner/work/openpilot/openpilot/pyproject.toml" " /home/runner/work/openpilot/openpilot/uv.lock" " /home/runner/work/openpilot/openpilot/tools/install_python_dependencies.sh" \
170
- /home/runner/
92
+ cp " $REPO /pyproject.toml" " $REPO /uv.lock" " $HOME /"
93
+ mkdir " $HOME /tools"
94
+ cp " $REPO /tools/install_python_dependencies.sh" " $HOME /tools/"
171
95
172
- cd
173
- rm -rf .venv
96
+ VIRTUAL_ENV=/home/ $USER /.venv
97
+ PATH= " $VIRTUAL_ENV /bin: $PATH "
174
98
175
- mkdir aaa
176
- cd aaa
177
- ../install_python_dependencies.sh
178
99
cd
179
- rm pyproject.toml uv.lock install_python_dependencies.sh
180
-
100
+ tools/ install_python_dependencies.sh
101
+ rm -rf tools/ pyproject.toml uv.lock .cache
181
102
182
103
# add a git safe directory for compiling openpilot
183
104
sudo git config --global --add safe.directory /tmp/openpilot
0 commit comments