blob: e9f0fdde542822637618f338744b2442d6e47a93 [file] [log] [blame]
Benjamin Copelandc78807d2019-04-02 08:54:42 +01001#!/bin/bash
2
3set -ex
4
Paul Sokolovskyd7a2ea72022-11-15 17:57:56 +03005docker --version
6
Benjamin Copelandc78807d2019-04-02 08:54:42 +01007echo ""
8echo "########################################################################"
9echo " Gerrit Environment"
10env |grep '^GERRIT'
11echo "########################################################################"
12
Paul Sokolovsky73acc7f2022-11-15 14:26:20 +030013ON_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
24
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030025# For dpkg-architecture call below
Paul Sokolovsky09455562022-11-12 11:35:36 +030026if ! type dpkg-architecture
27then
28 sudo apt-get -y -qq install --no-install-recommends dpkg-dev
Paul Sokolovsky429589e2022-11-12 11:43:14 +030029fi
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030030
31if ! 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 Sokolovsky0810ea22022-11-11 22:23:41 +030036 unzip -q awscliv2.zip
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030037 sudo ./aws/install
38fi
39
Riku Voipiob8ffb562020-10-12 11:44:40 +030040rm -f ${WORKSPACE}/log
Benjamin Copelandc78807d2019-04-02 08:54:42 +010041cd dockerfiles/
42
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030043aws configure list
44aws s3 cp --recursive s3://trustedfirmware-private/armclang/ .
45find .
46
47df -h
48
Benjamin Copelandc78807d2019-04-02 08:54:42 +010049git_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}
Riku Voipiob8ffb562020-10-12 11:44:40 +030053changed_dirs=$(dirname ${files}|sort -u)
Benjamin Copelandc78807d2019-04-02 08:54:42 +010054
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 ;;
Riku Voipiob8ffb562020-10-12 11:44:40 +030070 ".")
71 continue
72 ;;
Benjamin Copelandc78807d2019-04-02 08:54:42 +010073 *)
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} ==="
Paul Sokolovsky9c6dc902022-01-17 22:55:27 +0300102 bash -x ./build.sh || echo "=== FAIL: ${image} ===" >> ${WORKSPACE}/log
Benjamin Copelandc78807d2019-04-02 08:54:42 +0100103 ;;
104 *)
105 echo "Skipping: can't build for ${image_arch} on ${host_arch}"
106 ;;
107 esac
Benjamin Copelandc78807d2019-04-02 08:54:42 +0100108 )||echo $image failed >> ${WORKSPACE}/log
109done
110