1#!/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
18    PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
19fi
20
21Dockerfile=$(cat << EOF
22FROM ubuntu:latest
23
24${PROXY}
25
26ENV DEBIAN_FRONTEND noninteractive
27RUN apt-get update && apt-get install -yy \
28	bc \
29	build-essential \
30	git \
31	gcc-powerpc64le-linux-gnu \
32	software-properties-common \
33	libssl-dev \
34	bison \
35	flex \
36	iputils-ping
37
38RUN apt-add-repository -y multiverse && apt-get update && apt-get install -yy \
39	dwarves \
40	sparse
41
42RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
43RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
44
45USER ${USER}
46ENV HOME ${HOME}
47RUN /bin/bash
48EOF
49)
50
51# Build the docker container
52if ! docker build -t linux-build/ubuntu - <<< "${Dockerfile}" ; then
53    echo "Failed to build docker container."
54    exit 1
55fi
56
57# Create the docker run script
58export PROXY_HOST=${http_proxy/#http*:\/\/}
59export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
60export PROXY_PORT=${http_proxy/#http*:\/\/*:}
61
62mkdir -p "${WORKSPACE}"
63
64cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
65#!/bin/bash
66
67set -x
68set -e -o pipefail
69
70cd "${WORKSPACE}"
71
72# Go into the linux directory (the script will put us in a build subdir)
73cd linux
74
75# Record the version in the logs
76powerpc64le-linux-gnu-gcc --version
77
78# Build kernel prep
79ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make mrproper
80
81# Build kernel
82ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -s pseries_le_defconfig
83ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -s -j$(nproc)
84
85# Build kernel with debug
86ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -s pseries_le_defconfig
87echo "CONFIG_DEBUG_INFO=y" >> .config
88# Enable virtio-net driver for QEMU virtio-net-pci driver
89echo "CONFIG_VIRTIO=y" >> .config
90echo "CONFIG_VIRTIO_NET=y" >> .config
91echo "CONFIG_VIRTIO_PCI=y" >> .config
92ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make olddefconfig
93ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) -s C=2 CF=-D__CHECK_ENDIAN__ 2>&1 | gzip > sparse.log.gz
94pahole vmlinux 2>&1 | gzip > structs.dump.gz
95
96EOF_SCRIPT
97
98chmod a+x "${WORKSPACE}"/build.sh
99
100# Run the docker container, execute the build script we just built
101docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE="${WORKSPACE}" --user="${USER}" \
102    -w "${WORKSPACE}" -v "${WORKSPACE}":"${WORKSPACE}" -t linux-build/ubuntu "${WORKSPACE}"/build.sh
103
104result=${?}
105
106# Timestamp for build
107echo "Build completed, $(date)"
108
109exit ${result}
110