blob: 1dd5ed4c6c4a1077143611383682e1384d9b844e [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"
Patrick Williams01dd4362021-02-19 17:45:40 -060041# target The target we aim to build. Any system supported by
42# the openbmc/openbmc `setup` script is an option.
Ed Tanousd3c516b2021-08-19 11:39:09 -070043# repotest is a target to specifically run the CI checks
Patrick Williams1642d132021-02-19 15:18:20 -060044# Default: "qemuarm"
Andrew Geissler215e43c2019-04-23 10:57:48 -050045# no_tar Set to true if you do not want the debug tar built
46# Default: "false"
Michael Shepos33aeca42019-06-13 02:36:17 -050047# nice_priority Set nice priotity for bitbake command.
48# Nice:
49# Run with an adjusted niceness, which affects process
50# scheduling. Nice values range from -20 (most favorable
51# to the process) to 19 (least favorable to the process).
52# Default: "", nice is not used if nice_priority is not set
Alanny Lopez723fea62017-09-12 11:22:17 -050053#
Alanny Lopeze08e8702018-02-24 18:07:13 -060054# Deployment Variables:
Alanny Lopez1246b032018-02-24 23:34:55 -060055# obmc_dir Path of the OpenBMC repo directory used as a reference
Alanny Lopeze08e8702018-02-24 18:07:13 -060056# for the build inside the container.
57# Default: "${WORKSPACE}/openbmc"
Lei YUdf0e45c2020-09-03 11:25:57 +080058# ssc_dir Path of the OpenBMC shared directory that contains the
59# downloads dir and the sstate dir.
60# Default: "${HOME}"
Michael Shepos10afbb22019-02-06 13:33:07 -060061# xtrct_small_copy_dir
62# Directory within build_dir that should be copied to
63# xtrct_path. The directory and all parents up to, but not
64# including, build_dir will be copied. For example, if
65# build_dir is set to "/tmp/openbmc" and this is set to
66# "build/tmp", the directory at xtrct_path will have the
67# following directory structure:
68# xtrct_path
69# | - build
70# | - tmp
71# ...
72# Can also be set to the empty string to copy the entire
73# contents of build_dir to xtrct_path.
74# Default: "deploy/images".
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050075#
76###############################################################################
Joel Stanley4b8b2392016-02-12 15:44:57 +103077# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103078set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110079
Alanny Lopez46967702018-02-25 00:29:14 -060080# Script Variables:
81build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"}
82http_proxy=${http_proxy:-}
83WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Andrew Geisslerdc1e7022018-03-26 07:54:48 -070084num_cpu=${num_cpu:-$(nproc)}
Lei YU39587ad2020-06-17 19:55:54 +080085UBUNTU_MIRROR=${UBUNTU_MIRROR:-""}
Lei YU237bd082020-09-22 11:15:08 +080086ENV_LOCAL_CONF=${ENV_LOCAL_CONF:-""}
Alanny Lopez46967702018-02-25 00:29:14 -060087
88# Docker Image Build Variables:
Andrew Geisslerbd11f692020-09-04 09:36:28 -050089build_dir=${build_dir:-${WORKSPACE}/build}
Chris Smart02651712015-11-11 11:09:00 +110090distro=${distro:-ubuntu}
Alanny Lopez1246b032018-02-24 23:34:55 -060091img_tag=${img_tag:-latest}
Patrick Williams1642d132021-02-19 15:18:20 -060092target=${target:-qemuarm}
Andrew Geissler215e43c2019-04-23 10:57:48 -050093no_tar=${no_tar:-false}
Michael Shepos33aeca42019-06-13 02:36:17 -050094nice_priority=${nice_priority:-}
Alanny Lopez46967702018-02-25 00:29:14 -060095
96# Deployment variables
Alanny Lopez46967702018-02-25 00:29:14 -060097obmc_dir=${obmc_dir:-${WORKSPACE}/openbmc}
Lei YUdf0e45c2020-09-03 11:25:57 +080098ssc_dir=${ssc_dir:-${HOME}}
Michael Shepos10afbb22019-02-06 13:33:07 -060099xtrct_small_copy_dir=${xtrct_small_copy_dir:-deploy/images}
Michael Shepos3939e952019-01-16 16:00:35 -0600100xtrct_path="${obmc_dir}/build/tmp"
101xtrct_copy_timeout="300"
Alanny Lopez46967702018-02-25 00:29:14 -0600102
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500103bitbake_target="obmc-phosphor-image"
Chris Smartc3522542016-02-16 11:59:36 +1100104PROXY=""
Chris Smart02651712015-11-11 11:09:00 +1100105
Lei YU39587ad2020-06-17 19:55:54 +0800106MIRROR=""
107if [[ -n "${UBUNTU_MIRROR}" ]]; then
108 MIRROR="RUN echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME) main restricted universe multiverse\" > /etc/apt/sources.list && \
109 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-updates main restricted universe multiverse\" >> /etc/apt/sources.list && \
110 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-security main restricted universe multiverse\" >> /etc/apt/sources.list && \
111 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-proposed main restricted universe multiverse\" >> /etc/apt/sources.list && \
112 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-backports main restricted universe multiverse\" >> /etc/apt/sources.list"
113fi
114
Alanny Lopezccc650e2017-04-24 15:14:20 -0500115# Determine the architecture
116ARCH=$(uname -m)
117
118# Determine the prefix of the Dockerfile's base image
119case ${ARCH} in
Patrick Williams476a7e92022-12-06 09:52:53 -0600120 "ppc64le")
121 DOCKER_BASE="ppc64le/"
122 ;;
123 "x86_64")
124 DOCKER_BASE=""
125 ;;
126 "aarch64")
127 DOCKER_BASE="arm64v8/"
128 ;;
129 *)
130 echo "Unsupported system architecture(${ARCH}) found for docker image"
131 exit 1
Alanny Lopezccc650e2017-04-24 15:14:20 -0500132esac
Andrew Geissler11abbbe2016-08-14 19:39:47 -0500133
Chris Smart02651712015-11-11 11:09:00 +1100134# Timestamp for job
135echo "Build started, $(date)"
136
Alanny Lopez1246b032018-02-24 23:34:55 -0600137# If the obmc_dir directory doesn't exist clone it in
Patrick Williams384d7412020-11-06 16:15:41 -0600138if [ ! -d "${obmc_dir}" ]; then
Patrick Williams476a7e92022-12-06 09:52:53 -0600139 echo "Clone in openbmc master to ${obmc_dir}"
140 git clone https://github.com/openbmc/openbmc "${obmc_dir}"
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500141fi
142
Ed Tanousd3c516b2021-08-19 11:39:09 -0700143if [[ "$target" = repotest ]]; then
Patrick Williams476a7e92022-12-06 09:52:53 -0600144 DOCKER_IMAGE_NAME=$(./scripts/build-unit-test-docker)
145 docker run --cap-add=sys_admin --rm=true \
146 --network host \
147 --privileged=true \
148 -u "$USER" \
149 -w "${obmc_dir}" -v "${obmc_dir}:${obmc_dir}" \
150 -t "${DOCKER_IMAGE_NAME}" \
151 "${obmc_dir}"/meta-phosphor/scripts/run-repotest
152 exit
Ed Tanousd3c516b2021-08-19 11:39:09 -0700153fi
154
Alanny Lopez1246b032018-02-24 23:34:55 -0600155# Make and chown the xtrct_path directory to avoid permission errors
Patrick Williams384d7412020-11-06 16:15:41 -0600156if [ ! -d "${xtrct_path}" ]; then
Patrick Williams476a7e92022-12-06 09:52:53 -0600157 mkdir -p "${xtrct_path}"
Alanny Lopez723fea62017-09-12 11:22:17 -0500158fi
Patrick Williams384d7412020-11-06 16:15:41 -0600159chown "${UID}:${GROUPS[0]}" "${xtrct_path}"
Alanny Lopez723fea62017-09-12 11:22:17 -0500160
Patrick Williams01dd4362021-02-19 17:45:40 -0600161# Perform overrides for specific machines as required.
Adriana Kobylak1d2682b2021-04-01 18:40:42 +0000162DISTRO=${DISTRO:-}
Chris Smart02651712015-11-11 11:09:00 +1100163
Patrick Williams01dd4362021-02-19 17:45:40 -0600164# Set build target and BitBake command
165MACHINE="${target}"
Patrick Williamsf88e83f2021-02-19 15:15:06 -0600166BITBAKE_CMD="source ./setup ${MACHINE} ${build_dir}"
Brad Bishop7161a172018-10-05 16:48:06 -0400167
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500168# Configure Docker build
Chris Smart02651712015-11-11 11:09:00 +1100169if [[ "${distro}" == fedora ]];then
170
Patrick Williams476a7e92022-12-06 09:52:53 -0600171 if [[ -n "${http_proxy}" ]]; then
172 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
173 fi
Chris Smart02651712015-11-11 11:09:00 +1100174
Patrick Williams476a7e92022-12-06 09:52:53 -0600175 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600176 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100177
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500178 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100179
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500180 RUN dnf --refresh install -y \
181 bzip2 \
182 chrpath \
183 cpio \
184 diffstat \
Andrew Geissler36a12ec2022-05-04 16:46:56 -0400185 file \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500186 findutils \
187 gcc \
188 gcc-c++ \
189 git \
Frederic Jacob865a0912023-07-07 19:05:53 -0700190 lz4 \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500191 make \
192 patch \
193 perl-bignum \
194 perl-Data-Dumper \
195 perl-Thread-Queue \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500196 python3-devel \
197 SDL-devel \
198 socat \
199 subversion \
200 tar \
201 texinfo \
202 wget \
Saqib Khan5158a322017-10-23 11:31:24 -0500203 which \
Andrew Geissler40c1c9c2020-09-04 10:50:36 -0500204 file \
205 hostname \
206 rpcgen \
207 glibc-langpack-en \
Frederic Jacob865a0912023-07-07 19:05:53 -0700208 glibc-locale-source \
209 zstd
Andrew Geissler40c1c9c2020-09-04 10:50:36 -0500210
211 # Set the locale
212 ENV LANG=en_US.utf8
213 RUN localedef -f UTF-8 -i en_US en_US.UTF-8
Chris Smart02651712015-11-11 11:09:00 +1100214
Patrick Williams384d7412020-11-06 16:15:41 -0600215 RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
216 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100217
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500218 USER ${USER}
219 ENV HOME ${HOME}
Chris Smart02651712015-11-11 11:09:00 +1100220EOF
Patrick Williams476a7e92022-12-06 09:52:53 -0600221 )
Chris Smart02651712015-11-11 11:09:00 +1100222
Alanny Lopezccc650e2017-04-24 15:14:20 -0500223elif [[ "${distro}" == ubuntu ]]; then
224
Patrick Williams476a7e92022-12-06 09:52:53 -0600225 if [[ -n "${http_proxy}" ]]; then
226 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
227 fi
Chris Smart02651712015-11-11 11:09:00 +1100228
Patrick Williams476a7e92022-12-06 09:52:53 -0600229 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}
Lei YU39587ad2020-06-17 19:55:54 +0800233 ${MIRROR}
Chris Smart02651712015-11-11 11:09:00 +1100234
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500235 ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500236
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500237 RUN apt-get update && apt-get install -yy \
238 build-essential \
239 chrpath \
Andrew Geisslerce47cad2021-09-03 08:45:03 -0500240 cpio \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500241 debianutils \
242 diffstat \
Andrew Geissler36a12ec2022-05-04 16:46:56 -0400243 file \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500244 gawk \
245 git \
Andrew Geisslerce47cad2021-09-03 08:45:03 -0500246 iputils-ping \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500247 libdata-dumper-simple-perl \
Andrew Geissler0a82a762021-09-03 08:46:24 -0500248 liblz4-tool \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500249 libsdl1.2-dev \
250 libthread-queue-any-perl \
Alanny Lopez27af3a02017-05-26 10:49:06 -0500251 locales \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500252 python3 \
253 socat \
254 subversion \
255 texinfo \
Andrew Geisslerb7291422022-12-14 11:48:36 -0600256 vim \
Andrew Geissler0a82a762021-09-03 08:46:24 -0500257 wget \
258 zstd
Chris Smart02651712015-11-11 11:09:00 +1100259
Alanny Lopez27af3a02017-05-26 10:49:06 -0500260 # Set the locale
261 RUN locale-gen en_US.UTF-8
262 ENV LANG en_US.UTF-8
263 ENV LANGUAGE en_US:en
264 ENV LC_ALL en_US.UTF-8
265
Patrick Williams384d7412020-11-06 16:15:41 -0600266 RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
267 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100268
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500269 USER ${USER}
270 ENV HOME ${HOME}
Chris Smart02651712015-11-11 11:09:00 +1100271EOF
Patrick Williams476a7e92022-12-06 09:52:53 -0600272 )
Chris Smart02651712015-11-11 11:09:00 +1100273fi
274
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500275# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100276export PROXY_HOST=${http_proxy/#http*:\/\/}
277export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
278export PROXY_PORT=${http_proxy/#http*:\/\/*:}
279
Patrick Williams384d7412020-11-06 16:15:41 -0600280mkdir -p "${WORKSPACE}"
Chris Smart02651712015-11-11 11:09:00 +1100281
Andrew Geissler215e43c2019-04-23 10:57:48 -0500282# Determine command for bitbake image build
Patrick Williams384d7412020-11-06 16:15:41 -0600283if [ "$no_tar" = "false" ]; then
Andrew Geissler2eb45d32019-09-18 21:56:44 -0500284 bitbake_target="${bitbake_target} obmc-phosphor-debug-tarball"
Andrew Geissler215e43c2019-04-23 10:57:48 -0500285fi
286
Chris Smart01d2b962015-11-11 18:05:30 +1100287cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100288#!/bin/bash
289
Joel Stanley38c9d142016-02-16 12:31:55 +1030290set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100291
Alanny Lopez723fea62017-09-12 11:22:17 -0500292# Go into the OpenBMC directory, the build will handle changing directories
Alanny Lopez1246b032018-02-24 23:34:55 -0600293cd ${obmc_dir}
Chris Smart02651712015-11-11 11:09:00 +1100294
295# Set up proxies
296export ftp_proxy=${http_proxy}
297export http_proxy=${http_proxy}
298export https_proxy=${http_proxy}
299
Chris Smart01d2b962015-11-11 18:05:30 +1100300mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100301
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500302# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100303if [[ -n "${http_proxy}" ]]; then
304
Chris Smartd30c5902016-03-01 15:00:54 +1100305 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500306 #!/bin/bash
307 # \$1 = hostname, \$2 = port
308 PROXY=${PROXY_HOST}
309 PROXY_PORT=${PROXY_PORT}
310 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100311EOF_GIT
312
Chris Smart01d2b962015-11-11 18:05:30 +1100313 chmod a+x ${WORKSPACE}/bin/git-proxy
314 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100315
Lei YUa76d7ce2020-05-11 15:20:56 +0800316 lock=${HOME}/build-setup.lock
317 flock \${lock} git config --global core.gitProxy ${WORKSPACE}/bin/git-proxy
318 flock \${lock} git config --global http.proxy ${http_proxy}
Chris Smart02651712015-11-11 11:09:00 +1100319
Lei YUa76d7ce2020-05-11 15:20:56 +0800320 flock \${lock} mkdir -p ~/.subversion
321 flock \${lock} cat > ~/.subversion/servers << EOF_SVN
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500322 [global]
323 http-proxy-host = ${PROXY_HOST}
324 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100325EOF_SVN
Lei YU58cb3ad2020-04-30 13:04:58 +0800326
Lei YUa76d7ce2020-05-11 15:20:56 +0800327 flock \${lock} cat > ~/.wgetrc << EOF_WGETRC
Lei YU58cb3ad2020-04-30 13:04:58 +0800328 https_proxy = ${http_proxy}
329 http_proxy = ${http_proxy}
330 use_proxy = on
331EOF_WGETRC
332
Lei YUa76d7ce2020-05-11 15:20:56 +0800333 flock \${lock} cat > ~/.curlrc << EOF_CURLRC
Lei YU58cb3ad2020-04-30 13:04:58 +0800334 proxy = ${PROXY_HOST}:${PROXY_PORT}
335EOF_CURLRC
Chris Smart02651712015-11-11 11:09:00 +1100336fi
337
338# Source our build env
339${BITBAKE_CMD}
340
Andrew Geissler8565d2a2020-04-20 15:22:14 -0500341if [[ -z "${MACHINE}" ]]; then
342 echo "MACHINE is not configured for ${target}"
Brad Bishop91a200b2019-08-22 14:24:33 -0400343 exit 1
Michael Shepos2de03e92018-11-07 15:54:56 -0600344fi
345
Brad Bishop91a200b2019-08-22 14:24:33 -0400346export MACHINE="${MACHINE}"
Andrew Geissler8565d2a2020-04-20 15:22:14 -0500347if [[ -z "${DISTRO}" ]]; then
348 echo "DISTRO is not configured for ${target} so will use default"
349 unset DISTRO
350else
351 export DISTRO="${DISTRO}"
352fi
Brad Bishop91a200b2019-08-22 14:24:33 -0400353
Andrew Geisslerf87a7bc2021-01-29 09:28:40 -0600354# bitbake requires SDKMACHINE be x86
355export SDKMACHINE=x86_64
356
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500357# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100358cat >> conf/local.conf << EOF_CONF
Andrew Geissler4b9df8d2023-01-06 15:29:39 -0600359BB_NUMBER_THREADS = "$num_cpu"
360PARALLEL_MAKE = "-j$num_cpu"
Chris Smart02651712015-11-11 11:09:00 +1100361INHERIT += "rm_work"
362BB_GENERATE_MIRROR_TARBALLS = "1"
Alanny Lopez1246b032018-02-24 23:34:55 -0600363DL_DIR="${ssc_dir}/bitbake_downloads"
364SSTATE_DIR="${ssc_dir}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100365USER_CLASSES += "buildstats"
Patrick Williams120c99e2021-08-10 11:05:00 -0500366INHERIT:remove = "uninative"
Alanny Lopez1246b032018-02-24 23:34:55 -0600367TMPDIR="${build_dir}"
Lei YU237bd082020-09-22 11:15:08 +0800368${ENV_LOCAL_CONF}
Chris Smart02651712015-11-11 11:09:00 +1100369EOF_CONF
370
371# Kick off a build
Michael Shepos33aeca42019-06-13 02:36:17 -0500372if [[ -n "${nice_priority}" ]]; then
Patrick Williams625f2852022-04-27 21:56:02 -0500373 nice -${nice_priority} bitbake -k ${BITBAKE_OPTS} ${bitbake_target}
Michael Shepos33aeca42019-06-13 02:36:17 -0500374else
Patrick Williams625f2852022-04-27 21:56:02 -0500375 bitbake -k ${BITBAKE_OPTS} ${bitbake_target}
Michael Shepos33aeca42019-06-13 02:36:17 -0500376fi
Chris Smart02651712015-11-11 11:09:00 +1100377
Alanny Lopez1246b032018-02-24 23:34:55 -0600378# Copy internal build directory into xtrct_path directory
Charles Paul Hoferb249c2c2018-09-12 12:15:13 -0500379if [[ ${xtrct_small_copy_dir} ]]; then
380 mkdir -p ${xtrct_path}/${xtrct_small_copy_dir}
381 timeout ${xtrct_copy_timeout} cp -r ${build_dir}/${xtrct_small_copy_dir}/* ${xtrct_path}/${xtrct_small_copy_dir}
382else
383 timeout ${xtrct_copy_timeout} cp -r ${build_dir}/* ${xtrct_path}
384fi
Charles Paul Hoferbe8700e2018-09-05 09:28:08 -0500385
386if [[ 0 -ne $? ]]; then
387 echo "Received a non-zero exit code from timeout"
388 exit 1
389fi
390
Chris Smart02651712015-11-11 11:09:00 +1100391EOF_SCRIPT
392
Patrick Williams384d7412020-11-06 16:15:41 -0600393chmod a+x "${WORKSPACE}/build.sh"
Chris Smart02651712015-11-11 11:09:00 +1100394
Alanny Lopez51186882017-08-01 16:14:41 -0500395# Give the Docker image a name based on the distro,tag,arch,and target
Alanny Lopez1246b032018-02-24 23:34:55 -0600396img_name=${img_name:-openbmc/${distro}:${img_tag}-${target}-${ARCH}}
Alanny Lopez51186882017-08-01 16:14:41 -0500397
Andrew Geisslerd0dabc32023-04-04 08:09:21 -0600398# Ensure appropriate docker build output to see progress and identify
399# any issues
400export BUILDKIT_PROGRESS=plain
401
Alanny Lopez51186882017-08-01 16:14:41 -0500402# Build the Docker image
Patrick Williams384d7412020-11-06 16:15:41 -0600403docker build -t "${img_name}" - <<< "${Dockerfile}"
Alanny Lopez51186882017-08-01 16:14:41 -0500404
Michael Shepos3939e952019-01-16 16:00:35 -0600405# If obmc_dir or ssc_dir are ${HOME} or a subdirectory they will not be mounted
406mount_obmc_dir="-v ""${obmc_dir}"":""${obmc_dir}"" "
407mount_ssc_dir="-v ""${ssc_dir}"":""${ssc_dir}"" "
Lei YUde2a3202020-04-28 11:34:23 +0800408mount_workspace_dir="-v ""${WORKSPACE}"":""${WORKSPACE}"" "
Michael Shepos3939e952019-01-16 16:00:35 -0600409if [[ "${obmc_dir}" = "${HOME}/"* || "${obmc_dir}" = "${HOME}" ]];then
Patrick Williams476a7e92022-12-06 09:52:53 -0600410 mount_obmc_dir=""
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500411fi
Michael Shepos3939e952019-01-16 16:00:35 -0600412if [[ "${ssc_dir}" = "${HOME}/"* || "${ssc_dir}" = "${HOME}" ]];then
Patrick Williams476a7e92022-12-06 09:52:53 -0600413 mount_ssc_dir=""
Michael Shepos3939e952019-01-16 16:00:35 -0600414fi
Lei YUde2a3202020-04-28 11:34:23 +0800415if [[ "${WORKSPACE}" = "${HOME}/"* || "${WORKSPACE}" = "${HOME}" ]];then
Patrick Williams476a7e92022-12-06 09:52:53 -0600416 mount_workspace_dir=""
Lei YUde2a3202020-04-28 11:34:23 +0800417fi
Michael Shepos3939e952019-01-16 16:00:35 -0600418
Andrew Geisslerafdc0542023-03-31 15:55:22 -0600419# If we are building on a podman based machine, need to have this set in
420# the env to allow the home mount to work (no impact on non-podman systems)
421export PODMAN_USERNS="keep-id"
422
Michael Shepos3939e952019-01-16 16:00:35 -0600423# Run the Docker container, execute the build.sh script
Patrick Williams384d7412020-11-06 16:15:41 -0600424# shellcheck disable=SC2086 # mount commands word-split purposefully
Michael Shepos3939e952019-01-16 16:00:35 -0600425docker run \
Patrick Williams476a7e92022-12-06 09:52:53 -0600426 --cap-add=sys_admin \
427 --cap-add=sys_nice \
428 --net=host \
429 --rm=true \
430 -e WORKSPACE="${WORKSPACE}" \
431 -w "${HOME}" \
432 -v "${HOME}:${HOME}" \
433 ${mount_obmc_dir} \
434 ${mount_ssc_dir} \
435 ${mount_workspace_dir} \
Patrick Williams476a7e92022-12-06 09:52:53 -0600436 "${img_name}" \
437 "${WORKSPACE}/build.sh"
Chris Smart02651712015-11-11 11:09:00 +1100438
Alanny Lopezd32d3322017-07-18 15:21:39 -0500439# To maintain function of resources that used an older path, add a link
Patrick Williams384d7412020-11-06 16:15:41 -0600440ln -sf "${xtrct_path}/deploy" "${WORKSPACE}/deploy"
Alanny Lopezd32d3322017-07-18 15:21:39 -0500441
Chris Smart02651712015-11-11 11:09:00 +1100442# Timestamp for build
Alanny Lopez0e8ad992017-06-19 15:45:23 -0500443echo "Build completed, $(date)"