blob: 0f90d1ff9ac54ec5393af4db4602a99ae5279214 [file] [log] [blame]
# 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.
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
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
# shellcheck
# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/"
# shellcheck
# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/"
# This is the name of the base board.
# ${var,,} converts to all lowercase.
# This is the name of the reference board that we're using to make the variant.
# ${var,,} converts to all lowercase.
# This is the name of the variant that is being cloned.
# Assign BUG= text, or "None" if that parameter wasn't specified.
cd "${HOME}/trunk/src/overlays/overlay-${BASE}/chromeos-base/chromeos-bsp-${BASE}/files/cras-config"
# Start a branch. Use YMD timestamp to avoid collisions.
DATE=$(date +%Y%m%d)
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 "${HOME}/trunk/src/overlays/overlay-${BASE}/chromeos-base/chromeos-bsp-${BASE}"
git restore --staged "*.ebuild"
git restore "*.ebuild"
if [[ ! -z "${NEWEBUILD}" ]] ; then
rm -f "${NEWEBUILD}"
cd "files/cras-config"
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
repo abandon "${BRANCH}" .
trap 'cleanup' ERR
# ebuild will be located 2 directories up.
pushd ../..
mkdir "${VARIANT}"
cp "${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}).
check_standalone "$(pwd)" "${BRANCH}"