Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 1 | #!/bin/bash |
Alanny Lopez | cce369b | 2017-06-20 09:52:50 -0500 | [diff] [blame] | 2 | ############################################################################### |
| 3 | # |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 4 | # This build script is for running the QEMU build in a container |
| 5 | # |
| 6 | # It expects to be run in with the qemu source present in the directory called |
| 7 | # '$WORKSPACE/qemu', where WORKSPACE is an environment variable. |
| 8 | # |
| 9 | # In Jenkins configure the git SCM 'Additional Behaviours', 'check-out to a sub |
| 10 | # directory' called 'qemu'. |
| 11 | # |
| 12 | # When building locally set WORKSPACE to be the directory above the qemu |
| 13 | # checkout: |
| 14 | # git clone https://github.com/qemu/qemu |
| 15 | # WORKSPACE=$PWD/qemu ~/openbmc-build-scripts/qemu-build.sh |
Alanny Lopez | cce369b | 2017-06-20 09:52:50 -0500 | [diff] [blame] | 16 | # |
| 17 | ############################################################################### |
| 18 | # |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 19 | # Script Variables: |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 20 | # http_proxy The HTTP address of the proxy server to connect to. |
| 21 | # Default: "", proxy is not setup if this is not set |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 22 | # WORKSPACE Path of the workspace directory where the build will |
| 23 | # occur, and output artifacts will be produced. |
Alanny Lopez | cce369b | 2017-06-20 09:52:50 -0500 | [diff] [blame] | 24 | # |
| 25 | ############################################################################### |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 26 | # Trace bash processing |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 27 | #set -x |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 28 | |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 29 | # Script Variables: |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 30 | http_proxy=${http_proxy:-} |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 31 | |
| 32 | if [ -z ${WORKSPACE+x} ]; then |
| 33 | echo "Please set WORKSPACE variable" |
| 34 | exit 1 |
| 35 | fi |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 36 | |
Joel Stanley | 62d1802 | 2018-08-15 12:46:23 +0930 | [diff] [blame] | 37 | # Determine the architecture |
| 38 | ARCH=$(uname -m) |
| 39 | |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 40 | # Docker Image Build Variables: |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 41 | img_name=qemu-build |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 42 | |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 43 | # Timestamp for job |
| 44 | echo "Build started, $(date)" |
| 45 | |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 46 | # Setup Proxy |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 47 | if [[ -n "${http_proxy}" ]]; then |
| 48 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
| 49 | fi |
| 50 | |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 51 | # Determine the prefix of the Dockerfile's base image |
| 52 | case ${ARCH} in |
| 53 | "ppc64le") |
| 54 | DOCKER_BASE="ppc64le/" |
| 55 | ;; |
| 56 | "x86_64") |
| 57 | DOCKER_BASE="" |
| 58 | ;; |
| 59 | *) |
| 60 | echo "Unsupported system architecture(${ARCH}) found for docker image" |
| 61 | exit 1 |
| 62 | esac |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 63 | |
| 64 | # Create the docker run script |
| 65 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 66 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 67 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 68 | |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 69 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 70 | #!/bin/bash |
| 71 | |
| 72 | set -x |
| 73 | |
Alanny Lopez | a61e99a | 2017-06-27 14:20:48 -0500 | [diff] [blame] | 74 | # Go into the build directory |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 75 | cd ${WORKSPACE}/qemu |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 76 | |
| 77 | gcc --version |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 78 | git submodule update --init dtc |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 79 | # disable anything that requires us to pull in X |
Alanny Lopez | e30237c | 2017-06-15 13:27:47 -0500 | [diff] [blame] | 80 | ./configure \ |
| 81 | --target-list=arm-softmmu \ |
| 82 | --disable-spice \ |
| 83 | --disable-docs \ |
| 84 | --disable-gtk \ |
| 85 | --disable-smartcard \ |
| 86 | --disable-usb-redir \ |
| 87 | --disable-libusb \ |
| 88 | --disable-sdl \ |
| 89 | --disable-gnutls \ |
| 90 | --disable-vte \ |
| 91 | --disable-vnc \ |
Joel Stanley | e32aaee | 2018-10-24 15:30:17 +1030 | [diff] [blame] | 92 | --disable-werror \ |
Alanny Lopez | e30237c | 2017-06-15 13:27:47 -0500 | [diff] [blame] | 93 | --disable-vnc-png |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 94 | make clean |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 95 | make -j4 |
| 96 | |
| 97 | EOF_SCRIPT |
| 98 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 99 | chmod a+x "${WORKSPACE}"/build.sh |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 100 | |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 101 | # Configure docker build |
Andrew Jeffery | a311abc | 2021-01-15 14:22:34 +1030 | [diff] [blame] | 102 | |
| 103 | # !!! |
| 104 | # Keep the base docker image in sync with the image under which we run the |
| 105 | # resulting qemu binary. |
| 106 | # !!! |
| 107 | |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 108 | Dockerfile=$(cat << EOF |
Andrew Jeffery | a311abc | 2021-01-15 14:22:34 +1030 | [diff] [blame] | 109 | FROM ${DOCKER_BASE}ubuntu:bionic |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 110 | |
| 111 | ${PROXY} |
| 112 | |
| 113 | ENV DEBIAN_FRONTEND noninteractive |
| 114 | RUN apt-get update && apt-get install -yy --no-install-recommends \ |
| 115 | bison \ |
Andrew Jeffery | 4182680 | 2021-01-15 14:23:35 +1030 | [diff] [blame] | 116 | bzip2 \ |
Joel Stanley | a3f390e | 2019-01-16 00:24:25 +1100 | [diff] [blame] | 117 | ca-certificates \ |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 118 | flex \ |
| 119 | gcc \ |
| 120 | git \ |
| 121 | libc6-dev \ |
| 122 | libfdt-dev \ |
| 123 | libglib2.0-dev \ |
| 124 | libpixman-1-dev \ |
| 125 | make \ |
Andrew Jeffery | 4182680 | 2021-01-15 14:23:35 +1030 | [diff] [blame] | 126 | ninja-build \ |
Saqib Khan | 5158a32 | 2017-10-23 11:31:24 -0500 | [diff] [blame] | 127 | python3-yaml \ |
| 128 | iputils-ping |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 129 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 130 | RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} |
| 131 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER} |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 132 | USER ${USER} |
| 133 | ENV HOME ${HOME} |
| 134 | EOF |
| 135 | ) |
| 136 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 137 | if ! docker build -t ${img_name} - <<< "${Dockerfile}" ; then |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 138 | echo "Failed to build docker container." |
| 139 | exit 1 |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 140 | fi |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 141 | |
| 142 | docker run \ |
| 143 | --rm=true \ |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 144 | -e WORKSPACE="${WORKSPACE}" \ |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 145 | -w "${HOME}" \ |
| 146 | --user="${USER}" \ |
| 147 | -v "${HOME}":"${HOME}" \ |
| 148 | -t ${img_name} \ |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 149 | "${WORKSPACE}"/build.sh |