Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 3 | CONTAINERS="ubuntu1604 fedora27" |
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." |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 40 | echo "-s DIR SDK cache dir." |
| 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" |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 43 | 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-Jonas | 8d102aa | 2018-08-10 13:47:48 +1000 | [diff] [blame] | 48 | r) |
| 49 | echo "Build for release" |
| 50 | release_args="-r" |
| 51 | ;; |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 52 | \?) |
| 53 | echo "Invalid option: -$OPTARG" |
| 54 | exit 1 |
| 55 | ;; |
| 56 | :) |
| 57 | echo "Option -$OPTARG requires an argument." |
| 58 | exit 1 |
| 59 | ;; |
| 60 | esac |
| 61 | done |
| 62 | |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 63 | set -ex |
| 64 | set -eo pipefail |
| 65 | |
| 66 | function run_docker |
| 67 | { |
Samuel Mendoza-Jonas | ae0d13e | 2018-08-06 15:16:32 +1000 | [diff] [blame] | 68 | 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 Smith | 9c20ae2 | 2018-10-29 15:24:50 +1100 | [diff] [blame^] | 73 | $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] | 74 | --user="${USER}" -w "${PWD}" "${BINDARG}" \ |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 75 | -t $1 $2 |
| 76 | } |
| 77 | |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 78 | function toolchain_hash |
| 79 | { |
| 80 | echo -n 'toolchain-'$((git submodule ; cd openpower/configs/; cat `ls -1 |grep '_defconfig$'|sort`)|sha1sum |sed -e 's/ .*//') |
| 81 | } |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 82 | |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 83 | env |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 84 | |
Stewart Smith | 6650dd4 | 2017-02-16 14:41:10 +1100 | [diff] [blame] | 85 | for distro in $CONTAINERS; |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 86 | do |
Samuel Mendoza-Jonas | 7972250 | 2018-07-25 14:59:07 +1000 | [diff] [blame] | 87 | base_dockerfile=ci/Dockerfile/$distro.`uname -m` |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 88 | if [ ! -f $base_dockerfile ]; then |
Samuel Mendoza-Jonas | 7972250 | 2018-07-25 14:59:07 +1000 | [diff] [blame] | 89 | echo "$distro not supported on $(uname -m)."; |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 90 | continue |
| 91 | fi |
| 92 | if [[ -n "$HTTP_PROXY" ]]; then |
| 93 | http_proxy=$HTTP_PROXY |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 94 | 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 Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 99 | fi |
| 100 | if [[ -n "$http_proxy" ]]; then |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 101 | if [[ "$distro" == fedora27 ]]; then |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 102 | PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf" |
| 103 | fi |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 104 | if [[ "$distro" == ubuntu1604 ]]; then |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 105 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
| 106 | fi |
| 107 | fi |
Samuel Mendoza-Jonas | 94ec86a | 2018-08-06 15:18:26 +1000 | [diff] [blame] | 108 | 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 Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 114 | |
| 115 | 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] | 116 | ${PROXY} |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 117 | RUN useradd -d ${HOME} -m -u ${UID} ${USER} |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 118 | ENV HOME ${HOME} |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 119 | ${HTTP_PROXY_ENV} |
| 120 | ${HTTPS_PROXY_ENV} |
Samuel Mendoza-Jonas | 94ec86a | 2018-08-06 15:18:26 +1000 | [diff] [blame] | 121 | ${DL_DIR_ENV} |
| 122 | ${CCACHE_DIR_ENV} |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 123 | EOF |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 124 | ) |
Samuel Mendoza-Jonas | 86f9bb8 | 2018-08-06 12:51:59 +1000 | [diff] [blame] | 125 | $DOCKER_PREFIX docker build --network=host -t openpower/op-build-$distro - <<< "${Dockerfile}" |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 126 | 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 Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 135 | else |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 136 | 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 Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 144 | exit $?; |
| 145 | fi |
| 146 | done; |
| 147 | |