blob: 3e5f422ad48415a94894f299638b098a93ecb91c [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
37# Docker Image Build Variables:
Joel Stanleyb23c4cc2018-10-31 18:47:25 +103038img_name=qemu-build
Alanny Lopez46967702018-02-25 00:29:14 -060039
Joel Stanley0b851182016-06-21 23:51:19 +093040# Timestamp for job
41echo "Build started, $(date)"
42
Alanny Lopez41e2ada2017-06-15 13:54:43 -050043# Setup Proxy
Joel Stanley0b851182016-06-21 23:51:19 +093044if [[ -n "${http_proxy}" ]]; then
Patrick Williams476a7e92022-12-06 09:52:53 -060045 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
Joel Stanley0b851182016-06-21 23:51:19 +093046fi
47
Joel Stanley0b851182016-06-21 23:51:19 +093048# Create the docker run script
49export PROXY_HOST=${http_proxy/#http*:\/\/}
50export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
51export PROXY_PORT=${http_proxy/#http*:\/\/*:}
52
Joel Stanley0b851182016-06-21 23:51:19 +093053cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
54#!/bin/bash
55
56set -x
57
Alanny Lopeza61e99a2017-06-27 14:20:48 -050058# Go into the build directory
Joel Stanleyb23c4cc2018-10-31 18:47:25 +103059cd ${WORKSPACE}/qemu
Joel Stanley0b851182016-06-21 23:51:19 +093060
61gcc --version
Alanny Lopez41e2ada2017-06-15 13:54:43 -050062git submodule update --init dtc
Joel Stanley0b851182016-06-21 23:51:19 +093063# disable anything that requires us to pull in X
Alanny Lopeze30237c2017-06-15 13:27:47 -050064./configure \
65 --target-list=arm-softmmu \
66 --disable-spice \
67 --disable-docs \
68 --disable-gtk \
69 --disable-smartcard \
70 --disable-usb-redir \
71 --disable-libusb \
72 --disable-sdl \
73 --disable-gnutls \
74 --disable-vte \
75 --disable-vnc \
Andrew Geissler4a015822022-12-19 15:39:54 -060076 --disable-werror
Joel Stanleyb23c4cc2018-10-31 18:47:25 +103077make clean
Joel Stanley0b851182016-06-21 23:51:19 +093078make -j4
79
80EOF_SCRIPT
81
Patrick Williams384d7412020-11-06 16:15:41 -060082chmod a+x "${WORKSPACE}"/build.sh
Joel Stanley0b851182016-06-21 23:51:19 +093083
Alanny Lopez41e2ada2017-06-15 13:54:43 -050084# Configure docker build
Andrew Jefferya311abc2021-01-15 14:22:34 +103085
86# !!!
87# Keep the base docker image in sync with the image under which we run the
88# resulting qemu binary.
89# !!!
90
Alanny Lopez41e2ada2017-06-15 13:54:43 -050091Dockerfile=$(cat << EOF
Andrew Geissler9096c692024-10-02 16:36:17 -040092FROM ubuntu:jammy
Alanny Lopez41e2ada2017-06-15 13:54:43 -050093
94${PROXY}
95
96ENV DEBIAN_FRONTEND noninteractive
97RUN apt-get update && apt-get install -yy --no-install-recommends \
98 bison \
Andrew Jeffery41826802021-01-15 14:23:35 +103099 bzip2 \
Joel Stanleya3f390e2019-01-16 00:24:25 +1100100 ca-certificates \
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500101 flex \
102 gcc \
103 git \
104 libc6-dev \
105 libfdt-dev \
106 libglib2.0-dev \
107 libpixman-1-dev \
Andrew Geissler4a015822022-12-19 15:39:54 -0600108 libslirp-dev \
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500109 make \
Andrew Jeffery41826802021-01-15 14:23:35 +1030110 ninja-build \
Andrew Jefferydecca832024-09-05 18:02:10 +0200111 python3-tomli \
Andrew Geissler4b4c8ec2023-09-25 07:09:38 -0500112 python3-venv \
Saqib Khan5158a322017-10-23 11:31:24 -0500113 python3-yaml \
114 iputils-ping
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500115
Patrick Williams384d7412020-11-06 16:15:41 -0600116RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
117RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500118USER ${USER}
119ENV HOME ${HOME}
120EOF
121)
122
Patrick Williams384d7412020-11-06 16:15:41 -0600123if ! docker build -t ${img_name} - <<< "${Dockerfile}" ; then
Patrick Williams476a7e92022-12-06 09:52:53 -0600124 echo "Failed to build docker container."
125 exit 1
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500126fi
Joel Stanleyb23c4cc2018-10-31 18:47:25 +1030127
128docker run \
129 --rm=true \
Patrick Williams384d7412020-11-06 16:15:41 -0600130 -e WORKSPACE="${WORKSPACE}" \
Joel Stanleyb23c4cc2018-10-31 18:47:25 +1030131 -w "${HOME}" \
132 --user="${USER}" \
133 -v "${HOME}":"${HOME}" \
134 -t ${img_name} \
Patrick Williams384d7412020-11-06 16:15:41 -0600135 "${WORKSPACE}"/build.sh