1#!/usr/bin/env bash 2# 3# Copyright 2020 The ChromiumOS Authors 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6 7# Applies transforms to the program/config jsonconfig payload and generates 8# configuration derivatives used by the build system. 9 10readonly script_dir="$(dirname "$(realpath -e "${BASH_SOURCE[0]}")")" 11 12# Exit if any command fails. 13set -e 14 15source "${script_dir}/../setup_cipd.sh" 16 17readonly output_dir=$1 18 19# Path to the generated config protobuf. 20readonly private_config_path_rel="generated/config.jsonproto" 21# Path to output the filtered public config protobuf to. 22readonly public_config_path_rel="generated/public_config.jsonproto" 23 24# Generated filtered public configs. Note that this should be done for both 25# programs and projects. 26config/payload_utils/public_replication.py \ 27 --input "${output_dir}/${private_config_path_rel}" \ 28 --output "${output_dir}/${public_config_path_rel}" 29 30# If we don't see the program symlink in the cwd, then 31# we are not a project and we are done. 32[[ ! -L program ]] && exit 33 34# If we did see the program symlink in the cwd, then 35# we are a project and we continue with generation of 36# platform json. 37 38# Call cros_config_proto_converter to transform a Protocol Buffer to config 39# readable by the ChromeOS platform. 40# 41# If either the program or project configs do not exist (e.g. because they are 42# public configs with all fields filtered) the function will return 0 without 43# calling cros_config_proto_converter. 44# 45# Args: 46# $1: Path to the protobuf input. E.g. "generated/config.jsonproto". 47# $2: Output directory to write platform JSON and other artifacts to. Note 48# that this directory will be deleted and recreated. 49proto_converter(){ 50 local _program_config=$1 51 local _project_config=$2 52 local _output_dir=$3 53 54 if [[ ! -e "${_program_config}" || ! -e "${_project_config}" ]]; then 55 return 0 56 fi 57 58 rm -rf "${_output_dir}" 59 mkdir -p "${_output_dir}" 60 61 # Call cros_conifg_proto_converter from chromeos-config. 62 PYTHONPATH="${script_dir}/../../platform2/chromeos-config" \ 63 vpython3 -vpython-spec "${script_dir}/../.vpython3" \ 64 -m cros_config_host.cros_config_proto_converter \ 65 --output "${_output_dir}/project-config.json" \ 66 --program_config "${_program_config}" \ 67 --project_configs "${_project_config}" 68} 69 70resolve_rel_path() { 71 realpath -m --relative-to="$(pwd)" "$1" 72} 73 74# Output dirs for private and public software configs. 75readonly sw_output_dir='sw_build_config/platform/chromeos-config/generated' 76readonly public_sw_output_dir="public_${sw_output_dir}" 77 78# convert private protos 79proto_converter \ 80 "program/${private_config_path_rel}" \ 81 "$(resolve_rel_path "${output_dir}/${private_config_path_rel}")" \ 82 "$(resolve_rel_path "${output_dir}/${sw_output_dir}")" 83 84# convert public protos 85proto_converter \ 86 "program/${public_config_path_rel}" \ 87 "$(resolve_rel_path "${output_dir}/${public_config_path_rel}")" \ 88 "$(resolve_rel_path "${output_dir}/${public_sw_output_dir}")" 89 90# and convert factory config 91factory_gen_dir="$(realpath -m "${output_dir}/factory/generated")" 92rm -rf "${factory_gen_dir}" 93mkdir -p "${factory_gen_dir}" 94config/payload_utils/factory_config_proto_converter.py \ 95 --output "${factory_gen_dir}/model_sku.json" \ 96 --program_config program/generated/config.jsonproto \ 97 --project_configs "${output_dir}/${private_config_path_rel}" 98