blob: f663ef463d29ea15cce1ed1ecf55c8715a50dbd5 [file] [log] [blame]
Stewart Smith098d03e2016-03-01 13:59:42 +11001#!/bin/bash
2
Stewart Smith915cea12018-01-16 16:07:49 +11003CONTAINERS="ubuntu1604 fedora27"
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."
Stewart Smithc4b9bf62018-08-24 13:30:15 +100040 echo "-s DIR SDK cache dir."
41 echo "-S Build SDK only"
Stewart Smith6650dd42017-02-16 14:41:10 +110042 echo "-c Container to run in"
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053043 echo "Example:DOCKER_PREFIX=sudo ./ci/build.sh -a"
44 echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p firestone"
45 echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p garrison,palmetto,openpower_p9_mambo"
46 exit 1
47 ;;
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100048 r)
49 echo "Build for release"
50 release_args="-r"
51 ;;
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053052 \?)
53 echo "Invalid option: -$OPTARG"
54 exit 1
55 ;;
56 :)
57 echo "Option -$OPTARG requires an argument."
58 exit 1
59 ;;
60 esac
61done
62
Stewart Smith098d03e2016-03-01 13:59:42 +110063set -ex
64set -eo pipefail
65
66function run_docker
67{
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100068 if [ -n "$BIND" ]; then
69 BINDARG="--mount=type=bind,src=${BIND},dst=${BIND}"
70 else
71 BINDARG="--mount=type=bind,src=${PWD},dst=${PWD}"
72 fi
Stewart Smith9c20ae22018-10-29 15:24:50 +110073 $DOCKER_PREFIX docker run --init --cap-add=sys_admin --net=host --rm=true \
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100074 --user="${USER}" -w "${PWD}" "${BINDARG}" \
Stewart Smith098d03e2016-03-01 13:59:42 +110075 -t $1 $2
76}
77
Stewart Smithc4b9bf62018-08-24 13:30:15 +100078function toolchain_hash
79{
80 echo -n 'toolchain-'$((git submodule ; cd openpower/configs/; cat `ls -1 |grep '_defconfig$'|sort`)|sha1sum |sed -e 's/ .*//')
81}
Stewart Smith098d03e2016-03-01 13:59:42 +110082
Stewart Smithc4b9bf62018-08-24 13:30:15 +100083env
Stewart Smith098d03e2016-03-01 13:59:42 +110084
Stewart Smith6650dd42017-02-16 14:41:10 +110085for distro in $CONTAINERS;
Stewart Smith098d03e2016-03-01 13:59:42 +110086do
Samuel Mendoza-Jonas79722502018-07-25 14:59:07 +100087 base_dockerfile=ci/Dockerfile/$distro.`uname -m`
Stewart Smith098d03e2016-03-01 13:59:42 +110088 if [ ! -f $base_dockerfile ]; then
Samuel Mendoza-Jonas79722502018-07-25 14:59:07 +100089 echo "$distro not supported on $(uname -m).";
Stewart Smith098d03e2016-03-01 13:59:42 +110090 continue
91 fi
92 if [[ -n "$HTTP_PROXY" ]]; then
93 http_proxy=$HTTP_PROXY
Stewart Smith915cea12018-01-16 16:07:49 +110094 HTTP_PROXY_ENV="ENV http_proxy $HTTP_PROXY"
95 fi
96 if [[ -n "$HTTPS_PROXY" ]]; then
97 https_proxy=$HTTPS_PROXY
98 HTTPS_PROXY_ENV="ENV https_proxy $HTTPS_PROXY"
Stewart Smith098d03e2016-03-01 13:59:42 +110099 fi
100 if [[ -n "$http_proxy" ]]; then
Stewart Smith915cea12018-01-16 16:07:49 +1100101 if [[ "$distro" == fedora27 ]]; then
Stewart Smith098d03e2016-03-01 13:59:42 +1100102 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
103 fi
Stewart Smith915cea12018-01-16 16:07:49 +1100104 if [[ "$distro" == ubuntu1604 ]]; then
Stewart Smith098d03e2016-03-01 13:59:42 +1100105 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
106 fi
107 fi
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +1000108 if [[ -n "DL_DIR" ]]; then
109 DL_DIR_ENV="ENV DL_DIR $DL_DIR"
110 fi
111 if [[ -n "CCACHE_DIR" ]]; then
112 CCACHE_DIR_ENV="ENV CCACHE_DIR $CCACHE_DIR"
113 fi
Stewart Smith098d03e2016-03-01 13:59:42 +1100114
115 Dockerfile=$(head -n1 $base_dockerfile; echo ${PROXY}; tail -n +2 $base_dockerfile; cat << EOF
Stewart Smith098d03e2016-03-01 13:59:42 +1100116${PROXY}
Stewart Smith915cea12018-01-16 16:07:49 +1100117RUN useradd -d ${HOME} -m -u ${UID} ${USER}
Stewart Smith098d03e2016-03-01 13:59:42 +1100118ENV HOME ${HOME}
Stewart Smith915cea12018-01-16 16:07:49 +1100119${HTTP_PROXY_ENV}
120${HTTPS_PROXY_ENV}
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +1000121${DL_DIR_ENV}
122${CCACHE_DIR_ENV}
Stewart Smith098d03e2016-03-01 13:59:42 +1100123EOF
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000124 )
Samuel Mendoza-Jonas86f9bb82018-08-06 12:51:59 +1000125 $DOCKER_PREFIX docker build --network=host -t openpower/op-build-$distro - <<< "${Dockerfile}"
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000126 if [ -d "$SDK_CACHE" ]; then
127 SDK_DIR=$SDK_CACHE/$(toolchain_hash)-$distro
128 if [ ! -d "$SDK_DIR" ]; then
129 chmod +x ci/build-sdk.sh
130 run_docker openpower/op-build-$distro "./ci/build-sdk.sh $distro witherspoon_defconfig"
131 mv output-$distro-witherspoon_defconfig $SDK_DIR
132 $SDK_DIR/host/relocate-sdk.sh
133 fi
134 sdk_args="-s $SDK_DIR/host"
Stewart Smith098d03e2016-03-01 13:59:42 +1100135 else
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000136 sdk_args=""
137 fi
138
139 if [ $SDK_ONLY == 0 ]; then
140 run_docker openpower/op-build-$distro "./ci/build-all-defconfigs.sh -o `pwd`/output-$distro -p $PLATFORMS ${release_args} ${sdk_args}"
141 fi
142
143 if [ $? != 0 ]; then
Stewart Smith098d03e2016-03-01 13:59:42 +1100144 exit $?;
145 fi
146done;
147