blob: 3b576317cfe2baeece1afcd7408e0a7840cbd3e6 [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 2 ]]; then
echo "Usage: ${SCRIPT} base_name variant_name [bug_number]"
echo "e.g. ${SCRIPT} hatch kohaku b:140261109"
echo "Adds a new device and unprovisioned SKU to the YAML file for"
echo "the variant being created. Revbump the ebuild."
exit 1
# shellcheck
# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/"
# shellcheck
# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/"
# shellcheck
# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/"
# This is the name of the base 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.
# ${var^} capitalizes first letter only.
# We need all uppercase version, too, so ${var^^}
# Assign BUG= text, or "None" if that parameter wasn't specified.
cd "${HOME}/trunk/src/overlays/overlay-${BASE}/chromeos-base/chromeos-config-bsp/files"
if [[ ! -e "${YAML}" ]]; then
echo "${YAML} does not exist."
exit 1
# Make sure the variant doesn't already exist in the yaml file.
if grep -qi "${VARIANT}" "${YAML}" ; then
echo "${VARIANT} already appears to exist in ${YAML}"
echo "Have you already created this variant?"
exit 1
# 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)
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-config-bsp"
git restore --staged "*.ebuild"
git restore "*.ebuild"
if [[ ! -z "${NEWEBUILD}" ]] ; then
rm -f "${NEWEBUILD}"
cd files
git restore --staged "${YAML}"
git restore "${YAML}"
repo abandon "${BRANCH}" .
trap 'cleanup' ERR
# ebuild is located 1 directory up.
pushd ..
# Append a new device-name to the end of the model.yaml file.
cat <<EOF >>"${YAML}"
- \$device-name: "unprovisioned_${VARIANT}"
- \$key-id: "${BASE_UPPER}"
- \$sku-id: 255
config: *base_config
git add "${YAML}"
# Building the config.json and other files from the yaml requires that the
# changes have been made to both the public and private yaml files, which
# we can't guarantee here, so we will not automate the steps in the TEST=
# part of the commit message below. The high-level program which calls this
# script and others will be responsible for testing the emerge command and
# verifying that the new variant shows up in the output.
# Now commit the files.
git commit -m "model.yaml: Add ${VARIANT} variant
Add a new section to the yaml file to define the ${VARIANT}
variant of the ${BASE} baseboard.
(Auto-Generated by ${SCRIPT} version ${VERSION}).
TEST=emerge-${BASE} chromeos-config-bsp-hatch
chromeos-config-bsp-private chromeos-config-bsp chromeos-config
Check /build/${BASE}/usr/share/chromeos-config for '${VARIANT}' in
config.json, yaml/config.c, and yaml/*.yaml"