blob: c17b654409d94890f3d5be6728ad4fd62a6eeac0 [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
Patrick Williams476a7e92022-12-06 09:52:53 -060048 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
Joel Stanley0b851182016-06-21 23:51:19 +093049fi
50
Alanny Lopez41e2ada2017-06-15 13:54:43 -050051# Determine the prefix of the Dockerfile's base image
52case ${ARCH} in
Patrick Williams476a7e92022-12-06 09:52:53 -060053 "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 Lopez41e2ada2017-06-15 13:54:43 -050065esac
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 \
Andrew Geissler4a015822022-12-19 15:39:54 -060095 --disable-werror
Joel Stanleyb23c4cc2018-10-31 18:47:25 +103096make clean
Joel Stanley0b851182016-06-21 23:51:19 +093097make -j4
98
99EOF_SCRIPT
100
Patrick Williams384d7412020-11-06 16:15:41 -0600101chmod a+x "${WORKSPACE}"/build.sh
Joel Stanley0b851182016-06-21 23:51:19 +0930102
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500103# Configure docker build
Andrew Jefferya311abc2021-01-15 14:22:34 +1030104
105# !!!
106# Keep the base docker image in sync with the image under which we run the
107# resulting qemu binary.
108# !!!
109
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500110Dockerfile=$(cat << EOF
Andrew Geissler851eaff2022-12-22 09:47:54 -0600111FROM ${DOCKER_BASE}ubuntu:jammy
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500112
113${PROXY}
114
115ENV DEBIAN_FRONTEND noninteractive
116RUN apt-get update && apt-get install -yy --no-install-recommends \
117 bison \
Andrew Jeffery41826802021-01-15 14:23:35 +1030118 bzip2 \
Joel Stanleya3f390e2019-01-16 00:24:25 +1100119 ca-certificates \
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500120 flex \
121 gcc \
122 git \
123 libc6-dev \
124 libfdt-dev \
125 libglib2.0-dev \
126 libpixman-1-dev \
Andrew Geissler4a015822022-12-19 15:39:54 -0600127 libslirp-dev \
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500128 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
Patrick Williams476a7e92022-12-06 09:52:53 -0600141 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