Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Stewart Smith | 45af3fc | 2019-07-23 15:45:10 +1000 | [diff] [blame] | 3 | CONTAINERS="ubuntu1804 fedora30" |
Stewart Smith | 6650dd4 | 2017-02-16 14:41:10 +1100 | [diff] [blame] | 4 | |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 5 | |
| 6 | SDK_ONLY=0 |
| 7 | |
| 8 | while getopts ":ab:hp:c:rs:S" opt; do |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 9 | case $opt in |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 10 | s) |
| 11 | echo "SDK Cache dir" |
| 12 | SDK_CACHE="$OPTARG" |
| 13 | ;; |
| 14 | S) |
| 15 | echo "Build SDK Only" |
| 16 | SDK_ONLY=1 |
| 17 | ;; |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 18 | a) |
| 19 | echo "Build firmware images for all the platforms" |
| 20 | PLATFORMS="" |
| 21 | ;; |
Samuel Mendoza-Jonas | ae0d13e | 2018-08-06 15:16:32 +1000 | [diff] [blame] | 22 | b) |
| 23 | echo "Directory to bind to container: $OPTARG" |
| 24 | BIND="$OPTARG" |
| 25 | ;; |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 26 | p) |
| 27 | echo "Build firmware images for the platforms: $OPTARG" |
| 28 | PLATFORMS=$OPTARG |
| 29 | ;; |
Stewart Smith | 6650dd4 | 2017-02-16 14:41:10 +1100 | [diff] [blame] | 30 | c) |
| 31 | echo "Build in container: $OPTARG" |
| 32 | CONTAINERS=$OPTARG |
| 33 | ;; |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 34 | 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-Jonas | ae0d13e | 2018-08-06 15:16:32 +1000 | [diff] [blame] | 38 | echo "-b DIR Bind DIR to container." |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 39 | echo "-p List of comma separated platform names to build images for particular platforms." |
Joel Stanley | 4c94b9e | 2018-11-01 13:20:03 +1030 | [diff] [blame] | 40 | echo "-s DIR SDK cache dir (must exist)." |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 41 | echo "-S Build SDK only" |
Stewart Smith | 6650dd4 | 2017-02-16 14:41:10 +1100 | [diff] [blame] | 42 | echo "-c Container to run in" |
Joel Stanley | 3226cf3 | 2018-11-01 13:20:08 +1030 | [diff] [blame] | 43 | echo "" |
| 44 | echo "Note: set environment variables HTTP_PROXY and HTTPS_PROXY if a proxy is required." |
| 45 | echo "" |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 46 | echo "Example:DOCKER_PREFIX=sudo ./ci/build.sh -a" |
| 47 | echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p firestone" |
Joel Stanley | 33ed8f1 | 2019-04-03 12:13:43 +1030 | [diff] [blame] | 48 | echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p garrison,palmetto,opal" |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 49 | exit 1 |
| 50 | ;; |
Samuel Mendoza-Jonas | 8d102aa | 2018-08-10 13:47:48 +1000 | [diff] [blame] | 51 | r) |
| 52 | echo "Build for release" |
| 53 | release_args="-r" |
| 54 | ;; |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 55 | \?) |
| 56 | echo "Invalid option: -$OPTARG" |
| 57 | exit 1 |
| 58 | ;; |
| 59 | :) |
| 60 | echo "Option -$OPTARG requires an argument." |
| 61 | exit 1 |
| 62 | ;; |
| 63 | esac |
| 64 | done |
| 65 | |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 66 | set -ex |
| 67 | set -eo pipefail |
| 68 | |
| 69 | function run_docker |
| 70 | { |
Samuel Mendoza-Jonas | ae0d13e | 2018-08-06 15:16:32 +1000 | [diff] [blame] | 71 | 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 Smith | 9c20ae2 | 2018-10-29 15:24:50 +1100 | [diff] [blame] | 76 | $DOCKER_PREFIX docker run --init --cap-add=sys_admin --net=host --rm=true \ |
Samuel Mendoza-Jonas | ae0d13e | 2018-08-06 15:16:32 +1000 | [diff] [blame] | 77 | --user="${USER}" -w "${PWD}" "${BINDARG}" \ |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 78 | -t $1 $2 |
| 79 | } |
| 80 | |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 81 | function toolchain_hash |
| 82 | { |
| 83 | echo -n 'toolchain-'$((git submodule ; cd openpower/configs/; cat `ls -1 |grep '_defconfig$'|sort`)|sha1sum |sed -e 's/ .*//') |
| 84 | } |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 85 | |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 86 | env |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 87 | |
Stewart Smith | 6650dd4 | 2017-02-16 14:41:10 +1100 | [diff] [blame] | 88 | for distro in $CONTAINERS; |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 89 | do |
Samuel Mendoza-Jonas | 7972250 | 2018-07-25 14:59:07 +1000 | [diff] [blame] | 90 | base_dockerfile=ci/Dockerfile/$distro.`uname -m` |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 91 | if [ ! -f $base_dockerfile ]; then |
Samuel Mendoza-Jonas | 7972250 | 2018-07-25 14:59:07 +1000 | [diff] [blame] | 92 | echo "$distro not supported on $(uname -m)."; |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 93 | continue |
| 94 | fi |
| 95 | if [[ -n "$HTTP_PROXY" ]]; then |
| 96 | http_proxy=$HTTP_PROXY |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 97 | 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 Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 102 | fi |
| 103 | if [[ -n "$http_proxy" ]]; then |
Stewart Smith | 45af3fc | 2019-07-23 15:45:10 +1000 | [diff] [blame] | 104 | if [[ "$distro" == fedora30 ]]; then |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 105 | PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf" |
| 106 | fi |
Stewart Smith | 26b9f99 | 2019-03-27 14:46:49 +1100 | [diff] [blame] | 107 | if [[ "$distro" == ubuntu1804 ]]; then |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 108 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
| 109 | fi |
| 110 | fi |
Joel Stanley | ce8ae8d | 2018-11-01 13:19:50 +1030 | [diff] [blame] | 111 | if [ ! -z ${DL_DIR+x} ]; then |
Samuel Mendoza-Jonas | 94ec86a | 2018-08-06 15:18:26 +1000 | [diff] [blame] | 112 | DL_DIR_ENV="ENV DL_DIR $DL_DIR" |
| 113 | fi |
Joel Stanley | ce8ae8d | 2018-11-01 13:19:50 +1030 | [diff] [blame] | 114 | if [ ! -z ${CCACHE_DIR+x} ]; then |
Samuel Mendoza-Jonas | 94ec86a | 2018-08-06 15:18:26 +1000 | [diff] [blame] | 115 | CCACHE_DIR_ENV="ENV CCACHE_DIR $CCACHE_DIR" |
| 116 | fi |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 117 | |
| 118 | Dockerfile=$(head -n1 $base_dockerfile; echo ${PROXY}; tail -n +2 $base_dockerfile; cat << EOF |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 119 | ${PROXY} |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 120 | RUN useradd -d ${HOME} -m -u ${UID} ${USER} |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 121 | ENV HOME ${HOME} |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 122 | ${HTTP_PROXY_ENV} |
| 123 | ${HTTPS_PROXY_ENV} |
Samuel Mendoza-Jonas | 94ec86a | 2018-08-06 15:18:26 +1000 | [diff] [blame] | 124 | ${DL_DIR_ENV} |
| 125 | ${CCACHE_DIR_ENV} |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 126 | EOF |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 127 | ) |
Samuel Mendoza-Jonas | 86f9bb8 | 2018-08-06 12:51:59 +1000 | [diff] [blame] | 128 | $DOCKER_PREFIX docker build --network=host -t openpower/op-build-$distro - <<< "${Dockerfile}" |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 129 | 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 Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 138 | else |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 139 | 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 Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 147 | exit $?; |
| 148 | fi |
| 149 | done; |
| 150 | |