diff options
author | Maxim Biro <nurupo.contributions@gmail.com> | 2018-07-08 10:22:32 -0400 |
---|---|---|
committer | Maxim Biro <nurupo.contributions@gmail.com> | 2018-07-15 18:37:10 -0400 |
commit | c0b4cd156f79f1c7f3ce747a27cae16a78549cc6 (patch) | |
tree | cc1254c5c5b2e7fa5cce5415d450b1c6e59de42c /.travis | |
parent | b4cf9808e972952c003c80b9e766b8e66e671703 (diff) |
Simplify Travis-CI FreeBSD build
Diffstat (limited to '.travis')
-rw-r--r-- | .travis/cmake-freebsd-env.sh | 10 | ||||
-rwxr-xr-x | .travis/cmake-freebsd-install.sh | 89 | ||||
-rwxr-xr-x | .travis/cmake-freebsd-stage1 | 170 | ||||
-rwxr-xr-x | .travis/cmake-freebsd-stage2 | 65 |
4 files changed, 323 insertions, 11 deletions
diff --git a/.travis/cmake-freebsd-env.sh b/.travis/cmake-freebsd-env.sh new file mode 100644 index 00000000..8ae7e738 --- /dev/null +++ b/.travis/cmake-freebsd-env.sh | |||
@@ -0,0 +1,10 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | NPROC=`nproc` | ||
4 | |||
5 | SCREEN_SESSION=freebsd | ||
6 | SSH_PORT=10022 | ||
7 | |||
8 | RUN() { | ||
9 | ssh -t -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p $SSH_PORT "$@" | ||
10 | } | ||
diff --git a/.travis/cmake-freebsd-install.sh b/.travis/cmake-freebsd-install.sh new file mode 100755 index 00000000..59a78965 --- /dev/null +++ b/.travis/cmake-freebsd-install.sh | |||
@@ -0,0 +1,89 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | # Travis doesn't provide FreeBSD machines, so we just take a Linux one and run | ||
4 | # FreeBSD in qemu virtual machine. qemu is being ran in curses mode inside a | ||
5 | # screen session, because screen allows to easily send input and read output. | ||
6 | # The input is sent using `screen -S session-name -X stuff ...` and the output | ||
7 | # is read from the screen's log file. Note that for some reason you can't send | ||
8 | # long input lines on Travis (it works just fine when I do it on my machine...), | ||
9 | # but that limitation is not an issue, as we don't really need to send long | ||
10 | # lines of input anyway. Also, note that since we run qemu in curses mode, the | ||
11 | # output contains control characters intended for a terminal emulator telling | ||
12 | # how to position and color the text, so it might be a little tricky to read it | ||
13 | # sometimes. The only time when this script has to send input to and read the | ||
14 | # output from the screen session is during the initial setup when we setup the | ||
15 | # network, install and configure the ssh server, and update the system. After | ||
16 | # this initial setup, ssh is used to communicate with the FreeBSD running in the | ||
17 | # VM, which is a lot friendlier way of communication. Please note that Travis | ||
18 | # doesn't seem to allow KVM passthrough, so qemu has to emulate all the | ||
19 | # hardware, which makes it quite slow compared to the host machine. We cache | ||
20 | # the qemu image since it takes a long time to run the initial system and | ||
21 | # package updates, and we do incremental system and package updates on every | ||
22 | # change to the list of git tags (i.e. on every toxcore release, presumably). | ||
23 | |||
24 | sudo apt-get update | ||
25 | sudo apt-get install -y qemu | ||
26 | |||
27 | OLD_PWD="$PWD" | ||
28 | |||
29 | mkdir -p /opt/freebsd/cache | ||
30 | cd /opt/freebsd/cache | ||
31 | |||
32 | # Make sure to update DL_SHA512 when bumping the version | ||
33 | FREEBSD_VERSION="11.2" | ||
34 | IMAGE_NAME=FreeBSD-${FREEBSD_VERSION}-RELEASE-amd64.raw | ||
35 | |||
36 | # Sends keys to the VM as they are | ||
37 | send_keys() | ||
38 | { | ||
39 | screen -S $SCREEN_SESSION -X stuff "$1" | ||
40 | } | ||
41 | |||
42 | # Blocks until a specific text appears on VM's screen | ||
43 | wait_for() | ||
44 | { | ||
45 | while ! grep -q "$1" screenlog.0 | ||
46 | do | ||
47 | sleep 1 | ||
48 | done | ||
49 | } | ||
50 | |||
51 | # Starts VM and waits until it's fully running (until a login prompt is shown) | ||
52 | start_vm() | ||
53 | { | ||
54 | rm -f screenlog.0 | ||
55 | |||
56 | # Start emulator. 2000mb RAM should be enough, right? The build machine has over 7gb. | ||
57 | screen -L -S $SCREEN_SESSION -d -m \ | ||
58 | qemu-system-x86_64 -curses -m 2000 -smp $NPROC \ | ||
59 | -net user,hostfwd=tcp::${SSH_PORT}-:22 -net nic "$IMAGE_NAME" | ||
60 | |||
61 | # Wait for the boot screen options | ||
62 | wait_for "Autoboot in" | ||
63 | |||
64 | # Select the 1st option | ||
65 | send_keys ' | ||
66 | ' | ||
67 | |||
68 | # Wait for the system to boot and present the login prompt | ||
69 | wait_for "FreeBSD/amd64 (" | ||
70 | } | ||
71 | |||
72 | # Shuts VM down and waits until its process finishes | ||
73 | stop_vm() | ||
74 | { | ||
75 | # Turn it off | ||
76 | send_keys 'poweroff | ||
77 | ' | ||
78 | |||
79 | # Wait for qemu process to terminate | ||
80 | while ps aux | grep qemu | grep -vq grep | ||
81 | do | ||
82 | sleep 1 | ||
83 | done | ||
84 | } | ||
85 | |||
86 | # Let's see what's in the cache directory | ||
87 | ls -lh | ||
88 | |||
89 | cd "$OLD_PWD" | ||
diff --git a/.travis/cmake-freebsd-stage1 b/.travis/cmake-freebsd-stage1 index 3954e2af..d1aeab62 100755 --- a/.travis/cmake-freebsd-stage1 +++ b/.travis/cmake-freebsd-stage1 | |||
@@ -2,14 +2,174 @@ | |||
2 | 2 | ||
3 | ACTION="$1" | 3 | ACTION="$1" |
4 | 4 | ||
5 | set -eu | 5 | set -eux |
6 | 6 | ||
7 | . other/travis/env.sh | 7 | . .travis/cmake-freebsd-env.sh |
8 | . other/travis/env-freebsd.sh | ||
9 | 8 | ||
10 | travis_install() { | 9 | travis_install() { |
11 | . other/travis/freebsd-install | 10 | . .travis/cmake-freebsd-install.sh |
12 | . other/travis/freebsd-install-stage1 | 11 | |
12 | git tag -l --sort=version:refname > GIT_TAGS | ||
13 | |||
14 | OLD_PWD="$PWD" | ||
15 | |||
16 | mkdir -p /opt/freebsd/cache | ||
17 | cd /opt/freebsd/cache | ||
18 | |||
19 | # === Get the VM image, set it up and cache === | ||
20 | |||
21 | # Create image if it's not cached or if this build script has changed | ||
22 | sha256sum "$OLD_PWD/.travis/cmake-freebsd-env.sh" > /tmp/sha | ||
23 | sha256sum "$OLD_PWD/.travis/cmake-freebsd-install.sh" >> /tmp/sha | ||
24 | sha256sum "$OLD_PWD/.travis/cmake-freebsd-stage1" >> /tmp/sha | ||
25 | if [ ! -f "./$IMAGE_NAME.tgz" ] || [ ! -f ./cmake-freebsd-stage1-all.sha256 ] || [ "`cat cmake-freebsd-stage1-all.sha256`" != "`cat /tmp/sha`" ]; then | ||
26 | |||
27 | rm -rf ./* | ||
28 | |||
29 | # https://download.freebsd.org/ftp/releases/VM-IMAGES/11.2-RELEASE/amd64/Latest/ | ||
30 | DL_SHA512="0c3c232c7023c5036daeb5fbf68c2ddecf9703c74e317afcf19da91e83d0afcc526785571e2868894ce15cdb56b74fafa1ce9fd216469db91e021ac2ef8911e5" | ||
31 | # Selecting random mirror from https://www.freebsd.org/doc/handbook/mirrors-ftp.html | ||
32 | # Note that not all mirrors listed on that page are working, so we have removed them | ||
33 | # I'm so sorry, there are no arrays in sh and we are not using bash... | ||
34 | DL_MIRROR_1=1 | ||
35 | DL_MIRROR_2=4 | ||
36 | # There are 2 mirrors | ||
37 | DL_MIRROR_RANDOM=`expr $(date +%s) % 2 + 1` | ||
38 | DL_URL="ftp://ftp$(eval echo \$DL_MIRROR_$DL_MIRROR_RANDOM).us.freebsd.org/pub/FreeBSD/releases/VM-IMAGES/${FREEBSD_VERSION}-RELEASE/amd64/Latest/${IMAGE_NAME}.xz" | ||
39 | |||
40 | wget "$DL_URL" | ||
41 | |||
42 | if ! ( echo "$DL_SHA512 $IMAGE_NAME.xz" | sha512sum -c --status - ) ; then | ||
43 | echo "Error: sha512 of $IMAGE_NAME.xz doesn't match the known one" | ||
44 | exit 1 | ||
45 | fi | ||
46 | |||
47 | unxz "$IMAGE_NAME.xz" | ||
48 | |||
49 | # With this we don't have to guess how long a command will run for and sleeping | ||
50 | # for that amount of time, risking either under sleeping or over sleeping, instead | ||
51 | # we will sleep exactly until the command is finished by printing out a unique | ||
52 | # string after the command is executed and then checking if it was printed. | ||
53 | execute_shell_and_wait() | ||
54 | { | ||
55 | # $RANDOM is a bash built-in, so we try to avoid name collision here by using ugly RANDOM_STR name | ||
56 | RANDOM_STR=$(< /dev/urandom tr -dc _A-Za-z0-9 | head -c16) | ||
57 | send_keys "$1;echo $RANDOM_STR | ||
58 | |||
59 | " | ||
60 | # \[1B is a control escape sequence for a new line in the terminal. | ||
61 | # We want to wait for <new-line>$RANDOM_STR instead of just $RANDOM_STR because | ||
62 | # $RANDOM_STR we have inputted with send_keys above would appear in the screenlog.0 | ||
63 | # file and we don't want to match our input, we want to match the echo's output. | ||
64 | # The .\? optionally matches any character. Sometimes it happens that there is some | ||
65 | # random character inserved between the new line control escape sequence and $RANDOM_STR. | ||
66 | wait_for "\[1B.\?$RANDOM_STR" | ||
67 | } | ||
68 | |||
69 | start_vm | ||
70 | |||
71 | # Login as root user | ||
72 | send_keys 'root | ||
73 | |||
74 | ' | ||
75 | |||
76 | # Wait for the prompt | ||
77 | wait_for "root@.*:~" | ||
78 | |||
79 | # Configure network, ssh and start changing password | ||
80 | execute_shell_and_wait 'echo "ifconfig_em0=DHCP" >> /etc/rc.conf' | ||
81 | execute_shell_and_wait 'echo "Port 22" >> /etc/ssh/sshd_config' | ||
82 | execute_shell_and_wait 'echo "PermitRootLogin yes" >> /etc/ssh/sshd_config' | ||
83 | execute_shell_and_wait 'echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config' | ||
84 | execute_shell_and_wait 'echo "PermitEmptyPasswords yes" >> /etc/ssh/sshd_config' | ||
85 | execute_shell_and_wait 'echo "sshd_enable=YES" >> /etc/rc.conf' | ||
86 | send_keys 'sh /etc/rc.d/netif restart && sh /etc/rc.d/sshd start && passwd | ||
87 | ' | ||
88 | |||
89 | # Wait for the password prompt | ||
90 | wait_for "Changing local password for root" | ||
91 | |||
92 | # Reset password to empty for the passwordless ssh to work | ||
93 | send_keys ' | ||
94 | ' | ||
95 | wait_for "New Password" | ||
96 | send_keys ' | ||
97 | ' | ||
98 | |||
99 | # Update system | ||
100 | RUN env PAGER=cat env ASSUME_ALWAYS_YES=YES freebsd-update --not-running-from-cron fetch | ||
101 | # It fails if there is nothing to install, so we make it always succeed with true | ||
102 | RUN env PAGER=cat env ASSUME_ALWAYS_YES=YES freebsd-update --not-running-from-cron install || true | ||
103 | |||
104 | # Update packages | ||
105 | RUN env PAGER=cat env ASSUME_ALWAYS_YES=YES pkg upgrade | ||
106 | |||
107 | # Install and set bash as the default shell for the root user | ||
108 | RUN env PAGER=cat env ASSUME_ALWAYS_YES=YES pkg install bash | ||
109 | RUN chsh -s /usr/local/bin/bash root | ||
110 | |||
111 | # Install required toxcore dependencies | ||
112 | RUN PAGER=cat ASSUME_ALWAYS_YES=YES pkg install git \ | ||
113 | opus \ | ||
114 | libvpx \ | ||
115 | libsodium \ | ||
116 | gmake \ | ||
117 | cmake \ | ||
118 | pkgconf \ | ||
119 | opencv \ | ||
120 | portaudio \ | ||
121 | libsndfile \ | ||
122 | texinfo \ | ||
123 | autotools | ||
124 | |||
125 | # === Cache the VM image === | ||
126 | |||
127 | stop_vm | ||
128 | |||
129 | # Create cache | ||
130 | tar -Sczvf "$IMAGE_NAME.tgz" "$IMAGE_NAME" | ||
131 | rm "$IMAGE_NAME" | ||
132 | rm screenlog.0 | ||
133 | |||
134 | cp "$OLD_PWD/GIT_TAGS" . | ||
135 | sha256sum "$OLD_PWD/.travis/cmake-freebsd-env.sh" > cmake-freebsd-stage1-all.sha256 | ||
136 | sha256sum "$OLD_PWD/.travis/cmake-freebsd-install.sh" >> cmake-freebsd-stage1-all.sha256 | ||
137 | sha256sum "$OLD_PWD/.travis/cmake-freebsd-stage1" >> cmake-freebsd-stage1-all.sha256 | ||
138 | |||
139 | ls -lh | ||
140 | fi | ||
141 | |||
142 | # === Update the image on new version (tag) of toxcore === | ||
143 | |||
144 | if ! diff -u ./GIT_TAGS "$OLD_PWD/GIT_TAGS" ; then | ||
145 | # Extract the cached image | ||
146 | tar -Sxzvf "$IMAGE_NAME.tgz" | ||
147 | |||
148 | start_vm | ||
149 | |||
150 | # Update system | ||
151 | RUN PAGER=cat ASSUME_ALWAYS_YES=YES freebsd-update --not-running-from-cron fetch | ||
152 | RUN PAGER=cat ASSUME_ALWAYS_YES=YES freebsd-update --not-running-from-cron install || true | ||
153 | |||
154 | # Update packages | ||
155 | RUN PAGER=cat ASSUME_ALWAYS_YES=YES pkg upgrade | ||
156 | |||
157 | # === Cache the updated VM image === | ||
158 | |||
159 | stop_vm | ||
160 | |||
161 | # Create/Update cache | ||
162 | rm "$IMAGE_NAME.tgz" | ||
163 | tar -Sczvf "$IMAGE_NAME.tgz" "$IMAGE_NAME" | ||
164 | rm "$IMAGE_NAME" | ||
165 | rm screenlog.0 | ||
166 | |||
167 | cp "$OLD_PWD/GIT_TAGS" . | ||
168 | |||
169 | ls -lh | ||
170 | fi | ||
171 | |||
172 | cd "$OLD_PWD" | ||
13 | } | 173 | } |
14 | 174 | ||
15 | travis_script() { | 175 | travis_script() { |
diff --git a/.travis/cmake-freebsd-stage2 b/.travis/cmake-freebsd-stage2 index 57b8a0f8..92e681f0 100755 --- a/.travis/cmake-freebsd-stage2 +++ b/.travis/cmake-freebsd-stage2 | |||
@@ -2,18 +2,71 @@ | |||
2 | 2 | ||
3 | ACTION="$1" | 3 | ACTION="$1" |
4 | 4 | ||
5 | set -eu | 5 | set -eux |
6 | 6 | ||
7 | . other/travis/env.sh | 7 | . .travis/cmake-freebsd-env.sh |
8 | . other/travis/env-freebsd.sh | ||
9 | 8 | ||
10 | travis_install() { | 9 | travis_install() { |
11 | . other/travis/freebsd-install | 10 | . .travis/cmake-freebsd-install.sh |
12 | . other/travis/freebsd-install-stage2 | 11 | |
12 | OLD_PWD="$PWD" | ||
13 | |||
14 | mkdir -p /opt/freebsd/cache | ||
15 | cd /opt/freebsd/cache | ||
16 | |||
17 | # Extract the cached image | ||
18 | tar -Sxzvf "$IMAGE_NAME.tgz" | ||
19 | |||
20 | # Get the image we will be using out of the cached directory | ||
21 | mv "$IMAGE_NAME" .. | ||
22 | ls -lh | ||
23 | |||
24 | cd .. | ||
25 | |||
26 | ls -lh | ||
27 | |||
28 | # === Get VM ready to build the code === | ||
29 | |||
30 | start_vm | ||
31 | |||
32 | # Display FreeBSD kernel info and last login | ||
33 | RUN uname -a | ||
34 | RUN last | ||
35 | |||
36 | cd "$OLD_PWD" | ||
37 | |||
38 | # Copy over toxcore code from Travis to qemu | ||
39 | scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -P $SSH_PORT -r ./* root@localhost:~ | ||
40 | |||
41 | RUN ls -lh | ||
13 | } | 42 | } |
14 | 43 | ||
15 | travis_script() { | 44 | travis_script() { |
16 | . other/travis/toxcore-script | 45 | CACHEDIR="none" |
46 | . ".travis/flags-$CC.sh" | ||
47 | |||
48 | add_ld_flag -Wl,-z,defs | ||
49 | |||
50 | # Make compilation error on a warning | ||
51 | add_flag -Werror | ||
52 | |||
53 | RUN 'cmake -B_build -H. \ | ||
54 | -DCMAKE_C_FLAGS="$C_FLAGS" \ | ||
55 | -DCMAKE_CXX_FLAGS="$CXX_FLAGS" \ | ||
56 | -DCMAKE_EXE_LINKER_FLAGS="$LD_FLAGS" \ | ||
57 | -DCMAKE_SHARED_LINKER_FLAGS="$LD_FLAGS" \ | ||
58 | -DCMAKE_INSTALL_PREFIX:PATH="_install" \ | ||
59 | -DTRACE=ON \ | ||
60 | -DMUST_BUILD_TOXAV=ON \ | ||
61 | -DSTRICT_ABI=ON \ | ||
62 | -DTEST_TIMEOUT_SECONDS=120 \ | ||
63 | -DUSE_IPV6=OFF' | ||
64 | |||
65 | # We created the VM with the same number of cores as the host, so the host-ran `nproc` here is fine | ||
66 | RUN 'gmake "-j$NPROC" -k install -C_build' | ||
67 | RUN 'gmake "-j$NPROC" test ARGS="-j50" -C_build || \ | ||
68 | gmake "-j$NPROC" -C_build test ARGS="-j50 --rerun-failed" CTEST_OUTPUT_ON_FAILURE=1 || \ | ||
69 | true' | ||
17 | } | 70 | } |
18 | 71 | ||
19 | if [ "-z" "$ACTION" ]; then | 72 | if [ "-z" "$ACTION" ]; then |