Chris Smart | f9ad3f9 | 2016-01-11 14:59:28 +1100 | [diff] [blame] | 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 |
| 10 | WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} |
| 11 | http_proxy=${http_proxy:-} |
| 12 | |
| 13 | # Timestamp for job |
| 14 | echo "Build started, $(date)" |
| 15 | |
| 16 | # Configure docker build |
| 17 | if [[ -n "${http_proxy}" ]]; then |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame^] | 18 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
Chris Smart | f9ad3f9 | 2016-01-11 14:59:28 +1100 | [diff] [blame] | 19 | fi |
| 20 | |
| 21 | Dockerfile=$(cat << EOF |
Joel Stanley | 5f4de95 | 2017-12-06 18:53:16 +1030 | [diff] [blame] | 22 | FROM ubuntu:latest |
Chris Smart | f9ad3f9 | 2016-01-11 14:59:28 +1100 | [diff] [blame] | 23 | |
| 24 | ${PROXY} |
| 25 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 26 | ENV DEBIAN_FRONTEND noninteractive |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 27 | RUN apt-get update && apt-get install -yy \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 28 | bc \ |
| 29 | build-essential \ |
| 30 | git \ |
| 31 | gcc-powerpc64le-linux-gnu \ |
Saqib Khan | 5158a32 | 2017-10-23 11:31:24 -0500 | [diff] [blame] | 32 | software-properties-common \ |
Joel Stanley | 15a77ae | 2017-12-12 00:17:14 +1030 | [diff] [blame] | 33 | libssl-dev \ |
Joel Stanley | 4e94297 | 2018-02-06 16:06:01 +1030 | [diff] [blame] | 34 | bison \ |
| 35 | flex \ |
Saqib Khan | 5158a32 | 2017-10-23 11:31:24 -0500 | [diff] [blame] | 36 | iputils-ping |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 37 | |
| 38 | RUN apt-add-repository -y multiverse && apt-get update && apt-get install -yy \ |
| 39 | dwarves \ |
| 40 | sparse |
| 41 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 42 | RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} |
| 43 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER} |
Chris Smart | f9ad3f9 | 2016-01-11 14:59:28 +1100 | [diff] [blame] | 44 | |
| 45 | USER ${USER} |
| 46 | ENV HOME ${HOME} |
| 47 | RUN /bin/bash |
| 48 | EOF |
| 49 | ) |
| 50 | |
| 51 | # Build the docker container |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 52 | if ! docker build -t linux-build/ubuntu - <<< "${Dockerfile}" ; then |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame^] | 53 | echo "Failed to build docker container." |
| 54 | exit 1 |
Chris Smart | f9ad3f9 | 2016-01-11 14:59:28 +1100 | [diff] [blame] | 55 | fi |
| 56 | |
| 57 | # Create the docker run script |
| 58 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 59 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 60 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 61 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 62 | mkdir -p "${WORKSPACE}" |
Chris Smart | f9ad3f9 | 2016-01-11 14:59:28 +1100 | [diff] [blame] | 63 | |
| 64 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 65 | #!/bin/bash |
| 66 | |
| 67 | set -x |
Michael Ellerman | 9872b7c | 2017-12-12 14:03:10 +1100 | [diff] [blame] | 68 | set -e -o pipefail |
Chris Smart | f9ad3f9 | 2016-01-11 14:59:28 +1100 | [diff] [blame] | 69 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 70 | cd "${WORKSPACE}" |
Chris Smart | f9ad3f9 | 2016-01-11 14:59:28 +1100 | [diff] [blame] | 71 | |
| 72 | # Go into the linux directory (the script will put us in a build subdir) |
| 73 | cd linux |
| 74 | |
| 75 | # Record the version in the logs |
Michael Ellerman | 9872b7c | 2017-12-12 14:03:10 +1100 | [diff] [blame] | 76 | powerpc64le-linux-gnu-gcc --version |
Chris Smart | f9ad3f9 | 2016-01-11 14:59:28 +1100 | [diff] [blame] | 77 | |
Chris Smart | 7864662 | 2016-03-03 16:49:59 +1100 | [diff] [blame] | 78 | # Build kernel prep |
Michael Ellerman | 9872b7c | 2017-12-12 14:03:10 +1100 | [diff] [blame] | 79 | ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make mrproper |
Chris Smart | 7864662 | 2016-03-03 16:49:59 +1100 | [diff] [blame] | 80 | |
Michael Ellerman | 9f05cf3 | 2017-12-12 14:34:55 +1100 | [diff] [blame] | 81 | # Build kernel |
| 82 | ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -s pseries_le_defconfig |
| 83 | ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -s -j$(nproc) |
| 84 | |
Chris Smart | 7864662 | 2016-03-03 16:49:59 +1100 | [diff] [blame] | 85 | # Build kernel with debug |
Michael Ellerman | cf9b7f1 | 2017-12-12 14:05:25 +1100 | [diff] [blame] | 86 | ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -s pseries_le_defconfig |
Chris Smart | 7864662 | 2016-03-03 16:49:59 +1100 | [diff] [blame] | 87 | echo "CONFIG_DEBUG_INFO=y" >> .config |
Murilo Opsfelder Araujo | 87963e0 | 2019-02-07 20:40:39 -0200 | [diff] [blame] | 88 | # Enable virtio-net driver for QEMU virtio-net-pci driver |
| 89 | echo "CONFIG_VIRTIO=y" >> .config |
| 90 | echo "CONFIG_VIRTIO_NET=y" >> .config |
| 91 | echo "CONFIG_VIRTIO_PCI=y" >> .config |
Michael Ellerman | 9872b7c | 2017-12-12 14:03:10 +1100 | [diff] [blame] | 92 | ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make olddefconfig |
Chris Smart | 7864662 | 2016-03-03 16:49:59 +1100 | [diff] [blame] | 93 | ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- make -j$(nproc) -s C=2 CF=-D__CHECK_ENDIAN__ 2>&1 | gzip > sparse.log.gz |
| 94 | pahole vmlinux 2>&1 | gzip > structs.dump.gz |
| 95 | |
Chris Smart | f9ad3f9 | 2016-01-11 14:59:28 +1100 | [diff] [blame] | 96 | EOF_SCRIPT |
| 97 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 98 | chmod a+x "${WORKSPACE}"/build.sh |
Chris Smart | f9ad3f9 | 2016-01-11 14:59:28 +1100 | [diff] [blame] | 99 | |
| 100 | # Run the docker container, execute the build script we just built |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 101 | docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE="${WORKSPACE}" --user="${USER}" \ |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame^] | 102 | -w "${WORKSPACE}" -v "${WORKSPACE}":"${WORKSPACE}" -t linux-build/ubuntu "${WORKSPACE}"/build.sh |
Chris Smart | f9ad3f9 | 2016-01-11 14:59:28 +1100 | [diff] [blame] | 103 | |
Michael Ellerman | 6c69b7e | 2017-12-12 13:15:04 +1100 | [diff] [blame] | 104 | result=${?} |
| 105 | |
Chris Smart | f9ad3f9 | 2016-01-11 14:59:28 +1100 | [diff] [blame] | 106 | # Timestamp for build |
| 107 | echo "Build completed, $(date)" |
| 108 | |
Michael Ellerman | 6c69b7e | 2017-12-12 13:15:04 +1100 | [diff] [blame] | 109 | exit ${result} |