blob: 545499223b3410bfdf51e573820bb8e138b141de [file] [log] [blame]
Joel Stanley0b851182016-06-21 23:51:19 +09301#!/bin/bash
Alanny Lopezcce369b2017-06-20 09:52:50 -05002###############################################################################
3#
4# This build script is for running the QEMU build as a container with the
5# option of launching the container with Docker or Kubernetes.
6#
7###############################################################################
8#
9# Variables used for in the build:
10# WORKSPACE = Path of the workspace directory where some intermediate files
11# and the images will be saved to.
Alanny Lopeza61e99a2017-06-27 14:20:48 -050012# qemudir = Path of the directory that holds the QEMU repo, if none
13# exists will clone in the OpenBMC/QEMU repo to WORKSPACE.
14# builddir = Path of the directory that is created within the docker
15# container where the build is actually done. Done this way to
16# allow external volumes to be used for the qemudir.
Alanny Lopezcce369b2017-06-20 09:52:50 -050017#
18# Optional Variables:
19# launch = job|pod
20# Can be left blank to launch via Docker if not using
21# Kubernetes to launch the container.
22# Job lets you keep a copy of job and container logs on the
23# api, can be useful if not using Jenkins as you can run the
24# job again via the api without needing this script.
25# Pod launches a container which runs to completion without
26# saving anything to the api when it completes.
27# imgname = Defaults to qemu-build with the arch as its tag, can be
28# changed or passed to give a specific name to created image.
29# http_proxy = The HTTP address for the proxy server you wish to connect to.
30#
31###############################################################################
Joel Stanley0b851182016-06-21 23:51:19 +093032
33# Trace bash processing
34set -x
35
36# Default variables
37WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
38http_proxy=${http_proxy:-}
Alanny Lopez41e2ada2017-06-15 13:54:43 -050039launch=${launch:-}
Alanny Lopezcce369b2017-06-20 09:52:50 -050040qemudir=${qemudir:-${WORKSPACE}/qemu}
Alanny Lopeza61e99a2017-06-27 14:20:48 -050041builddir=${builddir:-/tmp/qemu}
Alanny Lopezcce369b2017-06-20 09:52:50 -050042ARCH=$(uname -m)
43imgname=${imgname:-qemu-build:${ARCH}}
Joel Stanley0b851182016-06-21 23:51:19 +093044
45# Timestamp for job
46echo "Build started, $(date)"
47
Alanny Lopez41e2ada2017-06-15 13:54:43 -050048# Setup Proxy
Joel Stanley0b851182016-06-21 23:51:19 +093049if [[ -n "${http_proxy}" ]]; then
50PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
51fi
52
Alanny Lopez41e2ada2017-06-15 13:54:43 -050053# Determine the prefix of the Dockerfile's base image
54case ${ARCH} in
55 "ppc64le")
56 DOCKER_BASE="ppc64le/"
57 ;;
58 "x86_64")
59 DOCKER_BASE=""
60 ;;
61 *)
62 echo "Unsupported system architecture(${ARCH}) found for docker image"
63 exit 1
64esac
Joel Stanley0b851182016-06-21 23:51:19 +093065
Alanny Lopezcce369b2017-06-20 09:52:50 -050066# If there is no qemu directory, git clone in the openbmc mirror
67if [ ! -d ${qemudir} ]; then
68 echo "Clone in openbmc master to ${qemudir}"
69 git clone https://github.com/openbmc/qemu ${qemudir}
70fi
71
Joel Stanley0b851182016-06-21 23:51:19 +093072# Create the docker run script
73export PROXY_HOST=${http_proxy/#http*:\/\/}
74export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
75export PROXY_PORT=${http_proxy/#http*:\/\/*:}
76
77mkdir -p ${WORKSPACE}
78
79cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
80#!/bin/bash
81
82set -x
83
Alanny Lopeza61e99a2017-06-27 14:20:48 -050084# create a copy of the qemudir in /qemu to use as the build directory
85cp -a ${qemudir}/. ${builddir}
86
87# Go into the build directory
88cd ${builddir}
Joel Stanley0b851182016-06-21 23:51:19 +093089
90gcc --version
Alanny Lopez41e2ada2017-06-15 13:54:43 -050091git submodule update --init dtc
Joel Stanley0b851182016-06-21 23:51:19 +093092# disable anything that requires us to pull in X
Alanny Lopeze30237c2017-06-15 13:27:47 -050093./configure \
94 --target-list=arm-softmmu \
95 --disable-spice \
96 --disable-docs \
97 --disable-gtk \
98 --disable-smartcard \
99 --disable-usb-redir \
100 --disable-libusb \
101 --disable-sdl \
102 --disable-gnutls \
103 --disable-vte \
104 --disable-vnc \
105 --disable-vnc-png
Joel Stanley0b851182016-06-21 23:51:19 +0930106make -j4
107
Alanny Lopeza61e99a2017-06-27 14:20:48 -0500108cp -a ${builddir}/arm-softmmu/. ${WORKSPACE}/arm-softmmu/
Joel Stanley0b851182016-06-21 23:51:19 +0930109EOF_SCRIPT
110
111chmod a+x ${WORKSPACE}/build.sh
112
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500113# Configure docker build
114Dockerfile=$(cat << EOF
115FROM ${DOCKER_BASE}ubuntu:16.04
116
117${PROXY}
118
119ENV DEBIAN_FRONTEND noninteractive
120RUN apt-get update && apt-get install -yy --no-install-recommends \
121 bison \
122 flex \
123 gcc \
124 git \
125 libc6-dev \
126 libfdt-dev \
127 libglib2.0-dev \
128 libpixman-1-dev \
129 make \
130 python-yaml \
131 python3-yaml
132
133RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
134RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
135USER ${USER}
Alanny Lopeza61e99a2017-06-27 14:20:48 -0500136RUN mkdir ${builddir}
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500137ENV HOME ${HOME}
138EOF
139)
140
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500141# If Launch is left empty will create a docker container
142if [[ "${launch}" == "" ]]; then
143
144 docker build -t ${imgname} - <<< "${Dockerfile}"
145 if [[ "$?" -ne 0 ]]; then
146 echo "Failed to build docker container."
147 exit 1
148 fi
Alanny Lopezcce369b2017-06-20 09:52:50 -0500149 mountqemu="-v ""${qemudir}"":""${qemudir}"" "
Alanny Lopez634ce362017-06-23 12:57:05 -0500150 if [[ "${qemudir}" = "${HOME}/"* || "${qemudir}" = "${HOME}" ]]; then
Alanny Lopezcce369b2017-06-20 09:52:50 -0500151 mountqemu=""
152 fi
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500153 docker run \
154 --rm=true \
155 -e WORKSPACE=${WORKSPACE} \
156 -w "${HOME}" \
157 -v "${HOME}":"${HOME}" \
Alanny Lopezcce369b2017-06-20 09:52:50 -0500158 ${mountqemu} \
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500159 -t ${imgname} \
160 ${WORKSPACE}/build.sh
Alanny Lopez634ce362017-06-23 12:57:05 -0500161elif [[ "${launch}" == "pod" || "${launch}" == "job" ]]; then
162 . ./kubernetes/kubernetes-launch.sh QEMU-build true true
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500163else
164 echo "Launch Parameter is invalid"
165fi
166
167