blob: e9f0fdde542822637618f338744b2442d6e47a93 [file] [log] [blame]
Paul Sokolovskydedc4832022-01-17 23:26:30 +03001#!/bin/bash
2
3set -ex
4
Paul Sokolovsky0685e502022-11-15 17:59:55 +03005docker --version
6
Paul Sokolovskydedc4832022-01-17 23:26:30 +03007echo ""
8echo "########################################################################"
9echo " Gerrit Environment"
10env |grep '^GERRIT'
11echo "########################################################################"
Paul Sokolovsky5da4ab22022-11-15 13:53:27 +030012
13ON_EC2="0"
14if [ -f /sys/hypervisor/uuid ] && grep -q ^ec2 /sys/hypervisor/uuid; then
15 ON_EC2="1"
16fi
17
18if [ "${ON_EC2}" == "1" ]; then
19 # On EC2 instances, stop and remove unattended-upgrades service which
20 # may interfere with any apt operations below.
21 sudo systemctl stop unattended-upgrades
22 sudo apt-get remove -y -qq unattended-upgrades
23fi
Paul Sokolovskydedc4832022-01-17 23:26:30 +030024
Paul Sokolovskyccdd8542022-11-11 17:53:32 +030025# For dpkg-architecture call below
Paul Sokolovskyd3245052022-11-15 15:40:38 +030026if ! type dpkg-architecture
27then
28 sudo apt-get -y -qq install --no-install-recommends dpkg-dev
29fi
Paul Sokolovskyccdd8542022-11-11 17:53:32 +030030
Paul Sokolovsky8364b0d2022-11-11 12:35:21 +030031if ! type aws
32then
33 sudo apt-get -y -qq update
34 sudo apt-get -y -qq install --no-install-recommends unzip
35 curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
Paul Sokolovskyd3245052022-11-15 15:40:38 +030036 unzip -q awscliv2.zip
Paul Sokolovsky8364b0d2022-11-11 12:35:21 +030037 sudo ./aws/install
38fi
39
Paul Sokolovskydedc4832022-01-17 23:26:30 +030040rm -f ${WORKSPACE}/log
41cd dockerfiles/
42
Paul Sokolovsky8364b0d2022-11-11 12:35:21 +030043aws configure list
Paul Sokolovsky1080e1d2022-11-11 20:49:12 +030044aws s3 cp --recursive s3://trustedfirmware-private/armclang/ .
Paul Sokolovsky2eae0672022-11-11 18:17:38 +030045find .
Paul Sokolovsky8364b0d2022-11-11 12:35:21 +030046
Paul Sokolovskyd63cfd92022-11-11 21:32:06 +030047df -h
48
Paul Sokolovskydedc4832022-01-17 23:26:30 +030049git_previous_commit=$(git rev-parse HEAD~1)
50git_commit=$(git rev-parse HEAD)
51files=$(git diff --name-only ${git_previous_commit} ${git_commit})
52echo Changes in: ${files}
53changed_dirs=$(dirname ${files}|sort -u)
54
55update_images=""
56for dir in ${changed_dirs}; do
57 # Find the closest directory with build.sh. This is, primarily,
58 # to handle changes to tcwg-base/tcwg-build/tcwg-builslave/* directories.
59 while [ ! -e ${dir}/build.sh -a ! -e ${dir}/.git ]; do
60 dir=$(dirname ${dir})
61 done
62 # Add this and all dependant images in the update.
63 dir_basename=$(basename ${dir})
64 case "${dir_basename}" in
65 "tcwg-"*)
66 # ${dir} is one of generic tcwg-base/* directories. Add dependent
67 # images to the list.
68 update_images="${update_images} $(dirname $(find . -path "*-${dir_basename}*/build.sh" | sed -e "s#^\./##g"))"
69 ;;
70 ".")
71 continue
72 ;;
73 *)
74 update_images="${update_images} $(dirname $(find ${dir} -name build.sh))"
75 ;;
76 esac
77done
78update_images="$(echo "${update_images}" | tr " " "\n" | sort -u)"
79
80host_arch=$(dpkg-architecture -qDEB_HOST_ARCH)
81
82for image in ${update_images}; do
83 (
84 cd ${image}
85 image_arch=$(basename ${PWD} | cut -f2 -d '-')
86 skip="skip"
87 if [ -f gerrit-branches ]; then
88 # Build only from branches mentioned in gerrit-branches
89 if grep -q "^${GERRIT_BRANCH}\$" gerrit-branches; then
90 skip="no"
91 fi
92 elif [ x"${GERRIT_BRANCH}" = x"master" ]; then
93 # No gerrit-branch file, so build only from "master" branch.
94 skip="no"
95 fi
96 case "${skip}:${host_arch}:${image_arch}" in
97 "skip:"*)
98 echo "Skipping: don't need to build ${image} on branch ${GERRIT_BRANCH}"
99 ;;
100 "no:amd64:amd64"|"no:amd64:i386"|"no:arm64:arm64"|"no:armhf:armhf")
101 echo "=== Start build: ${image} ==="
102 bash -x ./build.sh || echo "=== FAIL: ${image} ===" >> ${WORKSPACE}/log
103 ;;
104 *)
105 echo "Skipping: can't build for ${image_arch} on ${host_arch}"
106 ;;
107 esac
108 )||echo $image failed >> ${WORKSPACE}/log
109done
110