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