blob: 94681591b677a464f43260f9f13d4ee5952e2e70 [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
99chmod a+x ${WORKSPACE}/build.sh
100
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500101# Configure docker build
102Dockerfile=$(cat << EOF
103FROM ${DOCKER_BASE}ubuntu:16.04
104
105${PROXY}
106
107ENV DEBIAN_FRONTEND noninteractive
108RUN apt-get update && apt-get install -yy --no-install-recommends \
109 bison \
110 flex \
111 gcc \
112 git \
113 libc6-dev \
114 libfdt-dev \
115 libglib2.0-dev \
116 libpixman-1-dev \
117 make \
118 python-yaml \
Saqib Khan5158a322017-10-23 11:31:24 -0500119 python3-yaml \
120 iputils-ping
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500121
122RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
123RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
124USER ${USER}
125ENV HOME ${HOME}
126EOF
127)
128
Alanny Lopez1246b032018-02-24 23:34:55 -0600129docker build -t ${img_name} - <<< "${Dockerfile}"
Joel Stanleyb23c4cc2018-10-31 18:47:25 +1030130if [[ "$?" -ne 0 ]]; then
131 echo "Failed to build docker container."
132 exit 1
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500133fi
Joel Stanleyb23c4cc2018-10-31 18:47:25 +1030134
135docker run \
136 --rm=true \
137 -e WORKSPACE=${WORKSPACE} \
138 -w "${HOME}" \
139 --user="${USER}" \
140 -v "${HOME}":"${HOME}" \
141 -t ${img_name} \
142 ${WORKSPACE}/build.sh