#!/bin/bash -xe
#
# Purpose:
#  This script is responsible for building all CI machines to get a
#  new CI systems sstate and download caches setup.
#
# This script assumes openbmc-build-scripts has been cloned into
# the WORKSPACE directory.
#
# Required Inputs:
#  WORKSPACE:      Directory to run the builds out of

export LANG=en_US.UTF8

cd "${WORKSPACE}"
if [ -d openbmc ]; then
    git -C openbmc fetch
    git -C openbmc rebase
else
    git clone https://github.com/openbmc/openbmc.git
fi

# Ensure everything is built on same filesystem
export build_dir="${WORKSPACE}/build"

SEED_MACHINES=(
    bletchley
    catalina
    e3c246d4i
    evb-npcm845
    gb200nvl-obmc
    gbs
    harma
    minerva
    p10bmc
    romulus
    ventura
    witherspoon
    yosemite4
)

for m in "${SEED_MACHINES[@]}"; do
    echo "Seeding $m"
    export target=$m
    "${WORKSPACE}/openbmc-build-scripts/build-setup.sh" || \
        echo "Build failed for $m; continuing."
    rm -rf "${WORKSPACE}/openbmc/build"
    rm -rf "${build_dir}"
done
