Alanny Lopez | 56fc36a | 2017-07-27 13:55:44 -0500 | [diff] [blame] | 1 | #!/bin/bash |
Alanny Lopez | b0a12dd | 2017-04-24 16:21:47 -0500 | [diff] [blame] | 2 | ############################################################################### |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 3 | # |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 4 | # This build script is for running the OpenBMC builds as Docker containers. |
Alanny Lopez | 3fbaa51 | 2017-04-24 15:46:52 -0500 | [diff] [blame] | 5 | # |
Alanny Lopez | b0a12dd | 2017-04-24 16:21:47 -0500 | [diff] [blame] | 6 | ############################################################################### |
| 7 | # |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 8 | # 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 Geissler | dc1e702 | 2018-03-26 07:54:48 -0700 | [diff] [blame] | 16 | # num_cpu Number of cpu's to give bitbake, default is total amount |
| 17 | # in system |
Lei YU | 237bd08 | 2020-09-22 11:15:08 +0800 | [diff] [blame] | 18 | # UBUNTU_MIRROR [optional] The URL of a mirror of Ubuntu to override the |
| 19 | # default ones in /etc/apt/sources.list |
Lei YU | 39587ad | 2020-06-17 19:55:54 +0800 | [diff] [blame] | 20 | # default is empty, and no mirror is used. |
Lei YU | 237bd08 | 2020-09-22 11:15:08 +0800 | [diff] [blame] | 21 | # 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 Lopez | b0a12dd | 2017-04-24 16:21:47 -0500 | [diff] [blame] | 24 | # |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 25 | # Docker Image Build Variables: |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 26 | # BITBAKE_OPTS Set to "-c populate_sdk" or whatever other BitBake options |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 27 | # you'd like to pass into the build. |
| 28 | # Default: "", no options set |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 29 | # build_dir Path where the actual BitBake build occurs inside the |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 30 | # container, path cannot be located on network storage. |
Andrew Geissler | bd11f69 | 2020-09-04 09:36:28 -0500 | [diff] [blame] | 31 | # Default: "$WORKSPACE/build" |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 32 | # distro The distro used as the base image for the build image: |
| 33 | # fedora|ubuntu |
| 34 | # Default: "ubuntu" |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 35 | # img_name The name given to the target build's docker image. |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 36 | # Default: "openbmc/${distro}:${imgtag}-${target}-${ARCH}" |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 37 | # img_tag The base docker image distro tag: |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 38 | # ubuntu: latest|16.04|14.04|trusty|xenial |
| 39 | # fedora: 23|24|25 |
| 40 | # Default: "latest" |
Patrick Williams | 01dd436 | 2021-02-19 17:45:40 -0600 | [diff] [blame] | 41 | # target The target we aim to build. Any system supported by |
| 42 | # the openbmc/openbmc `setup` script is an option. |
Patrick Williams | 1642d13 | 2021-02-19 15:18:20 -0600 | [diff] [blame] | 43 | # Default: "qemuarm" |
Andrew Geissler | 215e43c | 2019-04-23 10:57:48 -0500 | [diff] [blame] | 44 | # no_tar Set to true if you do not want the debug tar built |
| 45 | # Default: "false" |
Michael Shepos | 33aeca4 | 2019-06-13 02:36:17 -0500 | [diff] [blame] | 46 | # nice_priority Set nice priotity for bitbake command. |
| 47 | # Nice: |
| 48 | # Run with an adjusted niceness, which affects process |
| 49 | # scheduling. Nice values range from -20 (most favorable |
| 50 | # to the process) to 19 (least favorable to the process). |
| 51 | # Default: "", nice is not used if nice_priority is not set |
Alanny Lopez | 723fea6 | 2017-09-12 11:22:17 -0500 | [diff] [blame] | 52 | # |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 53 | # Deployment Variables: |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 54 | # obmc_dir Path of the OpenBMC repo directory used as a reference |
Alanny Lopez | e08e870 | 2018-02-24 18:07:13 -0600 | [diff] [blame] | 55 | # for the build inside the container. |
| 56 | # Default: "${WORKSPACE}/openbmc" |
Lei YU | df0e45c | 2020-09-03 11:25:57 +0800 | [diff] [blame] | 57 | # ssc_dir Path of the OpenBMC shared directory that contains the |
| 58 | # downloads dir and the sstate dir. |
| 59 | # Default: "${HOME}" |
Michael Shepos | 10afbb2 | 2019-02-06 13:33:07 -0600 | [diff] [blame] | 60 | # xtrct_small_copy_dir |
| 61 | # Directory within build_dir that should be copied to |
| 62 | # xtrct_path. The directory and all parents up to, but not |
| 63 | # including, build_dir will be copied. For example, if |
| 64 | # build_dir is set to "/tmp/openbmc" and this is set to |
| 65 | # "build/tmp", the directory at xtrct_path will have the |
| 66 | # following directory structure: |
| 67 | # xtrct_path |
| 68 | # | - build |
| 69 | # | - tmp |
| 70 | # ... |
| 71 | # Can also be set to the empty string to copy the entire |
| 72 | # contents of build_dir to xtrct_path. |
| 73 | # Default: "deploy/images". |
Alanny Lopez | b0a12dd | 2017-04-24 16:21:47 -0500 | [diff] [blame] | 74 | # |
| 75 | ############################################################################### |
Joel Stanley | 4b8b239 | 2016-02-12 15:44:57 +1030 | [diff] [blame] | 76 | # Trace bash processing. Set -e so when a step fails, we fail the build |
Joel Stanley | 38c9d14 | 2016-02-16 12:31:55 +1030 | [diff] [blame] | 77 | set -xeo pipefail |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 78 | |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 79 | # Script Variables: |
| 80 | build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"} |
| 81 | http_proxy=${http_proxy:-} |
| 82 | WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} |
Andrew Geissler | dc1e702 | 2018-03-26 07:54:48 -0700 | [diff] [blame] | 83 | num_cpu=${num_cpu:-$(nproc)} |
Lei YU | 39587ad | 2020-06-17 19:55:54 +0800 | [diff] [blame] | 84 | UBUNTU_MIRROR=${UBUNTU_MIRROR:-""} |
Lei YU | 237bd08 | 2020-09-22 11:15:08 +0800 | [diff] [blame] | 85 | ENV_LOCAL_CONF=${ENV_LOCAL_CONF:-""} |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 86 | |
| 87 | # Docker Image Build Variables: |
Andrew Geissler | bd11f69 | 2020-09-04 09:36:28 -0500 | [diff] [blame] | 88 | build_dir=${build_dir:-${WORKSPACE}/build} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 89 | distro=${distro:-ubuntu} |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 90 | img_tag=${img_tag:-latest} |
Patrick Williams | 1642d13 | 2021-02-19 15:18:20 -0600 | [diff] [blame] | 91 | target=${target:-qemuarm} |
Andrew Geissler | 215e43c | 2019-04-23 10:57:48 -0500 | [diff] [blame] | 92 | no_tar=${no_tar:-false} |
Michael Shepos | 33aeca4 | 2019-06-13 02:36:17 -0500 | [diff] [blame] | 93 | nice_priority=${nice_priority:-} |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 94 | |
| 95 | # Deployment variables |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 96 | obmc_dir=${obmc_dir:-${WORKSPACE}/openbmc} |
Lei YU | df0e45c | 2020-09-03 11:25:57 +0800 | [diff] [blame] | 97 | ssc_dir=${ssc_dir:-${HOME}} |
Michael Shepos | 10afbb2 | 2019-02-06 13:33:07 -0600 | [diff] [blame] | 98 | xtrct_small_copy_dir=${xtrct_small_copy_dir:-deploy/images} |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 99 | xtrct_path="${obmc_dir}/build/tmp" |
| 100 | xtrct_copy_timeout="300" |
Alanny Lopez | 4696770 | 2018-02-25 00:29:14 -0600 | [diff] [blame] | 101 | |
Andrew Geissler | 2eb45d3 | 2019-09-18 21:56:44 -0500 | [diff] [blame] | 102 | bitbake_target="obmc-phosphor-image" |
Chris Smart | c352254 | 2016-02-16 11:59:36 +1100 | [diff] [blame] | 103 | PROXY="" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 104 | |
Lei YU | 39587ad | 2020-06-17 19:55:54 +0800 | [diff] [blame] | 105 | MIRROR="" |
| 106 | if [[ -n "${UBUNTU_MIRROR}" ]]; then |
| 107 | MIRROR="RUN echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME) main restricted universe multiverse\" > /etc/apt/sources.list && \ |
| 108 | echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-updates main restricted universe multiverse\" >> /etc/apt/sources.list && \ |
| 109 | echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-security main restricted universe multiverse\" >> /etc/apt/sources.list && \ |
| 110 | echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-proposed main restricted universe multiverse\" >> /etc/apt/sources.list && \ |
| 111 | echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-backports main restricted universe multiverse\" >> /etc/apt/sources.list" |
| 112 | fi |
| 113 | |
Alanny Lopez | ccc650e | 2017-04-24 15:14:20 -0500 | [diff] [blame] | 114 | # Determine the architecture |
| 115 | ARCH=$(uname -m) |
| 116 | |
| 117 | # Determine the prefix of the Dockerfile's base image |
| 118 | case ${ARCH} in |
| 119 | "ppc64le") |
| 120 | DOCKER_BASE="ppc64le/" |
| 121 | ;; |
| 122 | "x86_64") |
| 123 | DOCKER_BASE="" |
| 124 | ;; |
| 125 | *) |
| 126 | echo "Unsupported system architecture(${ARCH}) found for docker image" |
| 127 | exit 1 |
| 128 | esac |
Andrew Geissler | 11abbbe | 2016-08-14 19:39:47 -0500 | [diff] [blame] | 129 | |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 130 | # Timestamp for job |
| 131 | echo "Build started, $(date)" |
| 132 | |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 133 | # If the obmc_dir directory doesn't exist clone it in |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 134 | if [ ! -d "${obmc_dir}" ]; then |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 135 | echo "Clone in openbmc master to ${obmc_dir}" |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 136 | git clone https://github.com/openbmc/openbmc "${obmc_dir}" |
Andrew Geissler | c3c3520 | 2016-08-16 08:47:50 -0500 | [diff] [blame] | 137 | fi |
| 138 | |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 139 | # Make and chown the xtrct_path directory to avoid permission errors |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 140 | if [ ! -d "${xtrct_path}" ]; then |
| 141 | mkdir -p "${xtrct_path}" |
Alanny Lopez | 723fea6 | 2017-09-12 11:22:17 -0500 | [diff] [blame] | 142 | fi |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 143 | chown "${UID}:${GROUPS[0]}" "${xtrct_path}" |
Alanny Lopez | 723fea6 | 2017-09-12 11:22:17 -0500 | [diff] [blame] | 144 | |
Patrick Williams | 01dd436 | 2021-02-19 17:45:40 -0600 | [diff] [blame] | 145 | # Perform overrides for specific machines as required. |
Adriana Kobylak | 1d2682b | 2021-04-01 18:40:42 +0000 | [diff] [blame] | 146 | DISTRO=${DISTRO:-} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 147 | |
Patrick Williams | 01dd436 | 2021-02-19 17:45:40 -0600 | [diff] [blame] | 148 | # Set build target and BitBake command |
| 149 | MACHINE="${target}" |
Patrick Williams | f88e83f | 2021-02-19 15:15:06 -0600 | [diff] [blame] | 150 | BITBAKE_CMD="source ./setup ${MACHINE} ${build_dir}" |
Brad Bishop | 7161a17 | 2018-10-05 16:48:06 -0400 | [diff] [blame] | 151 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 152 | # Configure Docker build |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 153 | if [[ "${distro}" == fedora ]];then |
| 154 | |
| 155 | if [[ -n "${http_proxy}" ]]; then |
| 156 | PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf" |
| 157 | fi |
| 158 | |
| 159 | Dockerfile=$(cat << EOF |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 160 | FROM ${DOCKER_BASE}${distro}:${img_tag} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 161 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 162 | ${PROXY} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 163 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 164 | RUN dnf --refresh install -y \ |
| 165 | bzip2 \ |
| 166 | chrpath \ |
| 167 | cpio \ |
| 168 | diffstat \ |
| 169 | findutils \ |
| 170 | gcc \ |
| 171 | gcc-c++ \ |
| 172 | git \ |
| 173 | make \ |
| 174 | patch \ |
| 175 | perl-bignum \ |
| 176 | perl-Data-Dumper \ |
| 177 | perl-Thread-Queue \ |
| 178 | python-devel \ |
| 179 | python3-devel \ |
| 180 | SDL-devel \ |
| 181 | socat \ |
| 182 | subversion \ |
| 183 | tar \ |
| 184 | texinfo \ |
| 185 | wget \ |
Saqib Khan | 5158a32 | 2017-10-23 11:31:24 -0500 | [diff] [blame] | 186 | which \ |
Andrew Geissler | 40c1c9c | 2020-09-04 10:50:36 -0500 | [diff] [blame] | 187 | file \ |
| 188 | hostname \ |
| 189 | rpcgen \ |
| 190 | glibc-langpack-en \ |
| 191 | glibc-locale-source |
| 192 | |
| 193 | # Set the locale |
| 194 | ENV LANG=en_US.utf8 |
| 195 | RUN localedef -f UTF-8 -i en_US en_US.UTF-8 |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 196 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 197 | RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} |
| 198 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 199 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 200 | USER ${USER} |
| 201 | ENV HOME ${HOME} |
| 202 | RUN /bin/bash |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 203 | EOF |
| 204 | ) |
| 205 | |
Alanny Lopez | ccc650e | 2017-04-24 15:14:20 -0500 | [diff] [blame] | 206 | elif [[ "${distro}" == ubuntu ]]; then |
| 207 | |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 208 | if [[ -n "${http_proxy}" ]]; then |
| 209 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
| 210 | fi |
| 211 | |
| 212 | Dockerfile=$(cat << EOF |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 213 | FROM ${DOCKER_BASE}${distro}:${img_tag} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 214 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 215 | ${PROXY} |
Lei YU | 39587ad | 2020-06-17 19:55:54 +0800 | [diff] [blame] | 216 | ${MIRROR} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 217 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 218 | ENV DEBIAN_FRONTEND noninteractive |
Saqib Khan | 7563512 | 2017-03-23 10:57:34 -0500 | [diff] [blame] | 219 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 220 | RUN apt-get update && apt-get install -yy \ |
| 221 | build-essential \ |
| 222 | chrpath \ |
| 223 | debianutils \ |
| 224 | diffstat \ |
| 225 | gawk \ |
| 226 | git \ |
| 227 | libdata-dumper-simple-perl \ |
| 228 | libsdl1.2-dev \ |
| 229 | libthread-queue-any-perl \ |
Alanny Lopez | 27af3a0 | 2017-05-26 10:49:06 -0500 | [diff] [blame] | 230 | locales \ |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 231 | python \ |
| 232 | python3 \ |
| 233 | socat \ |
| 234 | subversion \ |
| 235 | texinfo \ |
| 236 | cpio \ |
Saqib Khan | 5158a32 | 2017-10-23 11:31:24 -0500 | [diff] [blame] | 237 | wget \ |
| 238 | iputils-ping |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 239 | |
Alanny Lopez | 27af3a0 | 2017-05-26 10:49:06 -0500 | [diff] [blame] | 240 | # Set the locale |
| 241 | RUN locale-gen en_US.UTF-8 |
| 242 | ENV LANG en_US.UTF-8 |
| 243 | ENV LANGUAGE en_US:en |
| 244 | ENV LC_ALL en_US.UTF-8 |
| 245 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 246 | RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} |
| 247 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER} |
Chris Smart | d30c590 | 2016-03-01 15:00:54 +1100 | [diff] [blame] | 248 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 249 | USER ${USER} |
| 250 | ENV HOME ${HOME} |
| 251 | RUN /bin/bash |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 252 | EOF |
| 253 | ) |
| 254 | fi |
| 255 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 256 | # Create the Docker run script |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 257 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 258 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 259 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 260 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 261 | mkdir -p "${WORKSPACE}" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 262 | |
Andrew Geissler | 215e43c | 2019-04-23 10:57:48 -0500 | [diff] [blame] | 263 | # Determine command for bitbake image build |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 264 | if [ "$no_tar" = "false" ]; then |
Andrew Geissler | 2eb45d3 | 2019-09-18 21:56:44 -0500 | [diff] [blame] | 265 | bitbake_target="${bitbake_target} obmc-phosphor-debug-tarball" |
Andrew Geissler | 215e43c | 2019-04-23 10:57:48 -0500 | [diff] [blame] | 266 | fi |
| 267 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 268 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 269 | #!/bin/bash |
| 270 | |
Joel Stanley | 38c9d14 | 2016-02-16 12:31:55 +1030 | [diff] [blame] | 271 | set -xeo pipefail |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 272 | |
Alanny Lopez | 723fea6 | 2017-09-12 11:22:17 -0500 | [diff] [blame] | 273 | # Go into the OpenBMC directory, the build will handle changing directories |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 274 | cd ${obmc_dir} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 275 | |
| 276 | # Set up proxies |
| 277 | export ftp_proxy=${http_proxy} |
| 278 | export http_proxy=${http_proxy} |
| 279 | export https_proxy=${http_proxy} |
| 280 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 281 | mkdir -p ${WORKSPACE}/bin |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 282 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 283 | # Configure proxies for BitBake |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 284 | if [[ -n "${http_proxy}" ]]; then |
| 285 | |
Chris Smart | d30c590 | 2016-03-01 15:00:54 +1100 | [diff] [blame] | 286 | cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 287 | #!/bin/bash |
| 288 | # \$1 = hostname, \$2 = port |
| 289 | PROXY=${PROXY_HOST} |
| 290 | PROXY_PORT=${PROXY_PORT} |
| 291 | exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 292 | EOF_GIT |
| 293 | |
Chris Smart | 01d2b96 | 2015-11-11 18:05:30 +1100 | [diff] [blame] | 294 | chmod a+x ${WORKSPACE}/bin/git-proxy |
| 295 | export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 296 | |
Lei YU | a76d7ce | 2020-05-11 15:20:56 +0800 | [diff] [blame] | 297 | lock=${HOME}/build-setup.lock |
| 298 | flock \${lock} git config --global core.gitProxy ${WORKSPACE}/bin/git-proxy |
| 299 | flock \${lock} git config --global http.proxy ${http_proxy} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 300 | |
Lei YU | a76d7ce | 2020-05-11 15:20:56 +0800 | [diff] [blame] | 301 | flock \${lock} mkdir -p ~/.subversion |
| 302 | flock \${lock} cat > ~/.subversion/servers << EOF_SVN |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 303 | [global] |
| 304 | http-proxy-host = ${PROXY_HOST} |
| 305 | http-proxy-port = ${PROXY_PORT} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 306 | EOF_SVN |
Lei YU | 58cb3ad | 2020-04-30 13:04:58 +0800 | [diff] [blame] | 307 | |
Lei YU | a76d7ce | 2020-05-11 15:20:56 +0800 | [diff] [blame] | 308 | flock \${lock} cat > ~/.wgetrc << EOF_WGETRC |
Lei YU | 58cb3ad | 2020-04-30 13:04:58 +0800 | [diff] [blame] | 309 | https_proxy = ${http_proxy} |
| 310 | http_proxy = ${http_proxy} |
| 311 | use_proxy = on |
| 312 | EOF_WGETRC |
| 313 | |
Lei YU | a76d7ce | 2020-05-11 15:20:56 +0800 | [diff] [blame] | 314 | flock \${lock} cat > ~/.curlrc << EOF_CURLRC |
Lei YU | 58cb3ad | 2020-04-30 13:04:58 +0800 | [diff] [blame] | 315 | proxy = ${PROXY_HOST}:${PROXY_PORT} |
| 316 | EOF_CURLRC |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 317 | fi |
| 318 | |
| 319 | # Source our build env |
| 320 | ${BITBAKE_CMD} |
| 321 | |
Andrew Geissler | 8565d2a | 2020-04-20 15:22:14 -0500 | [diff] [blame] | 322 | if [[ -z "${MACHINE}" ]]; then |
| 323 | echo "MACHINE is not configured for ${target}" |
Brad Bishop | 91a200b | 2019-08-22 14:24:33 -0400 | [diff] [blame] | 324 | exit 1 |
Michael Shepos | 2de03e9 | 2018-11-07 15:54:56 -0600 | [diff] [blame] | 325 | fi |
| 326 | |
Brad Bishop | 91a200b | 2019-08-22 14:24:33 -0400 | [diff] [blame] | 327 | export MACHINE="${MACHINE}" |
Andrew Geissler | 8565d2a | 2020-04-20 15:22:14 -0500 | [diff] [blame] | 328 | if [[ -z "${DISTRO}" ]]; then |
| 329 | echo "DISTRO is not configured for ${target} so will use default" |
| 330 | unset DISTRO |
| 331 | else |
| 332 | export DISTRO="${DISTRO}" |
| 333 | fi |
Brad Bishop | 91a200b | 2019-08-22 14:24:33 -0400 | [diff] [blame] | 334 | |
Andrew Geissler | f87a7bc | 2021-01-29 09:28:40 -0600 | [diff] [blame] | 335 | # bitbake requires SDKMACHINE be x86 |
| 336 | export SDKMACHINE=x86_64 |
| 337 | |
Alanny Lopez | eaa2eae | 2017-04-24 14:55:07 -0500 | [diff] [blame] | 338 | # Custom BitBake config settings |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 339 | cat >> conf/local.conf << EOF_CONF |
Chris Smart | c650c20 | 2015-11-25 15:58:53 +1100 | [diff] [blame] | 340 | BB_NUMBER_THREADS = "$(nproc)" |
| 341 | PARALLEL_MAKE = "-j$(nproc)" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 342 | INHERIT += "rm_work" |
| 343 | BB_GENERATE_MIRROR_TARBALLS = "1" |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 344 | DL_DIR="${ssc_dir}/bitbake_downloads" |
| 345 | SSTATE_DIR="${ssc_dir}/bitbake_sharedstatecache" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 346 | USER_CLASSES += "buildstats" |
Andrew Geissler | 931ec67 | 2016-08-11 13:10:05 -0500 | [diff] [blame] | 347 | INHERIT_remove = "uninative" |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 348 | TMPDIR="${build_dir}" |
Lei YU | 237bd08 | 2020-09-22 11:15:08 +0800 | [diff] [blame] | 349 | ${ENV_LOCAL_CONF} |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 350 | EOF_CONF |
| 351 | |
| 352 | # Kick off a build |
Michael Shepos | 33aeca4 | 2019-06-13 02:36:17 -0500 | [diff] [blame] | 353 | if [[ -n "${nice_priority}" ]]; then |
Andrew Geissler | 2eb45d3 | 2019-09-18 21:56:44 -0500 | [diff] [blame] | 354 | nice -${nice_priority} bitbake ${BITBAKE_OPTS} ${bitbake_target} |
Michael Shepos | 33aeca4 | 2019-06-13 02:36:17 -0500 | [diff] [blame] | 355 | else |
Andrew Geissler | 2eb45d3 | 2019-09-18 21:56:44 -0500 | [diff] [blame] | 356 | bitbake ${BITBAKE_OPTS} ${bitbake_target} |
Michael Shepos | 33aeca4 | 2019-06-13 02:36:17 -0500 | [diff] [blame] | 357 | fi |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 358 | |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 359 | # Copy internal build directory into xtrct_path directory |
Charles Paul Hofer | b249c2c | 2018-09-12 12:15:13 -0500 | [diff] [blame] | 360 | if [[ ${xtrct_small_copy_dir} ]]; then |
| 361 | mkdir -p ${xtrct_path}/${xtrct_small_copy_dir} |
| 362 | timeout ${xtrct_copy_timeout} cp -r ${build_dir}/${xtrct_small_copy_dir}/* ${xtrct_path}/${xtrct_small_copy_dir} |
| 363 | else |
| 364 | timeout ${xtrct_copy_timeout} cp -r ${build_dir}/* ${xtrct_path} |
| 365 | fi |
Charles Paul Hofer | be8700e | 2018-09-05 09:28:08 -0500 | [diff] [blame] | 366 | |
| 367 | if [[ 0 -ne $? ]]; then |
| 368 | echo "Received a non-zero exit code from timeout" |
| 369 | exit 1 |
| 370 | fi |
| 371 | |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 372 | EOF_SCRIPT |
| 373 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 374 | chmod a+x "${WORKSPACE}/build.sh" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 375 | |
Alanny Lopez | 5118688 | 2017-08-01 16:14:41 -0500 | [diff] [blame] | 376 | # Give the Docker image a name based on the distro,tag,arch,and target |
Alanny Lopez | 1246b03 | 2018-02-24 23:34:55 -0600 | [diff] [blame] | 377 | img_name=${img_name:-openbmc/${distro}:${img_tag}-${target}-${ARCH}} |
Alanny Lopez | 5118688 | 2017-08-01 16:14:41 -0500 | [diff] [blame] | 378 | |
| 379 | # Build the Docker image |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 380 | docker build -t "${img_name}" - <<< "${Dockerfile}" |
Alanny Lopez | 5118688 | 2017-08-01 16:14:41 -0500 | [diff] [blame] | 381 | |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 382 | # If obmc_dir or ssc_dir are ${HOME} or a subdirectory they will not be mounted |
| 383 | mount_obmc_dir="-v ""${obmc_dir}"":""${obmc_dir}"" " |
| 384 | mount_ssc_dir="-v ""${ssc_dir}"":""${ssc_dir}"" " |
Lei YU | de2a320 | 2020-04-28 11:34:23 +0800 | [diff] [blame] | 385 | mount_workspace_dir="-v ""${WORKSPACE}"":""${WORKSPACE}"" " |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 386 | if [[ "${obmc_dir}" = "${HOME}/"* || "${obmc_dir}" = "${HOME}" ]];then |
| 387 | mount_obmc_dir="" |
Alanny Lopez | 3fbaa51 | 2017-04-24 15:46:52 -0500 | [diff] [blame] | 388 | fi |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 389 | if [[ "${ssc_dir}" = "${HOME}/"* || "${ssc_dir}" = "${HOME}" ]];then |
| 390 | mount_ssc_dir="" |
| 391 | fi |
Lei YU | de2a320 | 2020-04-28 11:34:23 +0800 | [diff] [blame] | 392 | if [[ "${WORKSPACE}" = "${HOME}/"* || "${WORKSPACE}" = "${HOME}" ]];then |
| 393 | mount_workspace_dir="" |
| 394 | fi |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 395 | |
| 396 | # Run the Docker container, execute the build.sh script |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 397 | # shellcheck disable=SC2086 # mount commands word-split purposefully |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 398 | docker run \ |
| 399 | --cap-add=sys_admin \ |
Michael Shepos | 33aeca4 | 2019-06-13 02:36:17 -0500 | [diff] [blame] | 400 | --cap-add=sys_nice \ |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 401 | --net=host \ |
| 402 | --rm=true \ |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 403 | -e WORKSPACE="${WORKSPACE}" \ |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 404 | -w "${HOME}" \ |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 405 | -v "${HOME}:${HOME}" \ |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 406 | ${mount_obmc_dir} \ |
| 407 | ${mount_ssc_dir} \ |
Lei YU | de2a320 | 2020-04-28 11:34:23 +0800 | [diff] [blame] | 408 | ${mount_workspace_dir} \ |
Michael Shepos | 3939e95 | 2019-01-16 16:00:35 -0600 | [diff] [blame] | 409 | --cpus="$num_cpu" \ |
Ed Tanous | 3af5168 | 2021-01-28 13:57:00 -0800 | [diff] [blame] | 410 | "${img_name}" \ |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 411 | "${WORKSPACE}/build.sh" |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 412 | |
Alanny Lopez | d32d332 | 2017-07-18 15:21:39 -0500 | [diff] [blame] | 413 | # To maintain function of resources that used an older path, add a link |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 414 | ln -sf "${xtrct_path}/deploy" "${WORKSPACE}/deploy" |
Alanny Lopez | d32d332 | 2017-07-18 15:21:39 -0500 | [diff] [blame] | 415 | |
Chris Smart | 0265171 | 2015-11-11 11:09:00 +1100 | [diff] [blame] | 416 | # Timestamp for build |
Alanny Lopez | 0e8ad99 | 2017-06-19 15:45:23 -0500 | [diff] [blame] | 417 | echo "Build completed, $(date)" |