blob: f8e597de1144b6a779afdca94f38e0ef1a3802ff [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 YU237bd082020-09-22 11:15:08 +080018# UBUNTU_MIRROR [optional] The URL of a mirror of Ubuntu to override the
19# default ones in /etc/apt/sources.list
Lei YU39587ad2020-06-17 19:55:54 +080020# default is empty, and no mirror is used.
Lei YU237bd082020-09-22 11:15:08 +080021# ENV_LOCAL_CONF [optional] The environment variables to inject into the
22# build, which will be written into local.conf.
23# default is empty.
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050024#
Alanny Lopeze08e8702018-02-24 18:07:13 -060025# Docker Image Build Variables:
Alanny Lopez1246b032018-02-24 23:34:55 -060026# BITBAKE_OPTS Set to "-c populate_sdk" or whatever other BitBake options
Alanny Lopeze08e8702018-02-24 18:07:13 -060027# you'd like to pass into the build.
28# Default: "", no options set
Alanny Lopez1246b032018-02-24 23:34:55 -060029# build_dir Path where the actual BitBake build occurs inside the
Alanny Lopeze08e8702018-02-24 18:07:13 -060030# container, path cannot be located on network storage.
Andrew Geisslerbd11f692020-09-04 09:36:28 -050031# Default: "$WORKSPACE/build"
Alanny Lopeze08e8702018-02-24 18:07:13 -060032# distro The distro used as the base image for the build image:
33# fedora|ubuntu
34# Default: "ubuntu"
Alanny Lopez1246b032018-02-24 23:34:55 -060035# img_name The name given to the target build's docker image.
Alanny Lopeze08e8702018-02-24 18:07:13 -060036# Default: "openbmc/${distro}:${imgtag}-${target}-${ARCH}"
Alanny Lopez1246b032018-02-24 23:34:55 -060037# img_tag The base docker image distro tag:
Alanny Lopeze08e8702018-02-24 18:07:13 -060038# ubuntu: latest|16.04|14.04|trusty|xenial
39# fedora: 23|24|25
40# Default: "latest"
41# target The target we aim to build:
Andrew Geisslerdd820722018-02-20 13:42:58 -060042# evb-ast2500|palmetto|qemu|qemux86-64
Andrew Geisslerdd9e1962019-08-15 08:27:28 -050043# romulus|s2600wf|witherspoon|zaius|tiogapass|gsj|mihawk
Andrew Geisslerf86b4a82019-09-27 15:21:11 -050044# witherspoon-tacoma|rainier
Alanny Lopeze08e8702018-02-24 18:07:13 -060045# Default: "qemu"
Andrew Geissler215e43c2019-04-23 10:57:48 -050046# no_tar Set to true if you do not want the debug tar built
47# Default: "false"
Michael Shepos33aeca42019-06-13 02:36:17 -050048# nice_priority Set nice priotity for bitbake command.
49# Nice:
50# Run with an adjusted niceness, which affects process
51# scheduling. Nice values range from -20 (most favorable
52# to the process) to 19 (least favorable to the process).
53# Default: "", nice is not used if nice_priority is not set
Alanny Lopez723fea62017-09-12 11:22:17 -050054#
Alanny Lopeze08e8702018-02-24 18:07:13 -060055# Deployment Variables:
Alanny Lopez1246b032018-02-24 23:34:55 -060056# obmc_dir Path of the OpenBMC repo directory used as a reference
Alanny Lopeze08e8702018-02-24 18:07:13 -060057# for the build inside the container.
58# Default: "${WORKSPACE}/openbmc"
Lei YUdf0e45c2020-09-03 11:25:57 +080059# ssc_dir Path of the OpenBMC shared directory that contains the
60# downloads dir and the sstate dir.
61# Default: "${HOME}"
Michael Shepos10afbb22019-02-06 13:33:07 -060062# xtrct_small_copy_dir
63# Directory within build_dir that should be copied to
64# xtrct_path. The directory and all parents up to, but not
65# including, build_dir will be copied. For example, if
66# build_dir is set to "/tmp/openbmc" and this is set to
67# "build/tmp", the directory at xtrct_path will have the
68# following directory structure:
69# xtrct_path
70# | - build
71# | - tmp
72# ...
73# Can also be set to the empty string to copy the entire
74# contents of build_dir to xtrct_path.
75# Default: "deploy/images".
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050076#
77###############################################################################
Joel Stanley4b8b2392016-02-12 15:44:57 +103078# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103079set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110080
Alanny Lopez46967702018-02-25 00:29:14 -060081# Script Variables:
82build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"}
83http_proxy=${http_proxy:-}
84WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Andrew Geisslerdc1e7022018-03-26 07:54:48 -070085num_cpu=${num_cpu:-$(nproc)}
Lei YU39587ad2020-06-17 19:55:54 +080086UBUNTU_MIRROR=${UBUNTU_MIRROR:-""}
Lei YU237bd082020-09-22 11:15:08 +080087ENV_LOCAL_CONF=${ENV_LOCAL_CONF:-""}
Alanny Lopez46967702018-02-25 00:29:14 -060088
89# Docker Image Build Variables:
Andrew Geisslerbd11f692020-09-04 09:36:28 -050090build_dir=${build_dir:-${WORKSPACE}/build}
Chris Smart02651712015-11-11 11:09:00 +110091distro=${distro:-ubuntu}
Alanny Lopez1246b032018-02-24 23:34:55 -060092img_tag=${img_tag:-latest}
Alanny Lopez46967702018-02-25 00:29:14 -060093target=${target:-qemu}
Andrew Geissler215e43c2019-04-23 10:57:48 -050094no_tar=${no_tar:-false}
Michael Shepos33aeca42019-06-13 02:36:17 -050095nice_priority=${nice_priority:-}
Alanny Lopez46967702018-02-25 00:29:14 -060096
97# Deployment variables
Alanny Lopez46967702018-02-25 00:29:14 -060098obmc_dir=${obmc_dir:-${WORKSPACE}/openbmc}
Lei YUdf0e45c2020-09-03 11:25:57 +080099ssc_dir=${ssc_dir:-${HOME}}
Michael Shepos10afbb22019-02-06 13:33:07 -0600100xtrct_small_copy_dir=${xtrct_small_copy_dir:-deploy/images}
Michael Shepos3939e952019-01-16 16:00:35 -0600101xtrct_path="${obmc_dir}/build/tmp"
102xtrct_copy_timeout="300"
Alanny Lopez46967702018-02-25 00:29:14 -0600103
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500104bitbake_target="obmc-phosphor-image"
Chris Smartc3522542016-02-16 11:59:36 +1100105PROXY=""
Chris Smart02651712015-11-11 11:09:00 +1100106
Lei YU39587ad2020-06-17 19:55:54 +0800107MIRROR=""
108if [[ -n "${UBUNTU_MIRROR}" ]]; then
109 MIRROR="RUN echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME) main restricted universe multiverse\" > /etc/apt/sources.list && \
110 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-updates main restricted universe multiverse\" >> /etc/apt/sources.list && \
111 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-security main restricted universe multiverse\" >> /etc/apt/sources.list && \
112 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-proposed main restricted universe multiverse\" >> /etc/apt/sources.list && \
113 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-backports main restricted universe multiverse\" >> /etc/apt/sources.list"
114fi
115
Alanny Lopezccc650e2017-04-24 15:14:20 -0500116# Determine the architecture
117ARCH=$(uname -m)
118
119# Determine the prefix of the Dockerfile's base image
120case ${ARCH} in
121 "ppc64le")
122 DOCKER_BASE="ppc64le/"
123 ;;
124 "x86_64")
125 DOCKER_BASE=""
126 ;;
127 *)
128 echo "Unsupported system architecture(${ARCH}) found for docker image"
129 exit 1
130esac
Andrew Geissler11abbbe2016-08-14 19:39:47 -0500131
Chris Smart02651712015-11-11 11:09:00 +1100132# Timestamp for job
133echo "Build started, $(date)"
134
Alanny Lopez1246b032018-02-24 23:34:55 -0600135# If the obmc_dir directory doesn't exist clone it in
Patrick Williams384d7412020-11-06 16:15:41 -0600136if [ ! -d "${obmc_dir}" ]; then
Alanny Lopez1246b032018-02-24 23:34:55 -0600137 echo "Clone in openbmc master to ${obmc_dir}"
Patrick Williams384d7412020-11-06 16:15:41 -0600138 git clone https://github.com/openbmc/openbmc "${obmc_dir}"
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500139fi
140
Alanny Lopez1246b032018-02-24 23:34:55 -0600141# Make and chown the xtrct_path directory to avoid permission errors
Patrick Williams384d7412020-11-06 16:15:41 -0600142if [ ! -d "${xtrct_path}" ]; then
143 mkdir -p "${xtrct_path}"
Alanny Lopez723fea62017-09-12 11:22:17 -0500144fi
Patrick Williams384d7412020-11-06 16:15:41 -0600145chown "${UID}:${GROUPS[0]}" "${xtrct_path}"
Alanny Lopez723fea62017-09-12 11:22:17 -0500146
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500147# Work out what build target we should be running and set BitBake command
Michael Shepos2de03e92018-11-07 15:54:56 -0600148MACHINE=""
Chris Smart02651712015-11-11 11:09:00 +1100149case ${target} in
Chris Smart02651712015-11-11 11:09:00 +1100150 palmetto)
Brad Bishop7161a172018-10-05 16:48:06 -0400151 LAYER_DIR="meta-ibm/meta-palmetto"
Brad Bishop91a200b2019-08-22 14:24:33 -0400152 MACHINE="palmetto"
153 DISTRO="openbmc-openpower"
Chris Smart02651712015-11-11 11:09:00 +1100154 ;;
Adriana Kobylak4ec7db02019-05-07 12:44:30 -0500155 swift)
Brad Bishopf713bf42019-11-13 20:23:32 -0500156 LAYER_DIR="meta-ibm"
Adriana Kobylak4ec7db02019-05-07 12:44:30 -0500157 MACHINE="swift"
Brad Bishop91a200b2019-08-22 14:24:33 -0400158 DISTRO="openbmc-witherspoon"
Adriana Kobylak4ec7db02019-05-07 12:44:30 -0500159 ;;
Andrew Geisslerdd9e1962019-08-15 08:27:28 -0500160 mihawk)
Brad Bishopf713bf42019-11-13 20:23:32 -0500161 LAYER_DIR="meta-ibm"
Andrew Geisslerdd9e1962019-08-15 08:27:28 -0500162 MACHINE="mihawk"
Brad Bishop91a200b2019-08-22 14:24:33 -0400163 DISTRO="openbmc-witherspoon"
Andrew Geisslerdd9e1962019-08-15 08:27:28 -0500164 ;;
Joel Stanley0e077202016-06-28 16:42:45 +0930165 witherspoon)
Brad Bishopf713bf42019-11-13 20:23:32 -0500166 LAYER_DIR="meta-ibm"
Brad Bishop91a200b2019-08-22 14:24:33 -0400167 MACHINE="witherspoon"
168 DISTRO="openbmc-witherspoon"
Joel Stanley0e077202016-06-28 16:42:45 +0930169 ;;
Adriana Kobylakfcba1c32019-05-10 11:33:37 -0500170 witherspoon-128)
Brad Bishopf713bf42019-11-13 20:23:32 -0500171 LAYER_DIR="meta-ibm"
Adriana Kobylakfcba1c32019-05-10 11:33:37 -0500172 MACHINE="witherspoon-128"
Brad Bishop91a200b2019-08-22 14:24:33 -0400173 DISTRO="openbmc-witherspoon"
Adriana Kobylakfcba1c32019-05-10 11:33:37 -0500174 ;;
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500175 witherspoon-tacoma)
Brad Bishopf713bf42019-11-13 20:23:32 -0500176 LAYER_DIR="meta-ibm"
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500177 MACHINE="witherspoon-tacoma"
178 DISTRO="openbmc-openpower"
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500179 ;;
Andrew Geisslerf86b4a82019-09-27 15:21:11 -0500180 rainier)
Brad Bishopf713bf42019-11-13 20:23:32 -0500181 LAYER_DIR="meta-ibm"
Andrew Geisslerf86b4a82019-09-27 15:21:11 -0500182 MACHINE="rainier"
183 DISTRO="openbmc-openpower"
184 ;;
Joel Stanley0e077202016-06-28 16:42:45 +0930185 evb-ast2500)
Brad Bishop7161a172018-10-05 16:48:06 -0400186 LAYER_DIR="meta-evb/meta-evb-aspeed/meta-evb-ast2500"
Brad Bishop91a200b2019-08-22 14:24:33 -0400187 MACHINE="evb-ast2500"
188 DISTRO="openbmc-phosphor"
Joel Stanley0e077202016-06-28 16:42:45 +0930189 ;;
Ed Tanous6dc40d92018-07-30 11:13:36 -0700190 s2600wf)
Brad Bishop7161a172018-10-05 16:48:06 -0400191 LAYER_DIR="meta-intel/meta-s2600wf"
Brad Bishop91a200b2019-08-22 14:24:33 -0400192 MACHINE="s2600wf"
193 DISTRO="openbmc-phosphor"
Ed Tanous6dc40d92018-07-30 11:13:36 -0700194 ;;
Joel Stanley915381f2016-11-01 16:58:59 +1030195 zaius)
Brad Bishop7161a172018-10-05 16:48:06 -0400196 LAYER_DIR="meta-ingrasys/meta-zaius"
Brad Bishop91a200b2019-08-22 14:24:33 -0400197 MACHINE="zaius"
198 DISTRO="openbmc-openpower"
Joel Stanley915381f2016-11-01 16:58:59 +1030199 ;;
200 romulus)
Brad Bishop7161a172018-10-05 16:48:06 -0400201 LAYER_DIR="meta-ibm/meta-romulus"
Brad Bishop91a200b2019-08-22 14:24:33 -0400202 MACHINE="romulus"
203 DISTRO="openbmc-openpower"
Joel Stanley915381f2016-11-01 16:58:59 +1030204 ;;
Vijay Khemka4c5b12e2019-01-23 14:50:09 -0800205 tiogapass)
206 LAYER_DIR="meta-facebook/meta-tiogapass"
Brad Bishop91a200b2019-08-22 14:24:33 -0400207 MACHINE="tiogapass"
208 DISTRO="openbmc-phosphor"
Vijay Khemka4c5b12e2019-01-23 14:50:09 -0800209 ;;
Andrew Geissler9eef7282019-05-10 13:28:09 -0500210 gsj)
211 LAYER_DIR="meta-quanta/meta-gsj"
Brad Bishop91a200b2019-08-22 14:24:33 -0400212 MACHINE="gsj"
Andrew Geissler8565d2a2020-04-20 15:22:14 -0500213 # Use default DISTRO from layer
Andrew Geissler9eef7282019-05-10 13:28:09 -0500214 ;;
Chris Smart02651712015-11-11 11:09:00 +1100215 *)
216 exit 1
217 ;;
218esac
219
Brad Bishop7161a172018-10-05 16:48:06 -0400220BITBAKE_CMD="TEMPLATECONF=${LAYER_DIR}/conf source oe-init-build-env"
221
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500222# Configure Docker build
Chris Smart02651712015-11-11 11:09:00 +1100223if [[ "${distro}" == fedora ]];then
224
225 if [[ -n "${http_proxy}" ]]; then
226 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
227 fi
228
229 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600230 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100231
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500232 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100233
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500234 RUN dnf --refresh install -y \
235 bzip2 \
236 chrpath \
237 cpio \
238 diffstat \
239 findutils \
240 gcc \
241 gcc-c++ \
242 git \
243 make \
244 patch \
245 perl-bignum \
246 perl-Data-Dumper \
247 perl-Thread-Queue \
248 python-devel \
249 python3-devel \
250 SDL-devel \
251 socat \
252 subversion \
253 tar \
254 texinfo \
255 wget \
Saqib Khan5158a322017-10-23 11:31:24 -0500256 which \
Andrew Geissler40c1c9c2020-09-04 10:50:36 -0500257 file \
258 hostname \
259 rpcgen \
260 glibc-langpack-en \
261 glibc-locale-source
262
263 # Set the locale
264 ENV LANG=en_US.utf8
265 RUN localedef -f UTF-8 -i en_US en_US.UTF-8
Chris Smart02651712015-11-11 11:09:00 +1100266
Patrick Williams384d7412020-11-06 16:15:41 -0600267 RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
268 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100269
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500270 USER ${USER}
271 ENV HOME ${HOME}
272 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100273EOF
274)
275
Alanny Lopezccc650e2017-04-24 15:14:20 -0500276elif [[ "${distro}" == ubuntu ]]; then
277
Chris Smart02651712015-11-11 11:09:00 +1100278 if [[ -n "${http_proxy}" ]]; then
279 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
280 fi
281
282 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600283 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100284
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500285 ${PROXY}
Lei YU39587ad2020-06-17 19:55:54 +0800286 ${MIRROR}
Chris Smart02651712015-11-11 11:09:00 +1100287
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500288 ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500289
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500290 RUN apt-get update && apt-get install -yy \
291 build-essential \
292 chrpath \
293 debianutils \
294 diffstat \
295 gawk \
296 git \
297 libdata-dumper-simple-perl \
298 libsdl1.2-dev \
299 libthread-queue-any-perl \
Alanny Lopez27af3a02017-05-26 10:49:06 -0500300 locales \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500301 python \
302 python3 \
303 socat \
304 subversion \
305 texinfo \
306 cpio \
Saqib Khan5158a322017-10-23 11:31:24 -0500307 wget \
308 iputils-ping
Chris Smart02651712015-11-11 11:09:00 +1100309
Alanny Lopez27af3a02017-05-26 10:49:06 -0500310 # Set the locale
311 RUN locale-gen en_US.UTF-8
312 ENV LANG en_US.UTF-8
313 ENV LANGUAGE en_US:en
314 ENV LC_ALL en_US.UTF-8
315
Patrick Williams384d7412020-11-06 16:15:41 -0600316 RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
317 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100318
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500319 USER ${USER}
320 ENV HOME ${HOME}
321 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100322EOF
323)
324fi
325
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500326# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100327export PROXY_HOST=${http_proxy/#http*:\/\/}
328export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
329export PROXY_PORT=${http_proxy/#http*:\/\/*:}
330
Patrick Williams384d7412020-11-06 16:15:41 -0600331mkdir -p "${WORKSPACE}"
Chris Smart02651712015-11-11 11:09:00 +1100332
Andrew Geissler215e43c2019-04-23 10:57:48 -0500333# Determine command for bitbake image build
Patrick Williams384d7412020-11-06 16:15:41 -0600334if [ "$no_tar" = "false" ]; then
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500335 bitbake_target="${bitbake_target} obmc-phosphor-debug-tarball"
Andrew Geissler215e43c2019-04-23 10:57:48 -0500336fi
337
Chris Smart01d2b962015-11-11 18:05:30 +1100338cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100339#!/bin/bash
340
Joel Stanley38c9d142016-02-16 12:31:55 +1030341set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100342
Alanny Lopez723fea62017-09-12 11:22:17 -0500343# Go into the OpenBMC directory, the build will handle changing directories
Alanny Lopez1246b032018-02-24 23:34:55 -0600344cd ${obmc_dir}
Chris Smart02651712015-11-11 11:09:00 +1100345
346# Set up proxies
347export ftp_proxy=${http_proxy}
348export http_proxy=${http_proxy}
349export https_proxy=${http_proxy}
350
Chris Smart01d2b962015-11-11 18:05:30 +1100351mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100352
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500353# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100354if [[ -n "${http_proxy}" ]]; then
355
Chris Smartd30c5902016-03-01 15:00:54 +1100356 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500357 #!/bin/bash
358 # \$1 = hostname, \$2 = port
359 PROXY=${PROXY_HOST}
360 PROXY_PORT=${PROXY_PORT}
361 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100362EOF_GIT
363
Chris Smart01d2b962015-11-11 18:05:30 +1100364 chmod a+x ${WORKSPACE}/bin/git-proxy
365 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100366
Lei YUa76d7ce2020-05-11 15:20:56 +0800367 lock=${HOME}/build-setup.lock
368 flock \${lock} git config --global core.gitProxy ${WORKSPACE}/bin/git-proxy
369 flock \${lock} git config --global http.proxy ${http_proxy}
Chris Smart02651712015-11-11 11:09:00 +1100370
Lei YUa76d7ce2020-05-11 15:20:56 +0800371 flock \${lock} mkdir -p ~/.subversion
372 flock \${lock} cat > ~/.subversion/servers << EOF_SVN
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500373 [global]
374 http-proxy-host = ${PROXY_HOST}
375 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100376EOF_SVN
Lei YU58cb3ad2020-04-30 13:04:58 +0800377
Lei YUa76d7ce2020-05-11 15:20:56 +0800378 flock \${lock} cat > ~/.wgetrc << EOF_WGETRC
Lei YU58cb3ad2020-04-30 13:04:58 +0800379 https_proxy = ${http_proxy}
380 http_proxy = ${http_proxy}
381 use_proxy = on
382EOF_WGETRC
383
Lei YUa76d7ce2020-05-11 15:20:56 +0800384 flock \${lock} cat > ~/.curlrc << EOF_CURLRC
Lei YU58cb3ad2020-04-30 13:04:58 +0800385 proxy = ${PROXY_HOST}:${PROXY_PORT}
386EOF_CURLRC
Chris Smart02651712015-11-11 11:09:00 +1100387fi
388
389# Source our build env
390${BITBAKE_CMD}
391
Andrew Geissler8565d2a2020-04-20 15:22:14 -0500392if [[ -z "${MACHINE}" ]]; then
393 echo "MACHINE is not configured for ${target}"
Brad Bishop91a200b2019-08-22 14:24:33 -0400394 exit 1
Michael Shepos2de03e92018-11-07 15:54:56 -0600395fi
396
Brad Bishop91a200b2019-08-22 14:24:33 -0400397export MACHINE="${MACHINE}"
Andrew Geissler8565d2a2020-04-20 15:22:14 -0500398if [[ -z "${DISTRO}" ]]; then
399 echo "DISTRO is not configured for ${target} so will use default"
400 unset DISTRO
401else
402 export DISTRO="${DISTRO}"
403fi
Brad Bishop91a200b2019-08-22 14:24:33 -0400404
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500405# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100406cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100407BB_NUMBER_THREADS = "$(nproc)"
408PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100409INHERIT += "rm_work"
410BB_GENERATE_MIRROR_TARBALLS = "1"
Alanny Lopez1246b032018-02-24 23:34:55 -0600411DL_DIR="${ssc_dir}/bitbake_downloads"
412SSTATE_DIR="${ssc_dir}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100413USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500414INHERIT_remove = "uninative"
Alanny Lopez1246b032018-02-24 23:34:55 -0600415TMPDIR="${build_dir}"
Lei YU237bd082020-09-22 11:15:08 +0800416${ENV_LOCAL_CONF}
Chris Smart02651712015-11-11 11:09:00 +1100417EOF_CONF
418
419# Kick off a build
Michael Shepos33aeca42019-06-13 02:36:17 -0500420if [[ -n "${nice_priority}" ]]; then
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500421 nice -${nice_priority} bitbake ${BITBAKE_OPTS} ${bitbake_target}
Michael Shepos33aeca42019-06-13 02:36:17 -0500422else
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500423 bitbake ${BITBAKE_OPTS} ${bitbake_target}
Michael Shepos33aeca42019-06-13 02:36:17 -0500424fi
Chris Smart02651712015-11-11 11:09:00 +1100425
Alanny Lopez1246b032018-02-24 23:34:55 -0600426# Copy internal build directory into xtrct_path directory
Charles Paul Hoferb249c2c2018-09-12 12:15:13 -0500427if [[ ${xtrct_small_copy_dir} ]]; then
428 mkdir -p ${xtrct_path}/${xtrct_small_copy_dir}
429 timeout ${xtrct_copy_timeout} cp -r ${build_dir}/${xtrct_small_copy_dir}/* ${xtrct_path}/${xtrct_small_copy_dir}
430else
431 timeout ${xtrct_copy_timeout} cp -r ${build_dir}/* ${xtrct_path}
432fi
Charles Paul Hoferbe8700e2018-09-05 09:28:08 -0500433
434if [[ 0 -ne $? ]]; then
435 echo "Received a non-zero exit code from timeout"
436 exit 1
437fi
438
Chris Smart02651712015-11-11 11:09:00 +1100439EOF_SCRIPT
440
Patrick Williams384d7412020-11-06 16:15:41 -0600441chmod a+x "${WORKSPACE}/build.sh"
Chris Smart02651712015-11-11 11:09:00 +1100442
Alanny Lopez51186882017-08-01 16:14:41 -0500443# Give the Docker image a name based on the distro,tag,arch,and target
Alanny Lopez1246b032018-02-24 23:34:55 -0600444img_name=${img_name:-openbmc/${distro}:${img_tag}-${target}-${ARCH}}
Alanny Lopez51186882017-08-01 16:14:41 -0500445
446# Build the Docker image
Patrick Williams384d7412020-11-06 16:15:41 -0600447docker build -t "${img_name}" - <<< "${Dockerfile}"
Alanny Lopez51186882017-08-01 16:14:41 -0500448
Michael Shepos3939e952019-01-16 16:00:35 -0600449# If obmc_dir or ssc_dir are ${HOME} or a subdirectory they will not be mounted
450mount_obmc_dir="-v ""${obmc_dir}"":""${obmc_dir}"" "
451mount_ssc_dir="-v ""${ssc_dir}"":""${ssc_dir}"" "
Lei YUde2a3202020-04-28 11:34:23 +0800452mount_workspace_dir="-v ""${WORKSPACE}"":""${WORKSPACE}"" "
Michael Shepos3939e952019-01-16 16:00:35 -0600453if [[ "${obmc_dir}" = "${HOME}/"* || "${obmc_dir}" = "${HOME}" ]];then
454mount_obmc_dir=""
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500455fi
Michael Shepos3939e952019-01-16 16:00:35 -0600456if [[ "${ssc_dir}" = "${HOME}/"* || "${ssc_dir}" = "${HOME}" ]];then
457mount_ssc_dir=""
458fi
Lei YUde2a3202020-04-28 11:34:23 +0800459if [[ "${WORKSPACE}" = "${HOME}/"* || "${WORKSPACE}" = "${HOME}" ]];then
460mount_workspace_dir=""
461fi
Michael Shepos3939e952019-01-16 16:00:35 -0600462
463# Run the Docker container, execute the build.sh script
Patrick Williams384d7412020-11-06 16:15:41 -0600464# shellcheck disable=SC2086 # mount commands word-split purposefully
Michael Shepos3939e952019-01-16 16:00:35 -0600465docker run \
466--cap-add=sys_admin \
Michael Shepos33aeca42019-06-13 02:36:17 -0500467--cap-add=sys_nice \
Michael Shepos3939e952019-01-16 16:00:35 -0600468--net=host \
469--rm=true \
Patrick Williams384d7412020-11-06 16:15:41 -0600470-e WORKSPACE="${WORKSPACE}" \
Michael Shepos3939e952019-01-16 16:00:35 -0600471-w "${HOME}" \
Patrick Williams384d7412020-11-06 16:15:41 -0600472-v "${HOME}:${HOME}" \
Michael Shepos3939e952019-01-16 16:00:35 -0600473${mount_obmc_dir} \
474${mount_ssc_dir} \
Lei YUde2a3202020-04-28 11:34:23 +0800475${mount_workspace_dir} \
Michael Shepos3939e952019-01-16 16:00:35 -0600476--cpus="$num_cpu" \
Ed Tanous3af51682021-01-28 13:57:00 -0800477"${img_name}" \
Patrick Williams384d7412020-11-06 16:15:41 -0600478"${WORKSPACE}/build.sh"
Chris Smart02651712015-11-11 11:09:00 +1100479
Alanny Lopezd32d3322017-07-18 15:21:39 -0500480# To maintain function of resources that used an older path, add a link
Patrick Williams384d7412020-11-06 16:15:41 -0600481ln -sf "${xtrct_path}/deploy" "${WORKSPACE}/deploy"
Alanny Lopezd32d3322017-07-18 15:21:39 -0500482
Chris Smart02651712015-11-11 11:09:00 +1100483# Timestamp for build
Alanny Lopez0e8ad992017-06-19 15:45:23 -0500484echo "Build completed, $(date)"