blob: 3e6783925e6c099c262d2d80c623f9c0dd2cc2c4 [file] [log] [blame]
Benjamin Copelandc78807d2019-04-02 08:54:42 +01001#!/bin/bash
2
3set -ex
4
Benjamin Copelandc78807d2019-04-02 08:54:42 +01005echo ""
6echo "########################################################################"
7echo " Gerrit Environment"
8env |grep '^GERRIT'
9echo "########################################################################"
10
Paul Sokolovsky73acc7f2022-11-15 14:26:20 +030011ON_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
22
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030023# For dpkg-architecture call below
Paul Sokolovsky09455562022-11-12 11:35:36 +030024if ! type dpkg-architecture
25then
26 sudo apt-get -y -qq install --no-install-recommends dpkg-dev
Paul Sokolovsky429589e2022-11-12 11:43:14 +030027fi
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030028
29if ! 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 Sokolovsky0810ea22022-11-11 22:23:41 +030034 unzip -q awscliv2.zip
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030035 sudo ./aws/install
36fi
37
Riku Voipiob8ffb562020-10-12 11:44:40 +030038rm -f ${WORKSPACE}/log
Benjamin Copelandc78807d2019-04-02 08:54:42 +010039cd dockerfiles/
40
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030041aws configure list
42aws s3 cp --recursive s3://trustedfirmware-private/armclang/ .
43find .
44
45df -h
46
Benjamin Copelandc78807d2019-04-02 08:54:42 +010047git_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}
Riku Voipiob8ffb562020-10-12 11:44:40 +030051changed_dirs=$(dirname ${files}|sort -u)
Benjamin Copelandc78807d2019-04-02 08:54:42 +010052
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 ;;
Riku Voipiob8ffb562020-10-12 11:44:40 +030068 ".")
69 continue
70 ;;
Benjamin Copelandc78807d2019-04-02 08:54:42 +010071 *)
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} ==="
Paul Sokolovsky9c6dc902022-01-17 22:55:27 +0300100 bash -x ./build.sh || echo "=== FAIL: ${image} ===" >> ${WORKSPACE}/log
Benjamin Copelandc78807d2019-04-02 08:54:42 +0100101 ;;
102 *)
103 echo "Skipping: can't build for ${image_arch} on ${host_arch}"
104 ;;
105 esac
Benjamin Copelandc78807d2019-04-02 08:54:42 +0100106 )||echo $image failed >> ${WORKSPACE}/log
107done
108