blob: a0430df2b82ebb775a8d1cc022feb44740cd7599 [file] [log] [blame]
Stewart Smith098d03e2016-03-01 13:59:42 +11001#!/bin/bash
2
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -03003set -ex
4set -eo pipefail
5
Stewart Smith45af3fc2019-07-23 15:45:10 +10006CONTAINERS="ubuntu1804 fedora30"
Stewart Smithc4b9bf62018-08-24 13:30:15 +10007SDK_ONLY=0
8
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -03009opt=$(getopt -o 's:Sab:p:c:hr' -- "$@")
10if [ $? != 0 ] ; then
11 echo "Invalid arguments"
12 exit 1
13fi
14
15eval set -- "$opt"
16unset opt
17
18while true; do
19 case "$1" in
20 '-s')
21 shift
22 echo "SDK Cache dir: $1"
23 SDK_CACHE="$1"
Stewart Smithc4b9bf62018-08-24 13:30:15 +100024 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030025 '-S')
Stewart Smithc4b9bf62018-08-24 13:30:15 +100026 echo "Build SDK Only"
27 SDK_ONLY=1
28 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030029 '-a')
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053030 echo "Build firmware images for all the platforms"
31 PLATFORMS=""
32 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030033 '-b')
34 shift
35 echo "Directory to bind to container: $1"
36 BIND="$1"
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100037 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030038 '-p')
39 shift
40 echo "Build firmware images for the platforms: $1"
41 PLATFORMS="$1"
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053042 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030043 '-c')
44 shift
45 echo "Build in container: $1"
46 CONTAINERS="$1"
Stewart Smith6650dd42017-02-16 14:41:10 +110047 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030048 '-h')
49 echo "Usage: ./ci/build.sh [options]"
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053050 echo "-h Print this help and exit successfully."
51 echo "-a Build firmware images for all the platform defconfig's."
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100052 echo "-b DIR Bind DIR to container."
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053053 echo "-p List of comma separated platform names to build images for particular platforms."
Joel Stanley4c94b9e2018-11-01 13:20:03 +103054 echo "-s DIR SDK cache dir (must exist)."
Stewart Smithc4b9bf62018-08-24 13:30:15 +100055 echo "-S Build SDK only"
Stewart Smith6650dd42017-02-16 14:41:10 +110056 echo "-c Container to run in"
Joel Stanley3226cf32018-11-01 13:20:08 +103057 echo ""
58 echo "Note: set environment variables HTTP_PROXY and HTTPS_PROXY if a proxy is required."
59 echo ""
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053060 echo "Example:DOCKER_PREFIX=sudo ./ci/build.sh -a"
61 echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p firestone"
Joel Stanley33ed8f12019-04-03 12:13:43 +103062 echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p garrison,palmetto,opal"
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053063 exit 1
64 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030065 '-r')
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100066 echo "Build for release"
67 release_args="-r"
68 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030069 '--')
70 shift
71 break
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053072 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030073 *)
74 echo "Internal Error!"
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053075 exit 1
76 ;;
77 esac
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030078 shift
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053079done
80
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030081
82if [ ! -d "$SDK_CACHE" ]; then
83 echo "Error: SDK Cache dir doesn't exist: $SDK_CACHE"
84 exit 1
85fi
Stewart Smith098d03e2016-03-01 13:59:42 +110086
87function run_docker
88{
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100089 if [ -n "$BIND" ]; then
90 BINDARG="--mount=type=bind,src=${BIND},dst=${BIND}"
91 else
92 BINDARG="--mount=type=bind,src=${PWD},dst=${PWD}"
93 fi
Stewart Smith9c20ae22018-10-29 15:24:50 +110094 $DOCKER_PREFIX docker run --init --cap-add=sys_admin --net=host --rm=true \
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100095 --user="${USER}" -w "${PWD}" "${BINDARG}" \
Stewart Smith098d03e2016-03-01 13:59:42 +110096 -t $1 $2
97}
98
Stewart Smithc4b9bf62018-08-24 13:30:15 +100099function toolchain_hash
100{
101 echo -n 'toolchain-'$((git submodule ; cd openpower/configs/; cat `ls -1 |grep '_defconfig$'|sort`)|sha1sum |sed -e 's/ .*//')
102}
Stewart Smith098d03e2016-03-01 13:59:42 +1100103
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000104env
Stewart Smith098d03e2016-03-01 13:59:42 +1100105
Stewart Smith6650dd42017-02-16 14:41:10 +1100106for distro in $CONTAINERS;
Stewart Smith098d03e2016-03-01 13:59:42 +1100107do
Samuel Mendoza-Jonas79722502018-07-25 14:59:07 +1000108 base_dockerfile=ci/Dockerfile/$distro.`uname -m`
Stewart Smith098d03e2016-03-01 13:59:42 +1100109 if [ ! -f $base_dockerfile ]; then
Samuel Mendoza-Jonas79722502018-07-25 14:59:07 +1000110 echo "$distro not supported on $(uname -m).";
Stewart Smith098d03e2016-03-01 13:59:42 +1100111 continue
112 fi
113 if [[ -n "$HTTP_PROXY" ]]; then
114 http_proxy=$HTTP_PROXY
Stewart Smith915cea12018-01-16 16:07:49 +1100115 HTTP_PROXY_ENV="ENV http_proxy $HTTP_PROXY"
116 fi
117 if [[ -n "$HTTPS_PROXY" ]]; then
118 https_proxy=$HTTPS_PROXY
119 HTTPS_PROXY_ENV="ENV https_proxy $HTTPS_PROXY"
Stewart Smith098d03e2016-03-01 13:59:42 +1100120 fi
121 if [[ -n "$http_proxy" ]]; then
Stewart Smith45af3fc2019-07-23 15:45:10 +1000122 if [[ "$distro" == fedora30 ]]; then
Stewart Smith098d03e2016-03-01 13:59:42 +1100123 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
124 fi
Stewart Smith26b9f992019-03-27 14:46:49 +1100125 if [[ "$distro" == ubuntu1804 ]]; then
Stewart Smith098d03e2016-03-01 13:59:42 +1100126 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
127 fi
128 fi
Joel Stanleyce8ae8d2018-11-01 13:19:50 +1030129 if [ ! -z ${DL_DIR+x} ]; then
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +1000130 DL_DIR_ENV="ENV DL_DIR $DL_DIR"
131 fi
Joel Stanleyce8ae8d2018-11-01 13:19:50 +1030132 if [ ! -z ${CCACHE_DIR+x} ]; then
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +1000133 CCACHE_DIR_ENV="ENV CCACHE_DIR $CCACHE_DIR"
134 fi
Stewart Smith098d03e2016-03-01 13:59:42 +1100135
136 Dockerfile=$(head -n1 $base_dockerfile; echo ${PROXY}; tail -n +2 $base_dockerfile; cat << EOF
Stewart Smith098d03e2016-03-01 13:59:42 +1100137${PROXY}
Stewart Smith915cea12018-01-16 16:07:49 +1100138RUN useradd -d ${HOME} -m -u ${UID} ${USER}
Stewart Smith098d03e2016-03-01 13:59:42 +1100139ENV HOME ${HOME}
Stewart Smith915cea12018-01-16 16:07:49 +1100140${HTTP_PROXY_ENV}
141${HTTPS_PROXY_ENV}
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +1000142${DL_DIR_ENV}
143${CCACHE_DIR_ENV}
Stewart Smith098d03e2016-03-01 13:59:42 +1100144EOF
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000145 )
Samuel Mendoza-Jonas86f9bb82018-08-06 12:51:59 +1000146 $DOCKER_PREFIX docker build --network=host -t openpower/op-build-$distro - <<< "${Dockerfile}"
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -0300147 SDK_DIR=$SDK_CACHE/$(toolchain_hash)-$distro
148 if [ ! -d "$SDK_DIR" ]; then
149 chmod +x ci/build-sdk.sh
150 run_docker openpower/op-build-$distro "./ci/build-sdk.sh $distro witherspoon_defconfig"
151 mv output-$distro-witherspoon_defconfig $SDK_DIR
152 $SDK_DIR/host/relocate-sdk.sh
153 fi
154
155 sdk_args="-s $SDK_DIR/host"
156
157 if [ -n "$PLATFORMS" ]; then
158 platform_args="-p $PLATFORMS"
Stewart Smith098d03e2016-03-01 13:59:42 +1100159 else
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -0300160 platform_args=""
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000161 fi
162
163 if [ $SDK_ONLY == 0 ]; then
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -0300164 run_docker openpower/op-build-$distro "./ci/build-all-defconfigs.sh -o `pwd`/output-$distro ${platform_args} ${release_args} ${sdk_args}"
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000165 fi
166
167 if [ $? != 0 ]; then
Stewart Smith098d03e2016-03-01 13:59:42 +1100168 exit $?;
169 fi
170done;
171