1#!/bin/bash 2############################################################################### 3# 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 16# 17############################################################################### 18# 19# Script Variables: 20# http_proxy The HTTP address of the proxy server to connect to. 21# Default: "", proxy is not setup if this is not set 22# WORKSPACE Path of the workspace directory where the build will 23# occur, and output artifacts will be produced. 24# 25############################################################################### 26# Trace bash processing 27#set -x 28 29# Script Variables: 30http_proxy=${http_proxy:-} 31 32if [ -z ${WORKSPACE+x} ]; then 33 echo "Please set WORKSPACE variable" 34 exit 1 35fi 36 37# Docker Image Build Variables: 38img_name=qemu-build 39 40# Timestamp for job 41echo "Build started, $(date)" 42 43# Setup Proxy 44if [[ -n "${http_proxy}" ]]; then 45 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" 46fi 47 48# 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 53cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT 54#!/bin/bash 55 56set -x 57 58# Go into the build directory 59cd ${WORKSPACE}/qemu 60 61gcc --version 62git submodule update --init dtc 63# disable anything that requires us to pull in X 64./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 \ 76 --disable-werror 77make clean 78make -j4 79 80EOF_SCRIPT 81 82chmod a+x "${WORKSPACE}"/build.sh 83 84# Configure docker build 85 86# !!! 87# Keep the base docker image in sync with the image under which we run the 88# resulting qemu binary. 89# !!! 90 91Dockerfile=$(cat << EOF 92FROM ubuntu:jammy 93 94${PROXY} 95 96ENV DEBIAN_FRONTEND noninteractive 97RUN apt-get update && apt-get install -yy --no-install-recommends \ 98 bison \ 99 bzip2 \ 100 ca-certificates \ 101 flex \ 102 gcc \ 103 git \ 104 libc6-dev \ 105 libfdt-dev \ 106 libglib2.0-dev \ 107 libpixman-1-dev \ 108 libslirp-dev \ 109 make \ 110 ninja-build \ 111 python3-tomli \ 112 python3-venv \ 113 python3-yaml \ 114 iputils-ping 115 116RUN 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} 118USER ${USER} 119ENV HOME ${HOME} 120EOF 121) 122 123if ! docker build -t ${img_name} - <<< "${Dockerfile}" ; then 124 echo "Failed to build docker container." 125 exit 1 126fi 127 128docker run \ 129 --rm=true \ 130 -e WORKSPACE="${WORKSPACE}" \ 131 -w "${HOME}" \ 132 --user="${USER}" \ 133 -v "${HOME}":"${HOME}" \ 134 -t ${img_name} \ 135 "${WORKSPACE}"/build.sh 136