1f9ad3f9eSChris Smart#!/bin/bash 2f9ad3f9eSChris Smart 3f9ad3f9eSChris Smart# This build script is for running the Jenkins builds using docker. 4f9ad3f9eSChris Smart# 5f9ad3f9eSChris Smart 6f9ad3f9eSChris Smart# Trace bash processing 7f9ad3f9eSChris Smart#set -x 8f9ad3f9eSChris Smart 9f9ad3f9eSChris Smart# Default variables 10f9ad3f9eSChris SmartWORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} 11f9ad3f9eSChris Smarthttp_proxy=${http_proxy:-} 12f9ad3f9eSChris Smart 13f9ad3f9eSChris Smart# Timestamp for job 14f9ad3f9eSChris Smartecho "Build started, $(date)" 15f9ad3f9eSChris Smart 16f9ad3f9eSChris Smart# Configure docker build 17f9ad3f9eSChris Smartif [[ -n "${http_proxy}" ]]; then 18f9ad3f9eSChris Smart PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" 19f9ad3f9eSChris Smartfi 20f9ad3f9eSChris Smart 21f9ad3f9eSChris SmartDockerfile=$(cat << EOF 225f4de959SJoel StanleyFROM ubuntu:latest 23f9ad3f9eSChris Smart 24f9ad3f9eSChris Smart${PROXY} 25f9ad3f9eSChris Smart 264593d4f3SChris SmartENV DEBIAN_FRONTEND noninteractive 27fc730ff1SChris SmartRUN apt-get update && apt-get install -yy \ 284593d4f3SChris Smart bc \ 294593d4f3SChris Smart build-essential \ 304593d4f3SChris Smart git \ 314593d4f3SChris Smart gcc-powerpc64le-linux-gnu \ 325158a324SSaqib Khan software-properties-common \ 3315a77aebSJoel Stanley libssl-dev \ 344e94297dSJoel Stanley bison \ 354e94297dSJoel Stanley flex \ 365158a324SSaqib Khan iputils-ping 374593d4f3SChris Smart 384593d4f3SChris SmartRUN apt-add-repository -y multiverse && apt-get update && apt-get install -yy \ 394593d4f3SChris Smart dwarves \ 404593d4f3SChris Smart sparse 414593d4f3SChris Smart 42*384d741bSPatrick WilliamsRUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} 43*384d741bSPatrick WilliamsRUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER} 44f9ad3f9eSChris Smart 45f9ad3f9eSChris SmartUSER ${USER} 46f9ad3f9eSChris SmartENV HOME ${HOME} 47f9ad3f9eSChris SmartRUN /bin/bash 48f9ad3f9eSChris SmartEOF 49f9ad3f9eSChris Smart) 50f9ad3f9eSChris Smart 51f9ad3f9eSChris Smart# Build the docker container 52*384d741bSPatrick Williamsif ! docker build -t linux-build/ubuntu - <<< "${Dockerfile}" ; then 53f9ad3f9eSChris Smart echo "Failed to build docker container." 54f9ad3f9eSChris Smart exit 1 55f9ad3f9eSChris Smartfi 56f9ad3f9eSChris Smart 57f9ad3f9eSChris Smart# Create the docker run script 58f9ad3f9eSChris Smartexport PROXY_HOST=${http_proxy/#http*:\/\/} 59f9ad3f9eSChris Smartexport PROXY_HOST=${PROXY_HOST/%:[0-9]*} 60f9ad3f9eSChris Smartexport PROXY_PORT=${http_proxy/#http*:\/\/*:} 61f9ad3f9eSChris Smart 62*384d741bSPatrick Williamsmkdir -p "${WORKSPACE}" 63f9ad3f9eSChris Smart 64f9ad3f9eSChris Smartcat > "${WORKSPACE}"/build.sh << EOF_SCRIPT 65f9ad3f9eSChris Smart#!/bin/bash 66f9ad3f9eSChris Smart 67f9ad3f9eSChris Smartset -x 689872b7c3SMichael Ellermanset -e -o pipefail 69f9ad3f9eSChris Smart 70*384d741bSPatrick Williamscd "${WORKSPACE}" 71f9ad3f9eSChris Smart 72f9ad3f9eSChris Smart# Go into the linux directory (the script will put us in a build subdir) 73f9ad3f9eSChris Smartcd linux 74f9ad3f9eSChris Smart 75f9ad3f9eSChris Smart# Record the version in the logs 769872b7c3SMichael Ellermanpowerpc64le-linux-gnu-gcc --version 77f9ad3f9eSChris Smart 7878646628SChris Smart# Build kernel prep 799872b7c3SMichael EllermanARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make mrproper 8078646628SChris Smart 819f05cf3eSMichael Ellerman# Build kernel 829f05cf3eSMichael EllermanARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -s pseries_le_defconfig 839f05cf3eSMichael EllermanARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -s -j$(nproc) 849f05cf3eSMichael Ellerman 8578646628SChris Smart# Build kernel with debug 86cf9b7f11SMichael EllermanARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -s pseries_le_defconfig 8778646628SChris Smartecho "CONFIG_DEBUG_INFO=y" >> .config 8887963e0aSMurilo Opsfelder Araujo# Enable virtio-net driver for QEMU virtio-net-pci driver 8987963e0aSMurilo Opsfelder Araujoecho "CONFIG_VIRTIO=y" >> .config 9087963e0aSMurilo Opsfelder Araujoecho "CONFIG_VIRTIO_NET=y" >> .config 9187963e0aSMurilo Opsfelder Araujoecho "CONFIG_VIRTIO_PCI=y" >> .config 929872b7c3SMichael EllermanARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make olddefconfig 9378646628SChris SmartARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) -s C=2 CF=-D__CHECK_ENDIAN__ 2>&1 | gzip > sparse.log.gz 9478646628SChris Smartpahole vmlinux 2>&1 | gzip > structs.dump.gz 9578646628SChris Smart 96f9ad3f9eSChris SmartEOF_SCRIPT 97f9ad3f9eSChris Smart 98*384d741bSPatrick Williamschmod a+x "${WORKSPACE}"/build.sh 99f9ad3f9eSChris Smart 100f9ad3f9eSChris Smart# Run the docker container, execute the build script we just built 101*384d741bSPatrick Williamsdocker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE="${WORKSPACE}" --user="${USER}" \ 102*384d741bSPatrick Williams -w "${WORKSPACE}" -v "${WORKSPACE}":"${WORKSPACE}" -t linux-build/ubuntu "${WORKSPACE}"/build.sh 103f9ad3f9eSChris Smart 1046c69b7e6SMichael Ellermanresult=${?} 1056c69b7e6SMichael Ellerman 106f9ad3f9eSChris Smart# Timestamp for build 107f9ad3f9eSChris Smartecho "Build completed, $(date)" 108f9ad3f9eSChris Smart 1096c69b7e6SMichael Ellermanexit ${result} 110