blob: 60051289a42d8822559637aaf35cc6d28d842ab9 [file] [log] [blame]
Joel Stanley0b851182016-06-21 23:51:19 +09301#!/bin/bash
Alanny Lopezcce369b2017-06-20 09:52:50 -05002###############################################################################
3#
Joel Stanleyb23c4cc2018-10-31 18:47:25 +10304# 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 Lopezcce369b2017-06-20 09:52:50 -050016#
17###############################################################################
18#
Alanny Lopeze08e8702018-02-24 18:07:13 -060019# Script Variables:
Alanny Lopeze08e8702018-02-24 18:07:13 -060020# http_proxy The HTTP address of the proxy server to connect to.
21# Default: "", proxy is not setup if this is not set
Joel Stanleyb23c4cc2018-10-31 18:47:25 +103022# WORKSPACE Path of the workspace directory where the build will
23# occur, and output artifacts will be produced.
Alanny Lopezcce369b2017-06-20 09:52:50 -050024#
25###############################################################################
Joel Stanley0b851182016-06-21 23:51:19 +093026# Trace bash processing
Joel Stanleyb23c4cc2018-10-31 18:47:25 +103027#set -x
Joel Stanley0b851182016-06-21 23:51:19 +093028
Alanny Lopez46967702018-02-25 00:29:14 -060029# Script Variables:
Joel Stanley0b851182016-06-21 23:51:19 +093030http_proxy=${http_proxy:-}
Joel Stanleyb23c4cc2018-10-31 18:47:25 +103031
32if [ -z ${WORKSPACE+x} ]; then
33 echo "Please set WORKSPACE variable"
34 exit 1
35fi
Alanny Lopez46967702018-02-25 00:29:14 -060036
Joel Stanley62d18022018-08-15 12:46:23 +093037# Determine the architecture
38ARCH=$(uname -m)
39
Alanny Lopez46967702018-02-25 00:29:14 -060040# Docker Image Build Variables:
Joel Stanleyb23c4cc2018-10-31 18:47:25 +103041img_name=qemu-build
Alanny Lopez46967702018-02-25 00:29:14 -060042
Joel Stanley0b851182016-06-21 23:51:19 +093043# Timestamp for job
44echo "Build started, $(date)"
45
Alanny Lopez41e2ada2017-06-15 13:54:43 -050046# Setup Proxy
Joel Stanley0b851182016-06-21 23:51:19 +093047if [[ -n "${http_proxy}" ]]; then
48PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
49fi
50
Alanny Lopez41e2ada2017-06-15 13:54:43 -050051# Determine the prefix of the Dockerfile's base image
52case ${ARCH} in
53 "ppc64le")
54 DOCKER_BASE="ppc64le/"
55 ;;
56 "x86_64")
57 DOCKER_BASE=""
58 ;;
Thang Q. Nguyen051b05b2021-12-10 08:30:35 +000059 "aarch64")
60 DOCKER_BASE=""
61 ;;
Alanny Lopez41e2ada2017-06-15 13:54:43 -050062 *)
63 echo "Unsupported system architecture(${ARCH}) found for docker image"
64 exit 1
65esac
Joel Stanley0b851182016-06-21 23:51:19 +093066
67# Create the docker run script
68export PROXY_HOST=${http_proxy/#http*:\/\/}
69export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
70export PROXY_PORT=${http_proxy/#http*:\/\/*:}
71
Joel Stanley0b851182016-06-21 23:51:19 +093072cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
73#!/bin/bash
74
75set -x
76
Alanny Lopeza61e99a2017-06-27 14:20:48 -050077# Go into the build directory
Joel Stanleyb23c4cc2018-10-31 18:47:25 +103078cd ${WORKSPACE}/qemu
Joel Stanley0b851182016-06-21 23:51:19 +093079
80gcc --version
Alanny Lopez41e2ada2017-06-15 13:54:43 -050081git submodule update --init dtc
Joel Stanley0b851182016-06-21 23:51:19 +093082# disable anything that requires us to pull in X
Alanny Lopeze30237c2017-06-15 13:27:47 -050083./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 \
Joel Stanleye32aaee2018-10-24 15:30:17 +103095 --disable-werror \
Alanny Lopeze30237c2017-06-15 13:27:47 -050096 --disable-vnc-png
Joel Stanleyb23c4cc2018-10-31 18:47:25 +103097make clean
Joel Stanley0b851182016-06-21 23:51:19 +093098make -j4
99
100EOF_SCRIPT
101
Patrick Williams384d7412020-11-06 16:15:41 -0600102chmod a+x "${WORKSPACE}"/build.sh
Joel Stanley0b851182016-06-21 23:51:19 +0930103
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500104# Configure docker build
Andrew Jefferya311abc2021-01-15 14:22:34 +1030105
106# !!!
107# Keep the base docker image in sync with the image under which we run the
108# resulting qemu binary.
109# !!!
110
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500111Dockerfile=$(cat << EOF
Andrew Jefferya311abc2021-01-15 14:22:34 +1030112FROM ${DOCKER_BASE}ubuntu:bionic
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500113
114${PROXY}
115
116ENV DEBIAN_FRONTEND noninteractive
117RUN apt-get update && apt-get install -yy --no-install-recommends \
118 bison \
Andrew Jeffery41826802021-01-15 14:23:35 +1030119 bzip2 \
Joel Stanleya3f390e2019-01-16 00:24:25 +1100120 ca-certificates \
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500121 flex \
122 gcc \
123 git \
124 libc6-dev \
125 libfdt-dev \
126 libglib2.0-dev \
127 libpixman-1-dev \
128 make \
Andrew Jeffery41826802021-01-15 14:23:35 +1030129 ninja-build \
Saqib Khan5158a322017-10-23 11:31:24 -0500130 python3-yaml \
131 iputils-ping
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500132
Patrick Williams384d7412020-11-06 16:15:41 -0600133RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
134RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500135USER ${USER}
136ENV HOME ${HOME}
137EOF
138)
139
Patrick Williams384d7412020-11-06 16:15:41 -0600140if ! docker build -t ${img_name} - <<< "${Dockerfile}" ; then
Joel Stanleyb23c4cc2018-10-31 18:47:25 +1030141 echo "Failed to build docker container."
142 exit 1
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500143fi
Joel Stanleyb23c4cc2018-10-31 18:47:25 +1030144
145docker run \
146 --rm=true \
Patrick Williams384d7412020-11-06 16:15:41 -0600147 -e WORKSPACE="${WORKSPACE}" \
Joel Stanleyb23c4cc2018-10-31 18:47:25 +1030148 -w "${HOME}" \
149 --user="${USER}" \
150 -v "${HOME}":"${HOME}" \
151 -t ${img_name} \
Patrick Williams384d7412020-11-06 16:15:41 -0600152 "${WORKSPACE}"/build.sh