blob: 0f3151d62a5cb9c16f11eabcc1727d9c951f98fb [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
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050018#
Alanny Lopeze08e8702018-02-24 18:07:13 -060019# Docker Image Build Variables:
Alanny Lopez1246b032018-02-24 23:34:55 -060020# BITBAKE_OPTS Set to "-c populate_sdk" or whatever other BitBake options
Alanny Lopeze08e8702018-02-24 18:07:13 -060021# you'd like to pass into the build.
22# Default: "", no options set
Alanny Lopez1246b032018-02-24 23:34:55 -060023# build_dir Path where the actual BitBake build occurs inside the
Alanny Lopeze08e8702018-02-24 18:07:13 -060024# container, path cannot be located on network storage.
25# Default: "/tmp/openbmc"
26# distro The distro used as the base image for the build image:
27# fedora|ubuntu
28# Default: "ubuntu"
Alanny Lopez1246b032018-02-24 23:34:55 -060029# img_name The name given to the target build's docker image.
Alanny Lopeze08e8702018-02-24 18:07:13 -060030# Default: "openbmc/${distro}:${imgtag}-${target}-${ARCH}"
Alanny Lopez1246b032018-02-24 23:34:55 -060031# img_tag The base docker image distro tag:
Alanny Lopeze08e8702018-02-24 18:07:13 -060032# ubuntu: latest|16.04|14.04|trusty|xenial
33# fedora: 23|24|25
34# Default: "latest"
35# target The target we aim to build:
Andrew Geisslerdd820722018-02-20 13:42:58 -060036# evb-ast2500|palmetto|qemu|qemux86-64
Andrew Geisslerdd9e1962019-08-15 08:27:28 -050037# romulus|s2600wf|witherspoon|zaius|tiogapass|gsj|mihawk
Andrew Geisslerf86b4a82019-09-27 15:21:11 -050038# witherspoon-tacoma|rainier
Alanny Lopeze08e8702018-02-24 18:07:13 -060039# Default: "qemu"
Andrew Geissler215e43c2019-04-23 10:57:48 -050040# no_tar Set to true if you do not want the debug tar built
41# Default: "false"
Michael Shepos33aeca42019-06-13 02:36:17 -050042# nice_priority Set nice priotity for bitbake command.
43# Nice:
44# Run with an adjusted niceness, which affects process
45# scheduling. Nice values range from -20 (most favorable
46# to the process) to 19 (least favorable to the process).
47# Default: "", nice is not used if nice_priority is not set
Alanny Lopez723fea62017-09-12 11:22:17 -050048#
Alanny Lopeze08e8702018-02-24 18:07:13 -060049# Deployment Variables:
Alanny Lopez1246b032018-02-24 23:34:55 -060050# obmc_dir Path of the OpenBMC repo directory used as a reference
Alanny Lopeze08e8702018-02-24 18:07:13 -060051# for the build inside the container.
52# Default: "${WORKSPACE}/openbmc"
Michael Shepos10afbb22019-02-06 13:33:07 -060053# xtrct_small_copy_dir
54# Directory within build_dir that should be copied to
55# xtrct_path. The directory and all parents up to, but not
56# including, build_dir will be copied. For example, if
57# build_dir is set to "/tmp/openbmc" and this is set to
58# "build/tmp", the directory at xtrct_path will have the
59# following directory structure:
60# xtrct_path
61# | - build
62# | - tmp
63# ...
64# Can also be set to the empty string to copy the entire
65# contents of build_dir to xtrct_path.
66# Default: "deploy/images".
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050067#
68###############################################################################
Joel Stanley4b8b2392016-02-12 15:44:57 +103069# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103070set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110071
Alanny Lopez46967702018-02-25 00:29:14 -060072# Script Variables:
73build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"}
74http_proxy=${http_proxy:-}
75WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Andrew Geisslerdc1e7022018-03-26 07:54:48 -070076num_cpu=${num_cpu:-$(nproc)}
Alanny Lopez46967702018-02-25 00:29:14 -060077
78# Docker Image Build Variables:
79build_dir=${build_dir:-/tmp/openbmc}
Chris Smart02651712015-11-11 11:09:00 +110080distro=${distro:-ubuntu}
Alanny Lopez1246b032018-02-24 23:34:55 -060081img_tag=${img_tag:-latest}
Alanny Lopez46967702018-02-25 00:29:14 -060082target=${target:-qemu}
Andrew Geissler215e43c2019-04-23 10:57:48 -050083no_tar=${no_tar:-false}
Michael Shepos33aeca42019-06-13 02:36:17 -050084nice_priority=${nice_priority:-}
Alanny Lopez46967702018-02-25 00:29:14 -060085
86# Deployment variables
Alanny Lopez46967702018-02-25 00:29:14 -060087obmc_dir=${obmc_dir:-${WORKSPACE}/openbmc}
Michael Shepos3939e952019-01-16 16:00:35 -060088ssc_dir=${HOME}
Michael Shepos10afbb22019-02-06 13:33:07 -060089xtrct_small_copy_dir=${xtrct_small_copy_dir:-deploy/images}
Michael Shepos3939e952019-01-16 16:00:35 -060090xtrct_path="${obmc_dir}/build/tmp"
91xtrct_copy_timeout="300"
Alanny Lopez46967702018-02-25 00:29:14 -060092
Andrew Geissler2eb45d32019-09-18 21:56:44 -050093bitbake_target="obmc-phosphor-image"
Chris Smartc3522542016-02-16 11:59:36 +110094PROXY=""
Chris Smart02651712015-11-11 11:09:00 +110095
Alanny Lopezccc650e2017-04-24 15:14:20 -050096# Determine the architecture
97ARCH=$(uname -m)
98
99# Determine the prefix of the Dockerfile's base image
100case ${ARCH} in
101 "ppc64le")
102 DOCKER_BASE="ppc64le/"
103 ;;
104 "x86_64")
105 DOCKER_BASE=""
106 ;;
107 *)
108 echo "Unsupported system architecture(${ARCH}) found for docker image"
109 exit 1
110esac
Andrew Geissler11abbbe2016-08-14 19:39:47 -0500111
Chris Smart02651712015-11-11 11:09:00 +1100112# Timestamp for job
113echo "Build started, $(date)"
114
Alanny Lopez1246b032018-02-24 23:34:55 -0600115# If the obmc_dir directory doesn't exist clone it in
116if [ ! -d ${obmc_dir} ]; then
117 echo "Clone in openbmc master to ${obmc_dir}"
118 git clone https://github.com/openbmc/openbmc ${obmc_dir}
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500119fi
120
Alanny Lopez1246b032018-02-24 23:34:55 -0600121# Make and chown the xtrct_path directory to avoid permission errors
122if [ ! -d ${xtrct_path} ]; then
123 mkdir -p ${xtrct_path}
Alanny Lopez723fea62017-09-12 11:22:17 -0500124fi
Alanny Lopez1246b032018-02-24 23:34:55 -0600125chown ${UID}:${GROUPS} ${xtrct_path}
Alanny Lopez723fea62017-09-12 11:22:17 -0500126
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500127# Work out what build target we should be running and set BitBake command
Michael Shepos2de03e92018-11-07 15:54:56 -0600128MACHINE=""
Chris Smart02651712015-11-11 11:09:00 +1100129case ${target} in
Chris Smart02651712015-11-11 11:09:00 +1100130 palmetto)
Brad Bishop7161a172018-10-05 16:48:06 -0400131 LAYER_DIR="meta-ibm/meta-palmetto"
Brad Bishop91a200b2019-08-22 14:24:33 -0400132 MACHINE="palmetto"
133 DISTRO="openbmc-openpower"
Chris Smart02651712015-11-11 11:09:00 +1100134 ;;
Adriana Kobylak4ec7db02019-05-07 12:44:30 -0500135 swift)
Brad Bishopf713bf42019-11-13 20:23:32 -0500136 LAYER_DIR="meta-ibm"
Adriana Kobylak4ec7db02019-05-07 12:44:30 -0500137 MACHINE="swift"
Brad Bishop91a200b2019-08-22 14:24:33 -0400138 DISTRO="openbmc-witherspoon"
Adriana Kobylak4ec7db02019-05-07 12:44:30 -0500139 ;;
Andrew Geisslerdd9e1962019-08-15 08:27:28 -0500140 mihawk)
Brad Bishopf713bf42019-11-13 20:23:32 -0500141 LAYER_DIR="meta-ibm"
Andrew Geisslerdd9e1962019-08-15 08:27:28 -0500142 MACHINE="mihawk"
Brad Bishop91a200b2019-08-22 14:24:33 -0400143 DISTRO="openbmc-witherspoon"
Andrew Geisslerdd9e1962019-08-15 08:27:28 -0500144 ;;
Joel Stanley0e077202016-06-28 16:42:45 +0930145 witherspoon)
Brad Bishopf713bf42019-11-13 20:23:32 -0500146 LAYER_DIR="meta-ibm"
Brad Bishop91a200b2019-08-22 14:24:33 -0400147 MACHINE="witherspoon"
148 DISTRO="openbmc-witherspoon"
Joel Stanley0e077202016-06-28 16:42:45 +0930149 ;;
Adriana Kobylakfcba1c32019-05-10 11:33:37 -0500150 witherspoon-128)
Brad Bishopf713bf42019-11-13 20:23:32 -0500151 LAYER_DIR="meta-ibm"
Adriana Kobylakfcba1c32019-05-10 11:33:37 -0500152 MACHINE="witherspoon-128"
Brad Bishop91a200b2019-08-22 14:24:33 -0400153 DISTRO="openbmc-witherspoon"
Adriana Kobylakfcba1c32019-05-10 11:33:37 -0500154 ;;
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500155 witherspoon-tacoma)
Brad Bishopf713bf42019-11-13 20:23:32 -0500156 LAYER_DIR="meta-ibm"
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500157 MACHINE="witherspoon-tacoma"
158 DISTRO="openbmc-openpower"
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500159 ;;
Andrew Geisslerf86b4a82019-09-27 15:21:11 -0500160 rainier)
Brad Bishopf713bf42019-11-13 20:23:32 -0500161 LAYER_DIR="meta-ibm"
Andrew Geisslerf86b4a82019-09-27 15:21:11 -0500162 MACHINE="rainier"
163 DISTRO="openbmc-openpower"
164 ;;
Joel Stanley0e077202016-06-28 16:42:45 +0930165 evb-ast2500)
Brad Bishop7161a172018-10-05 16:48:06 -0400166 LAYER_DIR="meta-evb/meta-evb-aspeed/meta-evb-ast2500"
Brad Bishop91a200b2019-08-22 14:24:33 -0400167 MACHINE="evb-ast2500"
168 DISTRO="openbmc-phosphor"
Joel Stanley0e077202016-06-28 16:42:45 +0930169 ;;
Ed Tanous6dc40d92018-07-30 11:13:36 -0700170 s2600wf)
Brad Bishop7161a172018-10-05 16:48:06 -0400171 LAYER_DIR="meta-intel/meta-s2600wf"
Brad Bishop91a200b2019-08-22 14:24:33 -0400172 MACHINE="s2600wf"
173 DISTRO="openbmc-phosphor"
Ed Tanous6dc40d92018-07-30 11:13:36 -0700174 ;;
Joel Stanley915381f2016-11-01 16:58:59 +1030175 zaius)
Brad Bishop7161a172018-10-05 16:48:06 -0400176 LAYER_DIR="meta-ingrasys/meta-zaius"
Brad Bishop91a200b2019-08-22 14:24:33 -0400177 MACHINE="zaius"
178 DISTRO="openbmc-openpower"
Joel Stanley915381f2016-11-01 16:58:59 +1030179 ;;
180 romulus)
Brad Bishop7161a172018-10-05 16:48:06 -0400181 LAYER_DIR="meta-ibm/meta-romulus"
Brad Bishop91a200b2019-08-22 14:24:33 -0400182 MACHINE="romulus"
183 DISTRO="openbmc-openpower"
Joel Stanley915381f2016-11-01 16:58:59 +1030184 ;;
Vijay Khemka4c5b12e2019-01-23 14:50:09 -0800185 tiogapass)
186 LAYER_DIR="meta-facebook/meta-tiogapass"
Brad Bishop91a200b2019-08-22 14:24:33 -0400187 MACHINE="tiogapass"
188 DISTRO="openbmc-phosphor"
Vijay Khemka4c5b12e2019-01-23 14:50:09 -0800189 ;;
Andrew Geissler9eef7282019-05-10 13:28:09 -0500190 gsj)
191 LAYER_DIR="meta-quanta/meta-gsj"
Brad Bishop91a200b2019-08-22 14:24:33 -0400192 MACHINE="gsj"
Andrew Geissler8565d2a2020-04-20 15:22:14 -0500193 # Use default DISTRO from layer
Andrew Geissler9eef7282019-05-10 13:28:09 -0500194 ;;
Chris Smart02651712015-11-11 11:09:00 +1100195 *)
196 exit 1
197 ;;
198esac
199
Brad Bishop7161a172018-10-05 16:48:06 -0400200BITBAKE_CMD="TEMPLATECONF=${LAYER_DIR}/conf source oe-init-build-env"
201
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500202# Configure Docker build
Chris Smart02651712015-11-11 11:09:00 +1100203if [[ "${distro}" == fedora ]];then
204
205 if [[ -n "${http_proxy}" ]]; then
206 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
207 fi
208
209 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600210 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100211
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500212 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100213
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500214 # Set the locale
215 RUN locale-gen en_US.UTF-8
216 ENV LANG en_US.UTF-8
217 ENV LANGUAGE en_US:en
218 ENV LC_ALL en_US.UTF-8
Saqib Khan75635122017-03-23 10:57:34 -0500219
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500220 RUN dnf --refresh install -y \
221 bzip2 \
222 chrpath \
223 cpio \
224 diffstat \
225 findutils \
226 gcc \
227 gcc-c++ \
228 git \
229 make \
230 patch \
231 perl-bignum \
232 perl-Data-Dumper \
233 perl-Thread-Queue \
234 python-devel \
235 python3-devel \
236 SDL-devel \
237 socat \
238 subversion \
239 tar \
240 texinfo \
241 wget \
Saqib Khan5158a322017-10-23 11:31:24 -0500242 which \
243 iputils-ping
Chris Smart02651712015-11-11 11:09:00 +1100244
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500245 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
246 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100247
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500248 USER ${USER}
249 ENV HOME ${HOME}
250 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100251EOF
252)
253
Alanny Lopezccc650e2017-04-24 15:14:20 -0500254elif [[ "${distro}" == ubuntu ]]; then
255
Chris Smart02651712015-11-11 11:09:00 +1100256 if [[ -n "${http_proxy}" ]]; then
257 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
258 fi
259
260 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600261 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100262
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500263 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100264
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500265 ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500266
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500267 RUN apt-get update && apt-get install -yy \
268 build-essential \
269 chrpath \
270 debianutils \
271 diffstat \
272 gawk \
273 git \
274 libdata-dumper-simple-perl \
275 libsdl1.2-dev \
276 libthread-queue-any-perl \
Alanny Lopez27af3a02017-05-26 10:49:06 -0500277 locales \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500278 python \
279 python3 \
280 socat \
281 subversion \
282 texinfo \
283 cpio \
Saqib Khan5158a322017-10-23 11:31:24 -0500284 wget \
285 iputils-ping
Chris Smart02651712015-11-11 11:09:00 +1100286
Alanny Lopez27af3a02017-05-26 10:49:06 -0500287 # Set the locale
288 RUN locale-gen en_US.UTF-8
289 ENV LANG en_US.UTF-8
290 ENV LANGUAGE en_US:en
291 ENV LC_ALL en_US.UTF-8
292
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500293 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
294 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100295
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500296 USER ${USER}
297 ENV HOME ${HOME}
298 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100299EOF
300)
301fi
302
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500303# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100304export PROXY_HOST=${http_proxy/#http*:\/\/}
305export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
306export PROXY_PORT=${http_proxy/#http*:\/\/*:}
307
Chris Smart01d2b962015-11-11 18:05:30 +1100308mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100309
Andrew Geissler215e43c2019-04-23 10:57:48 -0500310# Determine command for bitbake image build
Andrew Geissler215e43c2019-04-23 10:57:48 -0500311if [ $no_tar = "false" ]; then
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500312 bitbake_target="${bitbake_target} obmc-phosphor-debug-tarball"
Andrew Geissler215e43c2019-04-23 10:57:48 -0500313fi
314
Chris Smart01d2b962015-11-11 18:05:30 +1100315cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100316#!/bin/bash
317
Joel Stanley38c9d142016-02-16 12:31:55 +1030318set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100319
Alanny Lopez723fea62017-09-12 11:22:17 -0500320# Go into the OpenBMC directory, the build will handle changing directories
Alanny Lopez1246b032018-02-24 23:34:55 -0600321cd ${obmc_dir}
Chris Smart02651712015-11-11 11:09:00 +1100322
323# Set up proxies
324export ftp_proxy=${http_proxy}
325export http_proxy=${http_proxy}
326export https_proxy=${http_proxy}
327
Chris Smart01d2b962015-11-11 18:05:30 +1100328mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100329
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500330# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100331if [[ -n "${http_proxy}" ]]; then
332
Chris Smartd30c5902016-03-01 15:00:54 +1100333 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500334 #!/bin/bash
335 # \$1 = hostname, \$2 = port
336 PROXY=${PROXY_HOST}
337 PROXY_PORT=${PROXY_PORT}
338 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100339EOF_GIT
340
Chris Smart01d2b962015-11-11 18:05:30 +1100341 chmod a+x ${WORKSPACE}/bin/git-proxy
342 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100343 git config core.gitProxy git-proxy
344
345 mkdir -p ~/.subversion
346
347 cat > ~/.subversion/servers << EOF_SVN
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500348 [global]
349 http-proxy-host = ${PROXY_HOST}
350 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100351EOF_SVN
352fi
353
354# Source our build env
355${BITBAKE_CMD}
356
Andrew Geissler8565d2a2020-04-20 15:22:14 -0500357if [[ -z "${MACHINE}" ]]; then
358 echo "MACHINE is not configured for ${target}"
Brad Bishop91a200b2019-08-22 14:24:33 -0400359 exit 1
Michael Shepos2de03e92018-11-07 15:54:56 -0600360fi
361
Brad Bishop91a200b2019-08-22 14:24:33 -0400362export MACHINE="${MACHINE}"
Andrew Geissler8565d2a2020-04-20 15:22:14 -0500363if [[ -z "${DISTRO}" ]]; then
364 echo "DISTRO is not configured for ${target} so will use default"
365 unset DISTRO
366else
367 export DISTRO="${DISTRO}"
368fi
Brad Bishop91a200b2019-08-22 14:24:33 -0400369
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500370# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100371cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100372BB_NUMBER_THREADS = "$(nproc)"
373PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100374INHERIT += "rm_work"
375BB_GENERATE_MIRROR_TARBALLS = "1"
Alanny Lopez1246b032018-02-24 23:34:55 -0600376DL_DIR="${ssc_dir}/bitbake_downloads"
377SSTATE_DIR="${ssc_dir}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100378USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500379INHERIT_remove = "uninative"
Alanny Lopez1246b032018-02-24 23:34:55 -0600380TMPDIR="${build_dir}"
Chris Smart02651712015-11-11 11:09:00 +1100381EOF_CONF
382
383# Kick off a build
Michael Shepos33aeca42019-06-13 02:36:17 -0500384if [[ -n "${nice_priority}" ]]; then
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500385 nice -${nice_priority} bitbake ${BITBAKE_OPTS} ${bitbake_target}
Michael Shepos33aeca42019-06-13 02:36:17 -0500386else
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500387 bitbake ${BITBAKE_OPTS} ${bitbake_target}
Michael Shepos33aeca42019-06-13 02:36:17 -0500388fi
Chris Smart02651712015-11-11 11:09:00 +1100389
Alanny Lopez1246b032018-02-24 23:34:55 -0600390# Copy internal build directory into xtrct_path directory
Charles Paul Hoferb249c2c2018-09-12 12:15:13 -0500391if [[ ${xtrct_small_copy_dir} ]]; then
392 mkdir -p ${xtrct_path}/${xtrct_small_copy_dir}
393 timeout ${xtrct_copy_timeout} cp -r ${build_dir}/${xtrct_small_copy_dir}/* ${xtrct_path}/${xtrct_small_copy_dir}
394else
395 timeout ${xtrct_copy_timeout} cp -r ${build_dir}/* ${xtrct_path}
396fi
Charles Paul Hoferbe8700e2018-09-05 09:28:08 -0500397
398if [[ 0 -ne $? ]]; then
399 echo "Received a non-zero exit code from timeout"
400 exit 1
401fi
402
Chris Smart02651712015-11-11 11:09:00 +1100403EOF_SCRIPT
404
405chmod a+x ${WORKSPACE}/build.sh
406
Alanny Lopez51186882017-08-01 16:14:41 -0500407# Give the Docker image a name based on the distro,tag,arch,and target
Alanny Lopez1246b032018-02-24 23:34:55 -0600408img_name=${img_name:-openbmc/${distro}:${img_tag}-${target}-${ARCH}}
Alanny Lopez51186882017-08-01 16:14:41 -0500409
410# Build the Docker image
Alanny Lopez1246b032018-02-24 23:34:55 -0600411docker build -t ${img_name} - <<< "${Dockerfile}"
Alanny Lopez51186882017-08-01 16:14:41 -0500412
Michael Shepos3939e952019-01-16 16:00:35 -0600413# If obmc_dir or ssc_dir are ${HOME} or a subdirectory they will not be mounted
414mount_obmc_dir="-v ""${obmc_dir}"":""${obmc_dir}"" "
415mount_ssc_dir="-v ""${ssc_dir}"":""${ssc_dir}"" "
416if [[ "${obmc_dir}" = "${HOME}/"* || "${obmc_dir}" = "${HOME}" ]];then
417mount_obmc_dir=""
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500418fi
Michael Shepos3939e952019-01-16 16:00:35 -0600419if [[ "${ssc_dir}" = "${HOME}/"* || "${ssc_dir}" = "${HOME}" ]];then
420mount_ssc_dir=""
421fi
422
423# Run the Docker container, execute the build.sh script
424docker run \
425--cap-add=sys_admin \
Michael Shepos33aeca42019-06-13 02:36:17 -0500426--cap-add=sys_nice \
Michael Shepos3939e952019-01-16 16:00:35 -0600427--net=host \
428--rm=true \
429-e WORKSPACE=${WORKSPACE} \
430-w "${HOME}" \
431-v "${HOME}":"${HOME}" \
432${mount_obmc_dir} \
433${mount_ssc_dir} \
434--cpus="$num_cpu" \
435-t ${img_name} \
436${WORKSPACE}/build.sh
Chris Smart02651712015-11-11 11:09:00 +1100437
Alanny Lopezd32d3322017-07-18 15:21:39 -0500438# To maintain function of resources that used an older path, add a link
Alanny Lopez1246b032018-02-24 23:34:55 -0600439ln -sf ${xtrct_path}/deploy ${WORKSPACE}/deploy
Alanny Lopezd32d3322017-07-18 15:21:39 -0500440
Chris Smart02651712015-11-11 11:09:00 +1100441# Timestamp for build
Alanny Lopez0e8ad992017-06-19 15:45:23 -0500442echo "Build completed, $(date)"