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# Used to generate starlark protojson config output. Expects to be able 8# to find the protocol buffer generating script in the directory with the 9# config file at config/generate.sh and expects to be able to find the 10# lucicfg binary on the path from depot_tools. 11 12readonly script_dir="$(dirname "$(realpath -e "${BASH_SOURCE[0]}")")" 13source "${script_dir}/common.sh" 14 15# Exit if any command fails. 16set -e 17trap "summarize" EXIT 18 19source "${script_dir}/../setup_cipd.sh" 20 21output_dir="." 22while [[ $# -gt 0 ]]; do 23 case $1 in 24 --output-dir|-o) 25 output_dir="$2" 26 shift 27 shift 28 ;; 29 *) 30 break 31 ;; 32 esac 33done 34 35if [[ $# -ne 1 ]]; then 36 config_usage 37fi 38 39readonly file_path=$1 40readonly config_file=$(basename "${file_path}") 41readonly config_dir="$(dirname "$(realpath -e "${file_path}")")" 42 43# Hitting some relative links so change to the directory. 44cd "${config_dir}" 45 46echo "Formatting .star files with lucicfg fmt..." 47lucicfg fmt 48 49# luci requires -config-dir be relative to cwd 50lucicfg \ 51 generate \ 52 -config-dir \ 53 "$(realpath -m --relative-to="$(pwd)" "${output_dir}/generated")" \ 54 "${config_file}" 55