blob: 931449a46382a3f11a7b55cdf9a8882628c8ba2c [file] [log] [blame]
Chris Smartf9ad3f92016-01-11 14:59:28 +11001#!/bin/bash
2
3# This build script is for running the Jenkins builds using docker.
4#
5
6# Trace bash processing
7#set -x
8
9# Default variables
10WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
11http_proxy=${http_proxy:-}
12
13# Timestamp for job
14echo "Build started, $(date)"
15
16# Configure docker build
17if [[ -n "${http_proxy}" ]]; then
18PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
19fi
20
21Dockerfile=$(cat << EOF
Joel Stanley5f4de952017-12-06 18:53:16 +103022FROM ubuntu:latest
Chris Smartf9ad3f92016-01-11 14:59:28 +110023
24${PROXY}
25
Chris Smart4593d4f2016-03-09 15:50:59 +110026ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +110027RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +110028 bc \
29 build-essential \
30 git \
31 gcc-powerpc64le-linux-gnu \
Saqib Khan5158a322017-10-23 11:31:24 -050032 software-properties-common \
Joel Stanley15a77ae2017-12-12 00:17:14 +103033 libssl-dev \
Saqib Khan5158a322017-10-23 11:31:24 -050034 iputils-ping
Chris Smart4593d4f2016-03-09 15:50:59 +110035
36RUN apt-add-repository -y multiverse && apt-get update && apt-get install -yy \
37 dwarves \
38 sparse
39
40RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
41RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smartf9ad3f92016-01-11 14:59:28 +110042
43USER ${USER}
44ENV HOME ${HOME}
45RUN /bin/bash
46EOF
47)
48
49# Build the docker container
50docker build -t linux-build/ubuntu - <<< "${Dockerfile}"
51if [[ "$?" -ne 0 ]]; then
52 echo "Failed to build docker container."
53 exit 1
54fi
55
56# Create the docker run script
57export PROXY_HOST=${http_proxy/#http*:\/\/}
58export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
59export PROXY_PORT=${http_proxy/#http*:\/\/*:}
60
61mkdir -p ${WORKSPACE}
62
63cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
64#!/bin/bash
65
66set -x
Michael Ellerman9872b7c2017-12-12 14:03:10 +110067set -e -o pipefail
Chris Smartf9ad3f92016-01-11 14:59:28 +110068
69cd ${WORKSPACE}
70
71# Go into the linux directory (the script will put us in a build subdir)
72cd linux
73
74# Record the version in the logs
Michael Ellerman9872b7c2017-12-12 14:03:10 +110075powerpc64le-linux-gnu-gcc --version
Chris Smartf9ad3f92016-01-11 14:59:28 +110076
Chris Smart78646622016-03-03 16:49:59 +110077# Build kernel prep
Michael Ellerman9872b7c2017-12-12 14:03:10 +110078ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make clean
79ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make mrproper
Chris Smart78646622016-03-03 16:49:59 +110080
81# Build kernel with debug
Michael Ellerman9872b7c2017-12-12 14:03:10 +110082ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make pseries_le_defconfig
Chris Smart78646622016-03-03 16:49:59 +110083echo "CONFIG_DEBUG_INFO=y" >> .config
Michael Ellerman9872b7c2017-12-12 14:03:10 +110084ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make olddefconfig
Chris Smart78646622016-03-03 16:49:59 +110085ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) -s C=2 CF=-D__CHECK_ENDIAN__ 2>&1 | gzip > sparse.log.gz
86pahole vmlinux 2>&1 | gzip > structs.dump.gz
87
88# Build kernel
Michael Ellerman9872b7c2017-12-12 14:03:10 +110089ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make pseries_le_defconfig
90ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc)
Chris Smartf9ad3f92016-01-11 14:59:28 +110091
92EOF_SCRIPT
93
94chmod a+x ${WORKSPACE}/build.sh
95
96# Run the docker container, execute the build script we just built
97docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
Michael Ellerman3225cfc2017-12-12 13:35:00 +110098 -w "${WORKSPACE}" -v "${WORKSPACE}":"${WORKSPACE}" -t linux-build/ubuntu ${WORKSPACE}/build.sh
Chris Smartf9ad3f92016-01-11 14:59:28 +110099
Michael Ellerman6c69b7e2017-12-12 13:15:04 +1100100result=${?}
101
Chris Smartf9ad3f92016-01-11 14:59:28 +1100102# Timestamp for build
103echo "Build completed, $(date)"
104
Michael Ellerman6c69b7e2017-12-12 13:15:04 +1100105exit ${result}