blob: 3747195c014bcd9b90c759a0f535add09d042faf [file] [log] [blame]
Stewart Smith098d03e2016-03-01 13:59:42 +11001#!/bin/bash
2
Stewart Smith45af3fc2019-07-23 15:45:10 +10003CONTAINERS="ubuntu1804 fedora30"
Stewart Smith6650dd42017-02-16 14:41:10 +11004
Stewart Smithc4b9bf62018-08-24 13:30:15 +10005
6SDK_ONLY=0
7
8while getopts ":ab:hp:c:rs:S" opt; do
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +05309 case $opt in
Stewart Smithc4b9bf62018-08-24 13:30:15 +100010 s)
11 echo "SDK Cache dir"
12 SDK_CACHE="$OPTARG"
13 ;;
14 S)
15 echo "Build SDK Only"
16 SDK_ONLY=1
17 ;;
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053018 a)
19 echo "Build firmware images for all the platforms"
20 PLATFORMS=""
21 ;;
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100022 b)
23 echo "Directory to bind to container: $OPTARG"
24 BIND="$OPTARG"
25 ;;
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053026 p)
27 echo "Build firmware images for the platforms: $OPTARG"
28 PLATFORMS=$OPTARG
29 ;;
Stewart Smith6650dd42017-02-16 14:41:10 +110030 c)
31 echo "Build in container: $OPTARG"
32 CONTAINERS=$OPTARG
33 ;;
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053034 h)
35 echo "Usage: ./ci/build.sh [options] [--]"
36 echo "-h Print this help and exit successfully."
37 echo "-a Build firmware images for all the platform defconfig's."
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100038 echo "-b DIR Bind DIR to container."
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053039 echo "-p List of comma separated platform names to build images for particular platforms."
Joel Stanley4c94b9e2018-11-01 13:20:03 +103040 echo "-s DIR SDK cache dir (must exist)."
Stewart Smithc4b9bf62018-08-24 13:30:15 +100041 echo "-S Build SDK only"
Stewart Smith6650dd42017-02-16 14:41:10 +110042 echo "-c Container to run in"
Joel Stanley3226cf32018-11-01 13:20:08 +103043 echo ""
44 echo "Note: set environment variables HTTP_PROXY and HTTPS_PROXY if a proxy is required."
45 echo ""
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053046 echo "Example:DOCKER_PREFIX=sudo ./ci/build.sh -a"
47 echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p firestone"
Joel Stanley33ed8f12019-04-03 12:13:43 +103048 echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p garrison,palmetto,opal"
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053049 exit 1
50 ;;
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100051 r)
52 echo "Build for release"
53 release_args="-r"
54 ;;
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053055 \?)
56 echo "Invalid option: -$OPTARG"
57 exit 1
58 ;;
59 :)
60 echo "Option -$OPTARG requires an argument."
61 exit 1
62 ;;
63 esac
64done
65
Stewart Smith098d03e2016-03-01 13:59:42 +110066set -ex
67set -eo pipefail
68
69function run_docker
70{
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100071 if [ -n "$BIND" ]; then
72 BINDARG="--mount=type=bind,src=${BIND},dst=${BIND}"
73 else
74 BINDARG="--mount=type=bind,src=${PWD},dst=${PWD}"
75 fi
Stewart Smith9c20ae22018-10-29 15:24:50 +110076 $DOCKER_PREFIX docker run --init --cap-add=sys_admin --net=host --rm=true \
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100077 --user="${USER}" -w "${PWD}" "${BINDARG}" \
Stewart Smith098d03e2016-03-01 13:59:42 +110078 -t $1 $2
79}
80
Stewart Smithc4b9bf62018-08-24 13:30:15 +100081function toolchain_hash
82{
83 echo -n 'toolchain-'$((git submodule ; cd openpower/configs/; cat `ls -1 |grep '_defconfig$'|sort`)|sha1sum |sed -e 's/ .*//')
84}
Stewart Smith098d03e2016-03-01 13:59:42 +110085
Stewart Smithc4b9bf62018-08-24 13:30:15 +100086env
Stewart Smith098d03e2016-03-01 13:59:42 +110087
Stewart Smith6650dd42017-02-16 14:41:10 +110088for distro in $CONTAINERS;
Stewart Smith098d03e2016-03-01 13:59:42 +110089do
Samuel Mendoza-Jonas79722502018-07-25 14:59:07 +100090 base_dockerfile=ci/Dockerfile/$distro.`uname -m`
Stewart Smith098d03e2016-03-01 13:59:42 +110091 if [ ! -f $base_dockerfile ]; then
Samuel Mendoza-Jonas79722502018-07-25 14:59:07 +100092 echo "$distro not supported on $(uname -m).";
Stewart Smith098d03e2016-03-01 13:59:42 +110093 continue
94 fi
95 if [[ -n "$HTTP_PROXY" ]]; then
96 http_proxy=$HTTP_PROXY
Stewart Smith915cea12018-01-16 16:07:49 +110097 HTTP_PROXY_ENV="ENV http_proxy $HTTP_PROXY"
98 fi
99 if [[ -n "$HTTPS_PROXY" ]]; then
100 https_proxy=$HTTPS_PROXY
101 HTTPS_PROXY_ENV="ENV https_proxy $HTTPS_PROXY"
Stewart Smith098d03e2016-03-01 13:59:42 +1100102 fi
103 if [[ -n "$http_proxy" ]]; then
Stewart Smith45af3fc2019-07-23 15:45:10 +1000104 if [[ "$distro" == fedora30 ]]; then
Stewart Smith098d03e2016-03-01 13:59:42 +1100105 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
106 fi
Stewart Smith26b9f992019-03-27 14:46:49 +1100107 if [[ "$distro" == ubuntu1804 ]]; then
Stewart Smith098d03e2016-03-01 13:59:42 +1100108 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
109 fi
110 fi
Joel Stanleyce8ae8d2018-11-01 13:19:50 +1030111 if [ ! -z ${DL_DIR+x} ]; then
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +1000112 DL_DIR_ENV="ENV DL_DIR $DL_DIR"
113 fi
Joel Stanleyce8ae8d2018-11-01 13:19:50 +1030114 if [ ! -z ${CCACHE_DIR+x} ]; then
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +1000115 CCACHE_DIR_ENV="ENV CCACHE_DIR $CCACHE_DIR"
116 fi
Stewart Smith098d03e2016-03-01 13:59:42 +1100117
118 Dockerfile=$(head -n1 $base_dockerfile; echo ${PROXY}; tail -n +2 $base_dockerfile; cat << EOF
Stewart Smith098d03e2016-03-01 13:59:42 +1100119${PROXY}
Stewart Smith915cea12018-01-16 16:07:49 +1100120RUN useradd -d ${HOME} -m -u ${UID} ${USER}
Stewart Smith098d03e2016-03-01 13:59:42 +1100121ENV HOME ${HOME}
Stewart Smith915cea12018-01-16 16:07:49 +1100122${HTTP_PROXY_ENV}
123${HTTPS_PROXY_ENV}
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +1000124${DL_DIR_ENV}
125${CCACHE_DIR_ENV}
Stewart Smith098d03e2016-03-01 13:59:42 +1100126EOF
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000127 )
Samuel Mendoza-Jonas86f9bb82018-08-06 12:51:59 +1000128 $DOCKER_PREFIX docker build --network=host -t openpower/op-build-$distro - <<< "${Dockerfile}"
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000129 if [ -d "$SDK_CACHE" ]; then
130 SDK_DIR=$SDK_CACHE/$(toolchain_hash)-$distro
131 if [ ! -d "$SDK_DIR" ]; then
132 chmod +x ci/build-sdk.sh
133 run_docker openpower/op-build-$distro "./ci/build-sdk.sh $distro witherspoon_defconfig"
134 mv output-$distro-witherspoon_defconfig $SDK_DIR
135 $SDK_DIR/host/relocate-sdk.sh
136 fi
137 sdk_args="-s $SDK_DIR/host"
Stewart Smith098d03e2016-03-01 13:59:42 +1100138 else
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000139 sdk_args=""
140 fi
141
142 if [ $SDK_ONLY == 0 ]; then
143 run_docker openpower/op-build-$distro "./ci/build-all-defconfigs.sh -o `pwd`/output-$distro -p $PLATFORMS ${release_args} ${sdk_args}"
144 fi
145
146 if [ $? != 0 ]; then
Stewart Smith098d03e2016-03-01 13:59:42 +1100147 exit $?;
148 fi
149done;
150