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 |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 48 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 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 |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 53 | "ppc64le") |
| 54 | DOCKER_BASE="ppc64le/" |
| 55 | ;; |
| 56 | "x86_64") |
| 57 | DOCKER_BASE="" |
| 58 | ;; |
| 59 | "aarch64") |
| 60 | DOCKER_BASE="arm64v8/" |
| 61 | ;; |
| 62 | *) |
| 63 | echo "Unsupported system architecture(${ARCH}) found for docker image" |
| 64 | exit 1 |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 65 | esac |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 66 | |
| 67 | # Create the docker run script |
| 68 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 69 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 70 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 71 | |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 72 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 73 | #!/bin/bash |
| 74 | |
| 75 | set -x |
| 76 | |
Alanny Lopez | a61e99a | 2017-06-27 14:20:48 -0500 | [diff] [blame] | 77 | # Go into the build directory |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 78 | cd ${WORKSPACE}/qemu |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 79 | |
| 80 | gcc --version |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 81 | git submodule update --init dtc |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 82 | # disable anything that requires us to pull in X |
Alanny Lopez | e30237c | 2017-06-15 13:27:47 -0500 | [diff] [blame] | 83 | ./configure \ |
| 84 | --target-list=arm-softmmu \ |
| 85 | --disable-spice \ |
| 86 | --disable-docs \ |
| 87 | --disable-gtk \ |
| 88 | --disable-smartcard \ |
| 89 | --disable-usb-redir \ |
| 90 | --disable-libusb \ |
| 91 | --disable-sdl \ |
| 92 | --disable-gnutls \ |
| 93 | --disable-vte \ |
| 94 | --disable-vnc \ |
Andrew Geissler | 4a01582 | 2022-12-19 15:39:54 -0600 | [diff] [blame] | 95 | --disable-werror |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 96 | make clean |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 97 | make -j4 |
| 98 | |
| 99 | EOF_SCRIPT |
| 100 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 101 | chmod a+x "${WORKSPACE}"/build.sh |
Joel Stanley | 0b85118 | 2016-06-21 23:51:19 +0930 | [diff] [blame] | 102 | |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 103 | # Configure docker build |
Andrew Jeffery | a311abc | 2021-01-15 14:22:34 +1030 | [diff] [blame] | 104 | |
| 105 | # !!! |
| 106 | # Keep the base docker image in sync with the image under which we run the |
| 107 | # resulting qemu binary. |
| 108 | # !!! |
| 109 | |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 110 | Dockerfile=$(cat << EOF |
Andrew Geissler | 851eaff | 2022-12-22 09:47:54 -0600 | [diff] [blame] | 111 | FROM ${DOCKER_BASE}ubuntu:jammy |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 112 | |
| 113 | ${PROXY} |
| 114 | |
| 115 | ENV DEBIAN_FRONTEND noninteractive |
| 116 | RUN apt-get update && apt-get install -yy --no-install-recommends \ |
| 117 | bison \ |
Andrew Jeffery | 4182680 | 2021-01-15 14:23:35 +1030 | [diff] [blame] | 118 | bzip2 \ |
Joel Stanley | a3f390e | 2019-01-16 00:24:25 +1100 | [diff] [blame] | 119 | ca-certificates \ |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 120 | flex \ |
| 121 | gcc \ |
| 122 | git \ |
| 123 | libc6-dev \ |
| 124 | libfdt-dev \ |
| 125 | libglib2.0-dev \ |
| 126 | libpixman-1-dev \ |
Andrew Geissler | 4a01582 | 2022-12-19 15:39:54 -0600 | [diff] [blame] | 127 | libslirp-dev \ |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 128 | make \ |
Andrew Jeffery | 4182680 | 2021-01-15 14:23:35 +1030 | [diff] [blame] | 129 | ninja-build \ |
Andrew Geissler | 4b4c8ec | 2023-09-25 07:09:38 -0500 | [diff] [blame^] | 130 | python3-venv \ |
Saqib Khan | 5158a32 | 2017-10-23 11:31:24 -0500 | [diff] [blame] | 131 | python3-yaml \ |
| 132 | iputils-ping |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 133 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 134 | RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} |
| 135 | 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] | 136 | USER ${USER} |
| 137 | ENV HOME ${HOME} |
| 138 | EOF |
| 139 | ) |
| 140 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 141 | if ! docker build -t ${img_name} - <<< "${Dockerfile}" ; then |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 142 | echo "Failed to build docker container." |
| 143 | exit 1 |
Alanny Lopez | 41e2ada | 2017-06-15 13:54:43 -0500 | [diff] [blame] | 144 | fi |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 145 | |
| 146 | docker run \ |
| 147 | --rm=true \ |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 148 | -e WORKSPACE="${WORKSPACE}" \ |
Joel Stanley | b23c4cc | 2018-10-31 18:47:25 +1030 | [diff] [blame] | 149 | -w "${HOME}" \ |
| 150 | --user="${USER}" \ |
| 151 | -v "${HOME}":"${HOME}" \ |
| 152 | -t ${img_name} \ |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 153 | "${WORKSPACE}"/build.sh |