blob: b91636c2faf55768e22c1784e8193878d337c20f [file] [log] [blame]
#!/bin/bash
# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
VERSION="1.3.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 2 ]]; then
echo "Usage: ${SCRIPT} base_name variant_name [trunk_path] [bug_number]"
echo "e.g. ${SCRIPT} puff wyvern chromiumos b:158269582"
echo "Updates the config.star to add a default _FW_BUILD_CONFIG"
echo "trunk_path is an optional parameter, script uses 'chromiumos' as default path"
exit 1
fi
# 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 variant that we are enabling _FW_BUILD_CONFIG for.
VARIANT="${2,,}"
# We need all uppercase version, too, so ${var^^}
VARIANT_UPPER="${VARIANT^^}"
# This is the trunk path. Default path is "chromiumos" in case not specified
TRUNK=${3:-"chromiumos"}
# Assign BUG= text, or "None" if that parameter wasn't specified.
BUG="${4:-None}"
if ! hash gen_config 2>/dev/null; then
echo "gen_config is not on your PATH."
echo "Run the following before continuing:"
echo "echo 'export PATH=\$PATH:~/${TRUNK}/src/config/bin' >> ~/.bashrc && source ~/.bashrc"
exit 1
fi
# The config.star file will be located here
cd "${HOME}/${TRUNK}/src/project/${BASE}/${VARIANT}"
# 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}"
# Store current branch information to restore in case of failure
CURRENT_BRANCH=`git describe --all | cut -d '/' -f 2-3`
# Checkout new branch to work on.
# In case script has already been running, skip new branch creation.
if [ -z "${NEW_VARIANT_WIP}" ]; then
git checkout -b "${BRANCH}" -t "${CURRENT_BRANCH}"
fi
cleanup() {
# If there is an error after the `repo start`, then restore modified files
# to clean up. `git restore --staged` will remove files added to a commit,
# and `git restore` will restore the file to its unmodified state. Then
# `repo abandon` the new branch.
git restore --staged config.star
git restore config.star
git restore --staged generated/config.jsonproto
git restore generated/config.jsonproto
git restore --staged sw_build_config/platform/chromeos-config/generated/project-config.json
git restore sw_build_config/platform/chromeos-config/generated/project-config.json
git checkout "${CURRENT_BRANCH}"
git branch -D "${BRANCH}"
}
trap 'cleanup "${BRANCH}"' ERR
# Change the _FW_BUILD_CONFIG from None to _${VARIANT_UPPER}.
sed -i -e "s/_FW_BUILD_CONFIG = None/_FW_BUILD_CONFIG = program.firmware_build_config(_${VARIANT_UPPER})/" config.star
# Regenerate the config.
./config.star
# Add modified files.
git add config.star
git add generated/config.jsonproto
git add sw_build_config/platform/chromeos-config/generated/project-config.json
# Now commit the files.
git commit -m "${VARIANT}: enable default firmware build
Add a default _FW_BUILD_CONFIG.
(Auto-Generated by ${SCRIPT} version ${VERSION}).
BUG=${BUG}
TEST=Verify the ${VARIANT} firmware builds"