Merge "ansible: Do not update jenkins node during ci-instances when not set"
[lttng-ci.git] / scripts / system-tests / check-build-needs.sh
CommitLineData
b3d73c46
FD
1#!/bin/bash -xeu
2# Copyright (C) 2016 - Francis Deslauriers <francis.deslauriers@efficios.com>
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
111565b0
JR
17# Version compare functions
18vercomp () {
19 set +u
20 if [[ "$1" == "$2" ]]; then
21 return 0
22 fi
23 local IFS=.
24 local i ver1=($1) ver2=($2)
25 # fill empty fields in ver1 with zeros
26 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
27 ver1[i]=0
28 done
29 for ((i=0; i<${#ver1[@]}; i++)); do
30 if [[ -z ${ver2[i]} ]]; then
31 # fill empty fields in ver2 with zeros
32 ver2[i]=0
33 fi
34 if ((10#${ver1[i]} > 10#${ver2[i]})); then
35 return 1
36 fi
37 if ((10#${ver1[i]} < 10#${ver2[i]})); then
38 return 2
39 fi
40 done
41 set -u
42 return 0
43}
44
45verlte() {
46 vercomp "$1" "$2"; local res="$?"
47 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
48}
49
50verlt() {
51 vercomp "$1" "$2"; local res="$?"
52 [ "$res" -eq "2" ]
53}
54
55vergte() {
56 vercomp "$1" "$2"; local res="$?"
57 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
58}
59
60vergt() {
61 vercomp "$1" "$2"; local res="$?"
62 [ "$res" -eq "1" ]
63}
64
65verne() {
66 vercomp "$1" "$2"; local res="$?"
67 [ "$res" -ne "0" ]
68}
69
b3d73c46
FD
70mkdir -p "$DEPLOYDIR"
71
72NEED_MODULES_BUILD=0
73NEED_KERNEL_BUILD=0
74
75set +e
76$SSH_COMMAND "$STORAGE_USER@$STORAGE_HOST" ls "$STORAGE_KERNEL_IMAGE"
77if [ $? -ne 0 ]; then
78 NEED_KERNEL_BUILD=1
79 # We need to build the lttng modules if the kernel has changed.
80 NEED_MODULES_BUILD=1
81fi
82
6d5c3948 83$S3_COMMAND info "s3://$S3_STORAGE_KERNEL_IMAGE"
6252703b
JR
84if [ $? -ne 0 ]; then
85 NEED_KERNEL_BUILD=1
86 # We need to build the lttng modules if the kernel has changed.
87 NEED_MODULES_BUILD=1
88fi
89
b3d73c46
FD
90$SSH_COMMAND "$STORAGE_USER@$STORAGE_HOST" ls "$STORAGE_LTTNG_MODULES"
91if [ $? -ne 0 ]; then
92 NEED_MODULES_BUILD=1
93fi
6252703b 94
6d5c3948 95$S3_COMMAND info "s3://$S3_STORAGE_LTTNG_MODULES"
6252703b
JR
96if [ $? -ne 0 ]; then
97 NEED_MODULES_BUILD=1
98fi
99
b3d73c46
FD
100set -e
101
102# We need to fetch the kernel source and lttng-modules to build either the
103# kernel or modules
104if [ $NEED_MODULES_BUILD -eq 1 ] || [ $NEED_KERNEL_BUILD -eq 1 ] ; then
6d2d0c69
JR
105 mkdir -p "$LINUX_PATH"
106 pushd "$LINUX_PATH"
107 git init
108 git remote add origin "$KGITREPO"
109 git fetch --depth 1 origin "$KERNEL_COMMIT_ID"
110 git checkout FETCH_HEAD
111565b0 111 version=$(make -s kernelversion)
6d2d0c69 112 popd
b3d73c46 113
111565b0
JR
114
115 # Prepare version string for comparison.
116 # Strip any '-rc tag'.
117 version=${version%%"-"*}
118
b33f21f4 119 cp src/lttng-ci/lava/kernel/vanilla/x86_64_server.config "$LINUX_PATH/.config"
b3d73c46 120 make --directory="$LINUX_PATH" olddefconfig
dc9700c9
FD
121
122 if [ $BUILD_DEVICE = 'kvm' ] ; then
111565b0
JR
123 if vergte "$version" "3.19"; then
124 make --directory="$LINUX_PATH" kvm_guest.config
125 else
126 make --directory="$LINUX_PATH" kvmconfig
127 fi
dc9700c9
FD
128 fi
129
41725171 130 make --directory="$LINUX_PATH" modules_prepare
b3d73c46
FD
131fi
132
133#We create files to specify what needs to be built for the subsequent build steps
134if [ $NEED_MODULES_BUILD -eq 0 ] ; then
135 touch modules-built.txt
136fi
137if [ $NEED_KERNEL_BUILD -eq 0 ] ; then
138 touch kernel-built.txt
139fi
This page took 0.032985 seconds and 4 git commands to generate.