blob: 97e7ce8249f9c9b757adc201827bfe7c9c57d37f [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 \
Joel Stanley4e942972018-02-06 16:06:01 +103034 bison \
35 flex \
Saqib Khan5158a322017-10-23 11:31:24 -050036 iputils-ping
Chris Smart4593d4f2016-03-09 15:50:59 +110037
38RUN apt-add-repository -y multiverse && apt-get update && apt-get install -yy \
39 dwarves \
40 sparse
41
42RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
43RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smartf9ad3f92016-01-11 14:59:28 +110044
45USER ${USER}
46ENV HOME ${HOME}
47RUN /bin/bash
48EOF
49)
50
51# Build the docker container
52docker build -t linux-build/ubuntu - <<< "${Dockerfile}"
53if [[ "$?" -ne 0 ]]; then
54 echo "Failed to build docker container."
55 exit 1
56fi
57
58# Create the docker run script
59export PROXY_HOST=${http_proxy/#http*:\/\/}
60export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
61export PROXY_PORT=${http_proxy/#http*:\/\/*:}
62
63mkdir -p ${WORKSPACE}
64
65cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
66#!/bin/bash
67
68set -x
Michael Ellerman9872b7c2017-12-12 14:03:10 +110069set -e -o pipefail
Chris Smartf9ad3f92016-01-11 14:59:28 +110070
71cd ${WORKSPACE}
72
73# Go into the linux directory (the script will put us in a build subdir)
74cd linux
75
76# Record the version in the logs
Michael Ellerman9872b7c2017-12-12 14:03:10 +110077powerpc64le-linux-gnu-gcc --version
Chris Smartf9ad3f92016-01-11 14:59:28 +110078
Chris Smart78646622016-03-03 16:49:59 +110079# Build kernel prep
Michael Ellerman9872b7c2017-12-12 14:03:10 +110080ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make mrproper
Chris Smart78646622016-03-03 16:49:59 +110081
Michael Ellerman9f05cf32017-12-12 14:34:55 +110082# Build kernel
83ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -s pseries_le_defconfig
84ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -s -j$(nproc)
85
Chris Smart78646622016-03-03 16:49:59 +110086# Build kernel with debug
Michael Ellermancf9b7f12017-12-12 14:05:25 +110087ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -s pseries_le_defconfig
Chris Smart78646622016-03-03 16:49:59 +110088echo "CONFIG_DEBUG_INFO=y" >> .config
Murilo Opsfelder Araujo87963e02019-02-07 20:40:39 -020089# Enable virtio-net driver for QEMU virtio-net-pci driver
90echo "CONFIG_VIRTIO=y" >> .config
91echo "CONFIG_VIRTIO_NET=y" >> .config
92echo "CONFIG_VIRTIO_PCI=y" >> .config
Michael Ellerman9872b7c2017-12-12 14:03:10 +110093ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make olddefconfig
Chris Smart78646622016-03-03 16:49:59 +110094ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) -s C=2 CF=-D__CHECK_ENDIAN__ 2>&1 | gzip > sparse.log.gz
95pahole vmlinux 2>&1 | gzip > structs.dump.gz
96
Chris Smartf9ad3f92016-01-11 14:59:28 +110097EOF_SCRIPT
98
99chmod a+x ${WORKSPACE}/build.sh
100
101# Run the docker container, execute the build script we just built
102docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
Michael Ellerman3225cfc2017-12-12 13:35:00 +1100103 -w "${WORKSPACE}" -v "${WORKSPACE}":"${WORKSPACE}" -t linux-build/ubuntu ${WORKSPACE}/build.sh
Chris Smartf9ad3f92016-01-11 14:59:28 +1100104
Michael Ellerman6c69b7e2017-12-12 13:15:04 +1100105result=${?}
106
Chris Smartf9ad3f92016-01-11 14:59:28 +1100107# Timestamp for build
108echo "Build completed, $(date)"
109
Michael Ellerman6c69b7e2017-12-12 13:15:04 +1100110exit ${result}