blob: 5d99bc1b754b5cd7efe7d8c5a626e73a33718f4b [file] [log] [blame]
Alanny Lopez56fc36a2017-07-27 13:55:44 -05001#!/bin/bash
Alanny Lopezb0a12dd2017-04-24 16:21:47 -05002###############################################################################
Chris Smart02651712015-11-11 11:09:00 +11003#
Michael Shepos3939e952019-01-16 16:00:35 -06004# This build script is for running the OpenBMC builds as Docker containers.
Alanny Lopez3fbaa512017-04-24 15:46:52 -05005#
Alanny Lopezb0a12dd2017-04-24 16:21:47 -05006###############################################################################
7#
Alanny Lopeze08e8702018-02-24 18:07:13 -06008# Script Variables:
9# build_scripts_dir The path of the openbmc-build-scripts directory.
10# Default: The directory containing this script
11# http_proxy The HTTP address of the proxy server to connect to.
12# Default: "", proxy is not setup if this is not set
13# WORKSPACE Path of the workspace directory where some intermediate
14# files and the images will be saved to.
15# Default: "~/{RandomNumber}"
Andrew Geisslerdc1e7022018-03-26 07:54:48 -070016# num_cpu Number of cpu's to give bitbake, default is total amount
17# in system
Lei YU39587ad2020-06-17 19:55:54 +080018# UBUNTU_MIRROR: <optional, the URL of a mirror of Ubuntu to override the
19# default ones in /etc/apt/sources.list>
20# default is empty, and no mirror is used.
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050021#
Alanny Lopeze08e8702018-02-24 18:07:13 -060022# Docker Image Build Variables:
Alanny Lopez1246b032018-02-24 23:34:55 -060023# BITBAKE_OPTS Set to "-c populate_sdk" or whatever other BitBake options
Alanny Lopeze08e8702018-02-24 18:07:13 -060024# you'd like to pass into the build.
25# Default: "", no options set
Alanny Lopez1246b032018-02-24 23:34:55 -060026# build_dir Path where the actual BitBake build occurs inside the
Alanny Lopeze08e8702018-02-24 18:07:13 -060027# container, path cannot be located on network storage.
28# Default: "/tmp/openbmc"
29# distro The distro used as the base image for the build image:
30# fedora|ubuntu
31# Default: "ubuntu"
Alanny Lopez1246b032018-02-24 23:34:55 -060032# img_name The name given to the target build's docker image.
Alanny Lopeze08e8702018-02-24 18:07:13 -060033# Default: "openbmc/${distro}:${imgtag}-${target}-${ARCH}"
Alanny Lopez1246b032018-02-24 23:34:55 -060034# img_tag The base docker image distro tag:
Alanny Lopeze08e8702018-02-24 18:07:13 -060035# ubuntu: latest|16.04|14.04|trusty|xenial
36# fedora: 23|24|25
37# Default: "latest"
38# target The target we aim to build:
Andrew Geisslerdd820722018-02-20 13:42:58 -060039# evb-ast2500|palmetto|qemu|qemux86-64
Andrew Geisslerdd9e1962019-08-15 08:27:28 -050040# romulus|s2600wf|witherspoon|zaius|tiogapass|gsj|mihawk
Andrew Geisslerf86b4a82019-09-27 15:21:11 -050041# witherspoon-tacoma|rainier
Alanny Lopeze08e8702018-02-24 18:07:13 -060042# Default: "qemu"
Andrew Geissler215e43c2019-04-23 10:57:48 -050043# no_tar Set to true if you do not want the debug tar built
44# Default: "false"
Michael Shepos33aeca42019-06-13 02:36:17 -050045# nice_priority Set nice priotity for bitbake command.
46# Nice:
47# Run with an adjusted niceness, which affects process
48# scheduling. Nice values range from -20 (most favorable
49# to the process) to 19 (least favorable to the process).
50# Default: "", nice is not used if nice_priority is not set
Alanny Lopez723fea62017-09-12 11:22:17 -050051#
Alanny Lopeze08e8702018-02-24 18:07:13 -060052# Deployment Variables:
Alanny Lopez1246b032018-02-24 23:34:55 -060053# obmc_dir Path of the OpenBMC repo directory used as a reference
Alanny Lopeze08e8702018-02-24 18:07:13 -060054# for the build inside the container.
55# Default: "${WORKSPACE}/openbmc"
Michael Shepos10afbb22019-02-06 13:33:07 -060056# xtrct_small_copy_dir
57# Directory within build_dir that should be copied to
58# xtrct_path. The directory and all parents up to, but not
59# including, build_dir will be copied. For example, if
60# build_dir is set to "/tmp/openbmc" and this is set to
61# "build/tmp", the directory at xtrct_path will have the
62# following directory structure:
63# xtrct_path
64# | - build
65# | - tmp
66# ...
67# Can also be set to the empty string to copy the entire
68# contents of build_dir to xtrct_path.
69# Default: "deploy/images".
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050070#
71###############################################################################
Joel Stanley4b8b2392016-02-12 15:44:57 +103072# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103073set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110074
Alanny Lopez46967702018-02-25 00:29:14 -060075# Script Variables:
76build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"}
77http_proxy=${http_proxy:-}
78WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Andrew Geisslerdc1e7022018-03-26 07:54:48 -070079num_cpu=${num_cpu:-$(nproc)}
Lei YU39587ad2020-06-17 19:55:54 +080080UBUNTU_MIRROR=${UBUNTU_MIRROR:-""}
Alanny Lopez46967702018-02-25 00:29:14 -060081
82# Docker Image Build Variables:
83build_dir=${build_dir:-/tmp/openbmc}
Chris Smart02651712015-11-11 11:09:00 +110084distro=${distro:-ubuntu}
Alanny Lopez1246b032018-02-24 23:34:55 -060085img_tag=${img_tag:-latest}
Alanny Lopez46967702018-02-25 00:29:14 -060086target=${target:-qemu}
Andrew Geissler215e43c2019-04-23 10:57:48 -050087no_tar=${no_tar:-false}
Michael Shepos33aeca42019-06-13 02:36:17 -050088nice_priority=${nice_priority:-}
Alanny Lopez46967702018-02-25 00:29:14 -060089
90# Deployment variables
Alanny Lopez46967702018-02-25 00:29:14 -060091obmc_dir=${obmc_dir:-${WORKSPACE}/openbmc}
Michael Shepos3939e952019-01-16 16:00:35 -060092ssc_dir=${HOME}
Michael Shepos10afbb22019-02-06 13:33:07 -060093xtrct_small_copy_dir=${xtrct_small_copy_dir:-deploy/images}
Michael Shepos3939e952019-01-16 16:00:35 -060094xtrct_path="${obmc_dir}/build/tmp"
95xtrct_copy_timeout="300"
Alanny Lopez46967702018-02-25 00:29:14 -060096
Andrew Geissler2eb45d32019-09-18 21:56:44 -050097bitbake_target="obmc-phosphor-image"
Chris Smartc3522542016-02-16 11:59:36 +110098PROXY=""
Chris Smart02651712015-11-11 11:09:00 +110099
Lei YU39587ad2020-06-17 19:55:54 +0800100MIRROR=""
101if [[ -n "${UBUNTU_MIRROR}" ]]; then
102 MIRROR="RUN echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME) main restricted universe multiverse\" > /etc/apt/sources.list && \
103 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-updates main restricted universe multiverse\" >> /etc/apt/sources.list && \
104 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-security main restricted universe multiverse\" >> /etc/apt/sources.list && \
105 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-proposed main restricted universe multiverse\" >> /etc/apt/sources.list && \
106 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-backports main restricted universe multiverse\" >> /etc/apt/sources.list"
107fi
108
Alanny Lopezccc650e2017-04-24 15:14:20 -0500109# Determine the architecture
110ARCH=$(uname -m)
111
112# Determine the prefix of the Dockerfile's base image
113case ${ARCH} in
114 "ppc64le")
115 DOCKER_BASE="ppc64le/"
116 ;;
117 "x86_64")
118 DOCKER_BASE=""
119 ;;
120 *)
121 echo "Unsupported system architecture(${ARCH}) found for docker image"
122 exit 1
123esac
Andrew Geissler11abbbe2016-08-14 19:39:47 -0500124
Chris Smart02651712015-11-11 11:09:00 +1100125# Timestamp for job
126echo "Build started, $(date)"
127
Alanny Lopez1246b032018-02-24 23:34:55 -0600128# If the obmc_dir directory doesn't exist clone it in
129if [ ! -d ${obmc_dir} ]; then
130 echo "Clone in openbmc master to ${obmc_dir}"
131 git clone https://github.com/openbmc/openbmc ${obmc_dir}
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500132fi
133
Alanny Lopez1246b032018-02-24 23:34:55 -0600134# Make and chown the xtrct_path directory to avoid permission errors
135if [ ! -d ${xtrct_path} ]; then
136 mkdir -p ${xtrct_path}
Alanny Lopez723fea62017-09-12 11:22:17 -0500137fi
Alanny Lopez1246b032018-02-24 23:34:55 -0600138chown ${UID}:${GROUPS} ${xtrct_path}
Alanny Lopez723fea62017-09-12 11:22:17 -0500139
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500140# Work out what build target we should be running and set BitBake command
Michael Shepos2de03e92018-11-07 15:54:56 -0600141MACHINE=""
Chris Smart02651712015-11-11 11:09:00 +1100142case ${target} in
Chris Smart02651712015-11-11 11:09:00 +1100143 palmetto)
Brad Bishop7161a172018-10-05 16:48:06 -0400144 LAYER_DIR="meta-ibm/meta-palmetto"
Brad Bishop91a200b2019-08-22 14:24:33 -0400145 MACHINE="palmetto"
146 DISTRO="openbmc-openpower"
Chris Smart02651712015-11-11 11:09:00 +1100147 ;;
Adriana Kobylak4ec7db02019-05-07 12:44:30 -0500148 swift)
Brad Bishopf713bf42019-11-13 20:23:32 -0500149 LAYER_DIR="meta-ibm"
Adriana Kobylak4ec7db02019-05-07 12:44:30 -0500150 MACHINE="swift"
Brad Bishop91a200b2019-08-22 14:24:33 -0400151 DISTRO="openbmc-witherspoon"
Adriana Kobylak4ec7db02019-05-07 12:44:30 -0500152 ;;
Andrew Geisslerdd9e1962019-08-15 08:27:28 -0500153 mihawk)
Brad Bishopf713bf42019-11-13 20:23:32 -0500154 LAYER_DIR="meta-ibm"
Andrew Geisslerdd9e1962019-08-15 08:27:28 -0500155 MACHINE="mihawk"
Brad Bishop91a200b2019-08-22 14:24:33 -0400156 DISTRO="openbmc-witherspoon"
Andrew Geisslerdd9e1962019-08-15 08:27:28 -0500157 ;;
Joel Stanley0e077202016-06-28 16:42:45 +0930158 witherspoon)
Brad Bishopf713bf42019-11-13 20:23:32 -0500159 LAYER_DIR="meta-ibm"
Brad Bishop91a200b2019-08-22 14:24:33 -0400160 MACHINE="witherspoon"
161 DISTRO="openbmc-witherspoon"
Joel Stanley0e077202016-06-28 16:42:45 +0930162 ;;
Adriana Kobylakfcba1c32019-05-10 11:33:37 -0500163 witherspoon-128)
Brad Bishopf713bf42019-11-13 20:23:32 -0500164 LAYER_DIR="meta-ibm"
Adriana Kobylakfcba1c32019-05-10 11:33:37 -0500165 MACHINE="witherspoon-128"
Brad Bishop91a200b2019-08-22 14:24:33 -0400166 DISTRO="openbmc-witherspoon"
Adriana Kobylakfcba1c32019-05-10 11:33:37 -0500167 ;;
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500168 witherspoon-tacoma)
Brad Bishopf713bf42019-11-13 20:23:32 -0500169 LAYER_DIR="meta-ibm"
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500170 MACHINE="witherspoon-tacoma"
171 DISTRO="openbmc-openpower"
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500172 ;;
Andrew Geisslerf86b4a82019-09-27 15:21:11 -0500173 rainier)
Brad Bishopf713bf42019-11-13 20:23:32 -0500174 LAYER_DIR="meta-ibm"
Andrew Geisslerf86b4a82019-09-27 15:21:11 -0500175 MACHINE="rainier"
176 DISTRO="openbmc-openpower"
177 ;;
Joel Stanley0e077202016-06-28 16:42:45 +0930178 evb-ast2500)
Brad Bishop7161a172018-10-05 16:48:06 -0400179 LAYER_DIR="meta-evb/meta-evb-aspeed/meta-evb-ast2500"
Brad Bishop91a200b2019-08-22 14:24:33 -0400180 MACHINE="evb-ast2500"
181 DISTRO="openbmc-phosphor"
Joel Stanley0e077202016-06-28 16:42:45 +0930182 ;;
Ed Tanous6dc40d92018-07-30 11:13:36 -0700183 s2600wf)
Brad Bishop7161a172018-10-05 16:48:06 -0400184 LAYER_DIR="meta-intel/meta-s2600wf"
Brad Bishop91a200b2019-08-22 14:24:33 -0400185 MACHINE="s2600wf"
186 DISTRO="openbmc-phosphor"
Ed Tanous6dc40d92018-07-30 11:13:36 -0700187 ;;
Joel Stanley915381f2016-11-01 16:58:59 +1030188 zaius)
Brad Bishop7161a172018-10-05 16:48:06 -0400189 LAYER_DIR="meta-ingrasys/meta-zaius"
Brad Bishop91a200b2019-08-22 14:24:33 -0400190 MACHINE="zaius"
191 DISTRO="openbmc-openpower"
Joel Stanley915381f2016-11-01 16:58:59 +1030192 ;;
193 romulus)
Brad Bishop7161a172018-10-05 16:48:06 -0400194 LAYER_DIR="meta-ibm/meta-romulus"
Brad Bishop91a200b2019-08-22 14:24:33 -0400195 MACHINE="romulus"
196 DISTRO="openbmc-openpower"
Joel Stanley915381f2016-11-01 16:58:59 +1030197 ;;
Vijay Khemka4c5b12e2019-01-23 14:50:09 -0800198 tiogapass)
199 LAYER_DIR="meta-facebook/meta-tiogapass"
Brad Bishop91a200b2019-08-22 14:24:33 -0400200 MACHINE="tiogapass"
201 DISTRO="openbmc-phosphor"
Vijay Khemka4c5b12e2019-01-23 14:50:09 -0800202 ;;
Andrew Geissler9eef7282019-05-10 13:28:09 -0500203 gsj)
204 LAYER_DIR="meta-quanta/meta-gsj"
Brad Bishop91a200b2019-08-22 14:24:33 -0400205 MACHINE="gsj"
Andrew Geissler8565d2a2020-04-20 15:22:14 -0500206 # Use default DISTRO from layer
Andrew Geissler9eef7282019-05-10 13:28:09 -0500207 ;;
Chris Smart02651712015-11-11 11:09:00 +1100208 *)
209 exit 1
210 ;;
211esac
212
Brad Bishop7161a172018-10-05 16:48:06 -0400213BITBAKE_CMD="TEMPLATECONF=${LAYER_DIR}/conf source oe-init-build-env"
214
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500215# Configure Docker build
Chris Smart02651712015-11-11 11:09:00 +1100216if [[ "${distro}" == fedora ]];then
217
218 if [[ -n "${http_proxy}" ]]; then
219 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
220 fi
221
222 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600223 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100224
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500225 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100226
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500227 # Set the locale
228 RUN locale-gen en_US.UTF-8
229 ENV LANG en_US.UTF-8
230 ENV LANGUAGE en_US:en
231 ENV LC_ALL en_US.UTF-8
Saqib Khan75635122017-03-23 10:57:34 -0500232
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500233 RUN dnf --refresh install -y \
234 bzip2 \
235 chrpath \
236 cpio \
237 diffstat \
238 findutils \
239 gcc \
240 gcc-c++ \
241 git \
242 make \
243 patch \
244 perl-bignum \
245 perl-Data-Dumper \
246 perl-Thread-Queue \
247 python-devel \
248 python3-devel \
249 SDL-devel \
250 socat \
251 subversion \
252 tar \
253 texinfo \
254 wget \
Saqib Khan5158a322017-10-23 11:31:24 -0500255 which \
256 iputils-ping
Chris Smart02651712015-11-11 11:09:00 +1100257
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500258 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
259 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100260
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500261 USER ${USER}
262 ENV HOME ${HOME}
263 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100264EOF
265)
266
Alanny Lopezccc650e2017-04-24 15:14:20 -0500267elif [[ "${distro}" == ubuntu ]]; then
268
Chris Smart02651712015-11-11 11:09:00 +1100269 if [[ -n "${http_proxy}" ]]; then
270 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
271 fi
272
273 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600274 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100275
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500276 ${PROXY}
Lei YU39587ad2020-06-17 19:55:54 +0800277 ${MIRROR}
Chris Smart02651712015-11-11 11:09:00 +1100278
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500279 ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500280
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500281 RUN apt-get update && apt-get install -yy \
282 build-essential \
283 chrpath \
284 debianutils \
285 diffstat \
286 gawk \
287 git \
288 libdata-dumper-simple-perl \
289 libsdl1.2-dev \
290 libthread-queue-any-perl \
Alanny Lopez27af3a02017-05-26 10:49:06 -0500291 locales \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500292 python \
293 python3 \
294 socat \
295 subversion \
296 texinfo \
297 cpio \
Saqib Khan5158a322017-10-23 11:31:24 -0500298 wget \
299 iputils-ping
Chris Smart02651712015-11-11 11:09:00 +1100300
Alanny Lopez27af3a02017-05-26 10:49:06 -0500301 # Set the locale
302 RUN locale-gen en_US.UTF-8
303 ENV LANG en_US.UTF-8
304 ENV LANGUAGE en_US:en
305 ENV LC_ALL en_US.UTF-8
306
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500307 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
308 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100309
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500310 USER ${USER}
311 ENV HOME ${HOME}
312 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100313EOF
314)
315fi
316
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500317# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100318export PROXY_HOST=${http_proxy/#http*:\/\/}
319export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
320export PROXY_PORT=${http_proxy/#http*:\/\/*:}
321
Chris Smart01d2b962015-11-11 18:05:30 +1100322mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100323
Andrew Geissler215e43c2019-04-23 10:57:48 -0500324# Determine command for bitbake image build
Andrew Geissler215e43c2019-04-23 10:57:48 -0500325if [ $no_tar = "false" ]; then
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500326 bitbake_target="${bitbake_target} obmc-phosphor-debug-tarball"
Andrew Geissler215e43c2019-04-23 10:57:48 -0500327fi
328
Chris Smart01d2b962015-11-11 18:05:30 +1100329cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100330#!/bin/bash
331
Joel Stanley38c9d142016-02-16 12:31:55 +1030332set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100333
Alanny Lopez723fea62017-09-12 11:22:17 -0500334# Go into the OpenBMC directory, the build will handle changing directories
Alanny Lopez1246b032018-02-24 23:34:55 -0600335cd ${obmc_dir}
Chris Smart02651712015-11-11 11:09:00 +1100336
337# Set up proxies
338export ftp_proxy=${http_proxy}
339export http_proxy=${http_proxy}
340export https_proxy=${http_proxy}
341
Chris Smart01d2b962015-11-11 18:05:30 +1100342mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100343
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500344# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100345if [[ -n "${http_proxy}" ]]; then
346
Chris Smartd30c5902016-03-01 15:00:54 +1100347 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500348 #!/bin/bash
349 # \$1 = hostname, \$2 = port
350 PROXY=${PROXY_HOST}
351 PROXY_PORT=${PROXY_PORT}
352 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100353EOF_GIT
354
Chris Smart01d2b962015-11-11 18:05:30 +1100355 chmod a+x ${WORKSPACE}/bin/git-proxy
356 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100357
Lei YUa76d7ce2020-05-11 15:20:56 +0800358 lock=${HOME}/build-setup.lock
359 flock \${lock} git config --global core.gitProxy ${WORKSPACE}/bin/git-proxy
360 flock \${lock} git config --global http.proxy ${http_proxy}
Chris Smart02651712015-11-11 11:09:00 +1100361
Lei YUa76d7ce2020-05-11 15:20:56 +0800362 flock \${lock} mkdir -p ~/.subversion
363 flock \${lock} cat > ~/.subversion/servers << EOF_SVN
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500364 [global]
365 http-proxy-host = ${PROXY_HOST}
366 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100367EOF_SVN
Lei YU58cb3ad2020-04-30 13:04:58 +0800368
Lei YUa76d7ce2020-05-11 15:20:56 +0800369 flock \${lock} cat > ~/.wgetrc << EOF_WGETRC
Lei YU58cb3ad2020-04-30 13:04:58 +0800370 https_proxy = ${http_proxy}
371 http_proxy = ${http_proxy}
372 use_proxy = on
373EOF_WGETRC
374
Lei YUa76d7ce2020-05-11 15:20:56 +0800375 flock \${lock} cat > ~/.curlrc << EOF_CURLRC
Lei YU58cb3ad2020-04-30 13:04:58 +0800376 proxy = ${PROXY_HOST}:${PROXY_PORT}
377EOF_CURLRC
Chris Smart02651712015-11-11 11:09:00 +1100378fi
379
380# Source our build env
381${BITBAKE_CMD}
382
Andrew Geissler8565d2a2020-04-20 15:22:14 -0500383if [[ -z "${MACHINE}" ]]; then
384 echo "MACHINE is not configured for ${target}"
Brad Bishop91a200b2019-08-22 14:24:33 -0400385 exit 1
Michael Shepos2de03e92018-11-07 15:54:56 -0600386fi
387
Brad Bishop91a200b2019-08-22 14:24:33 -0400388export MACHINE="${MACHINE}"
Andrew Geissler8565d2a2020-04-20 15:22:14 -0500389if [[ -z "${DISTRO}" ]]; then
390 echo "DISTRO is not configured for ${target} so will use default"
391 unset DISTRO
392else
393 export DISTRO="${DISTRO}"
394fi
Brad Bishop91a200b2019-08-22 14:24:33 -0400395
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500396# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100397cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100398BB_NUMBER_THREADS = "$(nproc)"
399PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100400INHERIT += "rm_work"
401BB_GENERATE_MIRROR_TARBALLS = "1"
Alanny Lopez1246b032018-02-24 23:34:55 -0600402DL_DIR="${ssc_dir}/bitbake_downloads"
403SSTATE_DIR="${ssc_dir}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100404USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500405INHERIT_remove = "uninative"
Alanny Lopez1246b032018-02-24 23:34:55 -0600406TMPDIR="${build_dir}"
Chris Smart02651712015-11-11 11:09:00 +1100407EOF_CONF
408
409# Kick off a build
Michael Shepos33aeca42019-06-13 02:36:17 -0500410if [[ -n "${nice_priority}" ]]; then
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500411 nice -${nice_priority} bitbake ${BITBAKE_OPTS} ${bitbake_target}
Michael Shepos33aeca42019-06-13 02:36:17 -0500412else
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500413 bitbake ${BITBAKE_OPTS} ${bitbake_target}
Michael Shepos33aeca42019-06-13 02:36:17 -0500414fi
Chris Smart02651712015-11-11 11:09:00 +1100415
Alanny Lopez1246b032018-02-24 23:34:55 -0600416# Copy internal build directory into xtrct_path directory
Charles Paul Hoferb249c2c2018-09-12 12:15:13 -0500417if [[ ${xtrct_small_copy_dir} ]]; then
418 mkdir -p ${xtrct_path}/${xtrct_small_copy_dir}
419 timeout ${xtrct_copy_timeout} cp -r ${build_dir}/${xtrct_small_copy_dir}/* ${xtrct_path}/${xtrct_small_copy_dir}
420else
421 timeout ${xtrct_copy_timeout} cp -r ${build_dir}/* ${xtrct_path}
422fi
Charles Paul Hoferbe8700e2018-09-05 09:28:08 -0500423
424if [[ 0 -ne $? ]]; then
425 echo "Received a non-zero exit code from timeout"
426 exit 1
427fi
428
Chris Smart02651712015-11-11 11:09:00 +1100429EOF_SCRIPT
430
431chmod a+x ${WORKSPACE}/build.sh
432
Alanny Lopez51186882017-08-01 16:14:41 -0500433# Give the Docker image a name based on the distro,tag,arch,and target
Alanny Lopez1246b032018-02-24 23:34:55 -0600434img_name=${img_name:-openbmc/${distro}:${img_tag}-${target}-${ARCH}}
Alanny Lopez51186882017-08-01 16:14:41 -0500435
436# Build the Docker image
Alanny Lopez1246b032018-02-24 23:34:55 -0600437docker build -t ${img_name} - <<< "${Dockerfile}"
Alanny Lopez51186882017-08-01 16:14:41 -0500438
Michael Shepos3939e952019-01-16 16:00:35 -0600439# If obmc_dir or ssc_dir are ${HOME} or a subdirectory they will not be mounted
440mount_obmc_dir="-v ""${obmc_dir}"":""${obmc_dir}"" "
441mount_ssc_dir="-v ""${ssc_dir}"":""${ssc_dir}"" "
Lei YUde2a3202020-04-28 11:34:23 +0800442mount_workspace_dir="-v ""${WORKSPACE}"":""${WORKSPACE}"" "
Michael Shepos3939e952019-01-16 16:00:35 -0600443if [[ "${obmc_dir}" = "${HOME}/"* || "${obmc_dir}" = "${HOME}" ]];then
444mount_obmc_dir=""
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500445fi
Michael Shepos3939e952019-01-16 16:00:35 -0600446if [[ "${ssc_dir}" = "${HOME}/"* || "${ssc_dir}" = "${HOME}" ]];then
447mount_ssc_dir=""
448fi
Lei YUde2a3202020-04-28 11:34:23 +0800449if [[ "${WORKSPACE}" = "${HOME}/"* || "${WORKSPACE}" = "${HOME}" ]];then
450mount_workspace_dir=""
451fi
Michael Shepos3939e952019-01-16 16:00:35 -0600452
453# Run the Docker container, execute the build.sh script
454docker run \
455--cap-add=sys_admin \
Michael Shepos33aeca42019-06-13 02:36:17 -0500456--cap-add=sys_nice \
Michael Shepos3939e952019-01-16 16:00:35 -0600457--net=host \
458--rm=true \
459-e WORKSPACE=${WORKSPACE} \
460-w "${HOME}" \
461-v "${HOME}":"${HOME}" \
462${mount_obmc_dir} \
463${mount_ssc_dir} \
Lei YUde2a3202020-04-28 11:34:23 +0800464${mount_workspace_dir} \
Michael Shepos3939e952019-01-16 16:00:35 -0600465--cpus="$num_cpu" \
466-t ${img_name} \
467${WORKSPACE}/build.sh
Chris Smart02651712015-11-11 11:09:00 +1100468
Alanny Lopezd32d3322017-07-18 15:21:39 -0500469# To maintain function of resources that used an older path, add a link
Alanny Lopez1246b032018-02-24 23:34:55 -0600470ln -sf ${xtrct_path}/deploy ${WORKSPACE}/deploy
Alanny Lopezd32d3322017-07-18 15:21:39 -0500471
Chris Smart02651712015-11-11 11:09:00 +1100472# Timestamp for build
Alanny Lopez0e8ad992017-06-19 15:45:23 -0500473echo "Build completed, $(date)"