blob: ff4bd7e05560a8f52aad27cb4642fb4f7c654322 [file] [log] [blame]
#!/usr/bin/env 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.
# Used to generate program and project configuration. Expects to be able
# to find the protocol buffer generating script in the directory with the
# config file at config/generate.sh and expects to be able to find the
# lucicfg binary on the path from depot_tools.
# Exit if any command fails.
set -e
function usage() {
echo "Usage: $0 <config_file>" >&2
echo " where <config_file> is a program's or project's main" >&2
echo " configuration file, typically config.star" >&2
exit 1
}
if [[ $# -ne 1 ]]; then
usage
fi
readonly script_dir="$(dirname "$(realpath -e "${BASH_SOURCE[0]}")")"
source "${script_dir}/../setup_cipd.sh"
readonly file_path="${1}"
readonly config_file=$(basename "${file_path}")
readonly config_dir="$(dirname "$(realpath -e "${file_path}")")"
# Hitting some relative links so change to the directory.
cd "${config_dir}"
if ! config/generate.sh; then
echo 'blew up generating proto descriptors'
exit 1
fi
echo "Formatting .star files with buildifier..."
find "${config_dir}" -name "*.star" -exec buildifier {} \;
lucicfg generate "${config_file}"
# Create and activate venv.
/usr/bin/python3 -m venv .venv
source .venv/bin/activate
# Install requirements.
pip install wheel -q
pip install -r config/requirements.txt -q
# TODO(crbug.com/1073530): Ideally lucicfg's to_jsonpb could handle writing
# JSON PB with enums serialized as ints. For now we do it with a python
# helper. Note that we overwrite the input file so only the converted result
# remains.
config/payload_utils/convert_config_enums.py \
--input_config='generated/config.jsonproto' \
--output_config='generated/config.jsonproto'
# If we don't see the program symlink in the cwd, then
# we are not a project and we are done.
[[ ! -L program ]] && exit
# If we did see the program symlink in the cwd, then
# we are a project and we continue with generation of
# platform json.
rm -rf sw_build_config/platform/chromeos-config/generated
mkdir -p sw_build_config/platform/chromeos-config/generated
python3 config/payload_utils/cros_config_proto_converter.py \
--output sw_build_config/platform/chromeos-config/generated/project-config.json \
--program_config program/generated/config.jsonproto \
--project_configs generated/config.jsonproto
rm -rf factory/generated
mkdir -p factory/generated
python3 config/payload_utils/factory_config_proto_converter.py \
--output factory/generated/model_sku.json \
--program_config program/generated/config.jsonproto \
--project_configs generated/config.jsonproto
deactivate