blob: 56a7483caa0a4307cca302fc3b77c5fef00d031c [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.
12# qemudir = Path of the QEMU directory where the build will be done, if
13# none exists will clone in the OpenBMC/QEMU repo to WORKSPACE.
14#
15# Optional Variables:
16# launch = job|pod
17# Can be left blank to launch via Docker if not using
18# Kubernetes to launch the container.
19# Job lets you keep a copy of job and container logs on the
20# api, can be useful if not using Jenkins as you can run the
21# job again via the api without needing this script.
22# Pod launches a container which runs to completion without
23# saving anything to the api when it completes.
24# imgname = Defaults to qemu-build with the arch as its tag, can be
25# changed or passed to give a specific name to created image.
26# http_proxy = The HTTP address for the proxy server you wish to connect to.
27#
28###############################################################################
Joel Stanley0b851182016-06-21 23:51:19 +093029
30# Trace bash processing
31set -x
32
33# Default variables
34WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
35http_proxy=${http_proxy:-}
Alanny Lopez41e2ada2017-06-15 13:54:43 -050036launch=${launch:-}
Alanny Lopezcce369b2017-06-20 09:52:50 -050037qemudir=${qemudir:-${WORKSPACE}/qemu}
38ARCH=$(uname -m)
39imgname=${imgname:-qemu-build:${ARCH}}
Joel Stanley0b851182016-06-21 23:51:19 +093040
41# Timestamp for job
42echo "Build started, $(date)"
43
Alanny Lopez41e2ada2017-06-15 13:54:43 -050044# Setup Proxy
Joel Stanley0b851182016-06-21 23:51:19 +093045if [[ -n "${http_proxy}" ]]; then
46PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
47fi
48
Alanny Lopez41e2ada2017-06-15 13:54:43 -050049# Determine the prefix of the Dockerfile's base image
50case ${ARCH} in
51 "ppc64le")
52 DOCKER_BASE="ppc64le/"
53 ;;
54 "x86_64")
55 DOCKER_BASE=""
56 ;;
57 *)
58 echo "Unsupported system architecture(${ARCH}) found for docker image"
59 exit 1
60esac
Joel Stanley0b851182016-06-21 23:51:19 +093061
Alanny Lopezcce369b2017-06-20 09:52:50 -050062# If there is no qemu directory, git clone in the openbmc mirror
63if [ ! -d ${qemudir} ]; then
64 echo "Clone in openbmc master to ${qemudir}"
65 git clone https://github.com/openbmc/qemu ${qemudir}
66fi
67
Joel Stanley0b851182016-06-21 23:51:19 +093068# Create the docker run script
69export PROXY_HOST=${http_proxy/#http*:\/\/}
70export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
71export PROXY_PORT=${http_proxy/#http*:\/\/*:}
72
73mkdir -p ${WORKSPACE}
74
75cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
76#!/bin/bash
77
78set -x
79
Alanny Lopezcce369b2017-06-20 09:52:50 -050080# Go into the source directory (the script will put us in a build subdir)
81cd ${qemudir}
Joel Stanley0b851182016-06-21 23:51:19 +093082
83gcc --version
Alanny Lopez41e2ada2017-06-15 13:54:43 -050084git submodule update --init dtc
Joel Stanley0b851182016-06-21 23:51:19 +093085# disable anything that requires us to pull in X
Alanny Lopeze30237c2017-06-15 13:27:47 -050086./configure \
87 --target-list=arm-softmmu \
88 --disable-spice \
89 --disable-docs \
90 --disable-gtk \
91 --disable-smartcard \
92 --disable-usb-redir \
93 --disable-libusb \
94 --disable-sdl \
95 --disable-gnutls \
96 --disable-vte \
97 --disable-vnc \
98 --disable-vnc-png
Joel Stanley0b851182016-06-21 23:51:19 +093099make -j4
100
101EOF_SCRIPT
102
103chmod a+x ${WORKSPACE}/build.sh
104
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500105# Configure docker build
106Dockerfile=$(cat << EOF
107FROM ${DOCKER_BASE}ubuntu:16.04
108
109${PROXY}
110
111ENV DEBIAN_FRONTEND noninteractive
112RUN apt-get update && apt-get install -yy --no-install-recommends \
113 bison \
114 flex \
115 gcc \
116 git \
117 libc6-dev \
118 libfdt-dev \
119 libglib2.0-dev \
120 libpixman-1-dev \
121 make \
122 python-yaml \
123 python3-yaml
124
125RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
126RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
127USER ${USER}
128ENV HOME ${HOME}
129EOF
130)
131
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500132# If Launch is left empty will create a docker container
133if [[ "${launch}" == "" ]]; then
134
135 docker build -t ${imgname} - <<< "${Dockerfile}"
136 if [[ "$?" -ne 0 ]]; then
137 echo "Failed to build docker container."
138 exit 1
139 fi
Alanny Lopezcce369b2017-06-20 09:52:50 -0500140 mountqemu="-v ""${qemudir}"":""${qemudir}"" "
Alanny Lopez634ce362017-06-23 12:57:05 -0500141 if [[ "${qemudir}" = "${HOME}/"* || "${qemudir}" = "${HOME}" ]]; then
Alanny Lopezcce369b2017-06-20 09:52:50 -0500142 mountqemu=""
143 fi
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500144 docker run \
145 --rm=true \
146 -e WORKSPACE=${WORKSPACE} \
147 -w "${HOME}" \
148 -v "${HOME}":"${HOME}" \
Alanny Lopezcce369b2017-06-20 09:52:50 -0500149 ${mountqemu} \
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500150 -t ${imgname} \
151 ${WORKSPACE}/build.sh
Alanny Lopez634ce362017-06-23 12:57:05 -0500152elif [[ "${launch}" == "pod" || "${launch}" == "job" ]]; then
153 . ./kubernetes/kubernetes-launch.sh QEMU-build true true
Alanny Lopez41e2ada2017-06-15 13:54:43 -0500154else
155 echo "Launch Parameter is invalid"
156fi
157
158