| 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 | |
| 17 | # Version compare functions |
| 18 | vercomp () { |
| 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 | |
| 45 | verlte() { |
| 46 | vercomp "$1" "$2"; local res="$?" |
| 47 | [ "$res" -eq "0" ] || [ "$res" -eq "2" ] |
| 48 | } |
| 49 | |
| 50 | verlt() { |
| 51 | vercomp "$1" "$2"; local res="$?" |
| 52 | [ "$res" -eq "2" ] |
| 53 | } |
| 54 | |
| 55 | vergte() { |
| 56 | vercomp "$1" "$2"; local res="$?" |
| 57 | [ "$res" -eq "0" ] || [ "$res" -eq "1" ] |
| 58 | } |
| 59 | |
| 60 | vergt() { |
| 61 | vercomp "$1" "$2"; local res="$?" |
| 62 | [ "$res" -eq "1" ] |
| 63 | } |
| 64 | |
| 65 | verne() { |
| 66 | vercomp "$1" "$2"; local res="$?" |
| 67 | [ "$res" -ne "0" ] |
| 68 | } |
| 69 | |
| 70 | mkdir -p "$DEPLOYDIR" |
| 71 | |
| 72 | NEED_MODULES_BUILD=0 |
| 73 | NEED_KERNEL_BUILD=0 |
| 74 | |
| 75 | set +e |
| 76 | $SSH_COMMAND "$STORAGE_USER@$STORAGE_HOST" ls "$STORAGE_KERNEL_IMAGE" |
| 77 | if [ $? -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 |
| 81 | fi |
| 82 | |
| 83 | $S3_COMMAND info "s3://$S3_STORAGE_KERNEL_IMAGE" |
| 84 | if [ $? -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 |
| 88 | fi |
| 89 | |
| 90 | $SSH_COMMAND "$STORAGE_USER@$STORAGE_HOST" ls "$STORAGE_LTTNG_MODULES" |
| 91 | if [ $? -ne 0 ]; then |
| 92 | NEED_MODULES_BUILD=1 |
| 93 | fi |
| 94 | |
| 95 | $S3_COMMAND info "s3://$S3_STORAGE_LTTNG_MODULES" |
| 96 | if [ $? -ne 0 ]; then |
| 97 | NEED_MODULES_BUILD=1 |
| 98 | fi |
| 99 | |
| 100 | set -e |
| 101 | |
| 102 | # We need to fetch the kernel source and lttng-modules to build either the |
| 103 | # kernel or modules |
| 104 | if [ $NEED_MODULES_BUILD -eq 1 ] || [ $NEED_KERNEL_BUILD -eq 1 ] ; then |
| 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 |
| 111 | version=$(make -s kernelversion) |
| 112 | popd |
| 113 | |
| 114 | |
| 115 | # Prepare version string for comparison. |
| 116 | # Strip any '-rc tag'. |
| 117 | version=${version%%"-"*} |
| 118 | |
| 119 | cp src/lttng-ci/lava/kernel/vanilla/x86_64_server.config "$LINUX_PATH/.config" |
| 120 | make --directory="$LINUX_PATH" olddefconfig |
| 121 | |
| 122 | if [ $BUILD_DEVICE = 'kvm' ] ; then |
| 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 |
| 128 | fi |
| 129 | |
| 130 | make --directory="$LINUX_PATH" modules_prepare |
| 131 | fi |
| 132 | |
| 133 | #We create files to specify what needs to be built for the subsequent build steps |
| 134 | if [ $NEED_MODULES_BUILD -eq 0 ] ; then |
| 135 | touch modules-built.txt |
| 136 | fi |
| 137 | if [ $NEED_KERNEL_BUILD -eq 0 ] ; then |
| 138 | touch kernel-built.txt |
| 139 | fi |