blob: 199075ad1d16b6b8a58babf5248f8e6b1ad1c02a [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
Patrick Williams384d7412020-11-06 16:15:41 -060026ENV 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
Patrick Williams384d7412020-11-06 16:15:41 -060042RUN 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}
Chris Smartf9ad3f92016-01-11 14:59:28 +110044
45USER ${USER}
46ENV HOME ${HOME}
47RUN /bin/bash
48EOF
49)
50
51# Build the docker container
Patrick Williams384d7412020-11-06 16:15:41 -060052if ! docker build -t linux-build/ubuntu - <<< "${Dockerfile}" ; then
Chris Smartf9ad3f92016-01-11 14:59:28 +110053 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
Patrick Williams384d7412020-11-06 16:15:41 -060062mkdir -p "${WORKSPACE}"
Chris Smartf9ad3f92016-01-11 14:59:28 +110063
64cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
65#!/bin/bash
66
67set -x
Michael Ellerman9872b7c2017-12-12 14:03:10 +110068set -e -o pipefail
Chris Smartf9ad3f92016-01-11 14:59:28 +110069
Patrick Williams384d7412020-11-06 16:15:41 -060070cd "${WORKSPACE}"
Chris Smartf9ad3f92016-01-11 14:59:28 +110071
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
Michael Ellerman9872b7c2017-12-12 14:03:10 +110076powerpc64le-linux-gnu-gcc --version
Chris Smartf9ad3f92016-01-11 14:59:28 +110077
Chris Smart78646622016-03-03 16:49:59 +110078# Build kernel prep
Michael Ellerman9872b7c2017-12-12 14:03:10 +110079ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make mrproper
Chris Smart78646622016-03-03 16:49:59 +110080
Michael Ellerman9f05cf32017-12-12 14:34:55 +110081# 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
Chris Smart78646622016-03-03 16:49:59 +110085# Build kernel with debug
Michael Ellermancf9b7f12017-12-12 14:05:25 +110086ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -s pseries_le_defconfig
Chris Smart78646622016-03-03 16:49:59 +110087echo "CONFIG_DEBUG_INFO=y" >> .config
Murilo Opsfelder Araujo87963e02019-02-07 20:40:39 -020088# 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
Michael Ellerman9872b7c2017-12-12 14:03:10 +110092ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make olddefconfig
Chris Smart78646622016-03-03 16:49:59 +110093ARCH=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
Chris Smartf9ad3f92016-01-11 14:59:28 +110096EOF_SCRIPT
97
Patrick Williams384d7412020-11-06 16:15:41 -060098chmod a+x "${WORKSPACE}"/build.sh
Chris Smartf9ad3f92016-01-11 14:59:28 +110099
100# Run the docker container, execute the build script we just built
Patrick Williams384d7412020-11-06 16:15:41 -0600101docker 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
Chris Smartf9ad3f92016-01-11 14:59:28 +1100103
Michael Ellerman6c69b7e2017-12-12 13:15:04 +1100104result=${?}
105
Chris Smartf9ad3f92016-01-11 14:59:28 +1100106# Timestamp for build
107echo "Build completed, $(date)"
108
Michael Ellerman6c69b7e2017-12-12 13:15:04 +1100109exit ${result}