blob: 9f07cb7eaafc1fe75bb359952a9f0b14e3e0736f [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 ;;
59 *)
60 echo "Unsupported system architecture(${ARCH}) found for docker image"
61 exit 1
62esac
Joel Stanley0b851182016-06-21 23:51:19 +093063
64# Create the docker run script
65export PROXY_HOST=${http_proxy/#http*:\/\/}
66export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
67export PROXY_PORT=${http_proxy/#http*:\/\/*:}
68
Joel Stanley0b851182016-06-21 23:51:19 +093069cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
70#!/bin/bash
71
72set -x
73
Alanny Lopeza61e99a2017-06-27 14:20:48 -050074# Go into the build directory
Joel Stanleyb23c4cc2018-10-31 18:47:25 +103075cd ${WORKSPACE}/qemu
Joel Stanley0b851182016-06-21 23:51:19 +093076
77gcc --version
Alanny Lopez41e2ada2017-06-15 13:54:43 -050078git submodule update --init dtc
Joel Stanley0b851182016-06-21 23:51:19 +093079# disable anything that requires us to pull in X
Alanny Lopeze30237c2017-06-15 13:27:47 -050080./configure \
81 --target-list=arm-softmmu \
82 --disable-spice \
83 --disable-docs \
84 --disable-gtk \
85 --disable-smartcard \
86 --disable-usb-redir \
87 --disable-libusb \
88 --disable-sdl \
89 --disable-gnutls \
90 --disable-vte \
91 --disable-vnc \
Joel Stanleye32aaee2018-10-24 15:30:17 +103092 --disable-werror \
Alanny Lopeze30237c2017-06-15 13:27:47 -050093 --disable-vnc-png
Joel Stanleyb23c4cc2018-10-31 18:47:25 +103094make clean
Joel Stanley0b851182016-06-21 23:51:19 +093095make -j4
96
97EOF_SCRIPT
98
Patrick Williams384d7412020-11-06 16:15:41 -060099chmod a+x "${WORKSPACE}"/build.sh
Joel Stanley0b851182016-06-21 23:51:19 +0930100
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500101# Configure docker build
Andrew Jefferya311abc2021-01-15 14:22:34 +1030102
103# !!!
104# Keep the base docker image in sync with the image under which we run the
105# resulting qemu binary.
106# !!!
107
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500108Dockerfile=$(cat << EOF
Andrew Jefferya311abc2021-01-15 14:22:34 +1030109FROM ${DOCKER_BASE}ubuntu:bionic
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500110
111${PROXY}
112
113ENV DEBIAN_FRONTEND noninteractive
114RUN apt-get update && apt-get install -yy --no-install-recommends \
115 bison \
Andrew Jeffery41826802021-01-15 14:23:35 +1030116 bzip2 \
Joel Stanleya3f390e2019-01-16 00:24:25 +1100117 ca-certificates \
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500118 flex \
119 gcc \
120 git \
121 libc6-dev \
122 libfdt-dev \
123 libglib2.0-dev \
124 libpixman-1-dev \
125 make \
Andrew Jeffery41826802021-01-15 14:23:35 +1030126 ninja-build \
Saqib Khan5158a322017-10-23 11:31:24 -0500127 python3-yaml \
128 iputils-ping
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500129
Patrick Williams384d7412020-11-06 16:15:41 -0600130RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
131RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500132USER ${USER}
133ENV HOME ${HOME}
134EOF
135)
136
Patrick Williams384d7412020-11-06 16:15:41 -0600137if ! docker build -t ${img_name} - <<< "${Dockerfile}" ; then
Joel Stanleyb23c4cc2018-10-31 18:47:25 +1030138 echo "Failed to build docker container."
139 exit 1
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500140fi
Joel Stanleyb23c4cc2018-10-31 18:47:25 +1030141
142docker run \
143 --rm=true \
Patrick Williams384d7412020-11-06 16:15:41 -0600144 -e WORKSPACE="${WORKSPACE}" \
Joel Stanleyb23c4cc2018-10-31 18:47:25 +1030145 -w "${HOME}" \
146 --user="${USER}" \
147 -v "${HOME}":"${HOME}" \
148 -t ${img_name} \
Patrick Williams384d7412020-11-06 16:15:41 -0600149 "${WORKSPACE}"/build.sh