blob: 7ec5520a8c3a5ed753bd4117c107d68428886bce [file] [log] [blame]
#!/bin/bash
# Copyright 2020 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
VERSION="1.5.0"
SCRIPT=$(basename -- "${0}")
set -e
export LC_ALL=C
if [[ ! -e /etc/cros_chroot_version ]]; then
echo "This script must be run inside the chroot."
exit 1
fi
if [[ "$#" -lt 3 ]]; then
echo "Usage: ${SCRIPT} base_name reference_name variant_name [bug_number]"
echo "e.g. ${SCRIPT} hatch hatch kohaku b:140261109"
echo "e.g. ${SCRIPT} zork trembyle frobozz b:148161697"
echo "Copies the cras config from the reference board to the new variant"
exit 1
fi
# shellcheck source=revbump_ebuild.sh
# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/revbump_ebuild.sh"
# shellcheck source=check_standalone.sh
# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/check_standalone.sh"
check_standalone
# shellcheck source=check_pending_changes.sh
# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/check_pending_changes.sh"
# This is the name of the base board.
# ${var,,} converts to all lowercase.
BASE="${1,,}"
# This is the name of the reference board that we're using to make the variant.
# ${var,,} converts to all lowercase.
REFERENCE="${2,,}"
# This is the name of the variant that is being cloned.
VARIANT="${3,,}"
# Assign BUG= text, or "None" if that parameter wasn't specified.
BUG=${4:-None}
CHROMEOS_BSP_DIR="${HOME}/trunk/src/overlays/overlay-${BASE}/chromeos-base/chromeos-bsp-${BASE}"
if [[ -d "${CHROMEOS_BSP_DIR}/files/cras-config" ]]; then
CRAS_DIR="files/cras-config"
elif [[ -d "${CHROMEOS_BSP_DIR}/files/${REFERENCE}/audio/cras-config" ]]; then
CRAS_DIR="files/${REFERENCE}/audio/cras-config"
else
echo "cras-config dir does not exists in overlay-${BASE}."
fi
cd "${CHROMEOS_BSP_DIR}"
# If there are pending changes, exit the script (unless overridden)
check_pending_changes "$(pwd)"
# Start a branch. Use YMD timestamp to avoid collisions.
DATE=$(date +%Y%m%d)
BRANCH="create_${VARIANT}_${DATE}"
repo start "${BRANCH}" . "${NEW_VARIANT_WIP:+--head}"
# ${parameter:+word}" substitutes "word" if $parameter is set to a non-null
# value, or substitutes null if $parameter is null or unset.
cleanup() {
# If there is an error after the `repo start`, then restore modified files
# to clean up and `repo abandon` the new branch.
cd "${CHROMEOS_BSP_DIR}"
git restore --staged "*.ebuild"
git restore "*.ebuild"
if [[ ! -z "${NEWEBUILD}" ]] ; then
rm -f "${NEWEBUILD}"
fi
cd "${CRAS_DIR}"
if [[ -e "${VARIANT}" ]] ; then
rm -Rf "${VARIANT}"
# Use || true so that if the new files haven't been added yet, the error
# won't terminate the script before we can finish cleaning up.
git restore --staged "${VARIANT}" || true
fi
repo abandon "${BRANCH}" .
}
trap 'cleanup' ERR
# ebuild will be located in CHROMEOS_BSP_DIR.
revbump_ebuild
if [[ $CRAS_DIR == "files/cras-config" ]]; then
cd "files/cras-config"
else
cd "files/"
fi
mkdir "${VARIANT}"
cp -r "${REFERENCE}"/* "${VARIANT}"
git add "${VARIANT}"
git commit -m "${BASE}: Add ${VARIANT} cras config
Create a new cras config for the ${VARIANT} variant as a
copy of the ${REFERENCE} reference board's cras config.
(Auto-Generated by ${SCRIPT} version ${VERSION}).
BUG=${BUG}
TEST=N/A"