blob: c21bc223c05224ced3a446f91c55001484b1e33b [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
24sudo apt-get -y -qq install --no-install-recommends dpkg-dev
25
Paul Sokolovsky8364b0d2022-11-11 12:35:21 +030026if ! type aws
27then
28 sudo apt-get -y -qq update
29 sudo apt-get -y -qq install --no-install-recommends unzip
30 curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
31 unzip awscliv2.zip
32 sudo ./aws/install
33fi
34
Paul Sokolovskydedc4832022-01-17 23:26:30 +030035rm -f ${WORKSPACE}/log
36cd dockerfiles/
37
Paul Sokolovsky8364b0d2022-11-11 12:35:21 +030038aws configure list
Paul Sokolovsky1080e1d2022-11-11 20:49:12 +030039aws s3 cp --recursive s3://trustedfirmware-private/armclang/ .
Paul Sokolovsky2eae0672022-11-11 18:17:38 +030040find .
Paul Sokolovsky8364b0d2022-11-11 12:35:21 +030041
Paul Sokolovskyd63cfd92022-11-11 21:32:06 +030042df -h
43
Paul Sokolovskydedc4832022-01-17 23:26:30 +030044git_previous_commit=$(git rev-parse HEAD~1)
45git_commit=$(git rev-parse HEAD)
46files=$(git diff --name-only ${git_previous_commit} ${git_commit})
47echo Changes in: ${files}
48changed_dirs=$(dirname ${files}|sort -u)
49
50update_images=""
51for dir in ${changed_dirs}; do
52 # Find the closest directory with build.sh. This is, primarily,
53 # to handle changes to tcwg-base/tcwg-build/tcwg-builslave/* directories.
54 while [ ! -e ${dir}/build.sh -a ! -e ${dir}/.git ]; do
55 dir=$(dirname ${dir})
56 done
57 # Add this and all dependant images in the update.
58 dir_basename=$(basename ${dir})
59 case "${dir_basename}" in
60 "tcwg-"*)
61 # ${dir} is one of generic tcwg-base/* directories. Add dependent
62 # images to the list.
63 update_images="${update_images} $(dirname $(find . -path "*-${dir_basename}*/build.sh" | sed -e "s#^\./##g"))"
64 ;;
65 ".")
66 continue
67 ;;
68 *)
69 update_images="${update_images} $(dirname $(find ${dir} -name build.sh))"
70 ;;
71 esac
72done
73update_images="$(echo "${update_images}" | tr " " "\n" | sort -u)"
74
75host_arch=$(dpkg-architecture -qDEB_HOST_ARCH)
76
77for image in ${update_images}; do
78 (
79 cd ${image}
80 image_arch=$(basename ${PWD} | cut -f2 -d '-')
81 skip="skip"
82 if [ -f gerrit-branches ]; then
83 # Build only from branches mentioned in gerrit-branches
84 if grep -q "^${GERRIT_BRANCH}\$" gerrit-branches; then
85 skip="no"
86 fi
87 elif [ x"${GERRIT_BRANCH}" = x"master" ]; then
88 # No gerrit-branch file, so build only from "master" branch.
89 skip="no"
90 fi
91 case "${skip}:${host_arch}:${image_arch}" in
92 "skip:"*)
93 echo "Skipping: don't need to build ${image} on branch ${GERRIT_BRANCH}"
94 ;;
95 "no:amd64:amd64"|"no:amd64:i386"|"no:arm64:arm64"|"no:armhf:armhf")
96 echo "=== Start build: ${image} ==="
97 bash -x ./build.sh || echo "=== FAIL: ${image} ===" >> ${WORKSPACE}/log
98 ;;
99 *)
100 echo "Skipping: can't build for ${image_arch} on ${host_arch}"
101 ;;
102 esac
103 )||echo $image failed >> ${WORKSPACE}/log
104done
105