blob: 2fb38381037be454655ce8be2e1e5bf6d2424f85 [file] [log] [blame]
Lann Martind8f0c0c2019-03-08 11:00:32 -07001#!/bin/bash -e
Sean Abrahamfdabbe72019-03-13 09:03:37 -06002#
3# Copyright 2019 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6#
7# Runs protoc over the protos in this repo to produce generated proto code.
Lann Martind8f0c0c2019-03-08 11:00:32 -07008
Prathmesh Prabhu6ade1ae2020-03-09 12:46:39 -07009CROS_CONFIG_REPO="https://chromium.googlesource.com/chromiumos/config"
10
Prathmesh Prabhu6ade1ae2020-03-09 12:46:39 -070011readonly script_dir="$(dirname "$(realpath -e "${BASH_SOURCE[0]}")")"
Allen Li4f211142020-02-21 17:31:10 -080012source "${script_dir}/setup_cipd.sh"
Prathmesh Prabhu6ade1ae2020-03-09 12:46:39 -070013
14readonly work_dir=$(mktemp --tmpdir -d genprotoXXXXXX)
15trap "rm -rf ${work_dir}" EXIT
16echo "Using temporary directory ${work_dir}"
17
18if [[ -n ${CHROMIUMOS_CONFIG_DIR+x} ]]; then
19 echo "CHROMIUMOS_CONFIG_DIR is set: " \
20 "Copying sources from ${CHROMIUMOS_CONFIG_DIR}/"
21 cp -r "${CHROMIUMOS_CONFIG_DIR}/" "${work_dir}/config"
22else
23 echo "Creating a shallow clone of ${CROS_CONFIG_REPO}"
24 git clone -q --depth=1 --shallow-submodules "${CROS_CONFIG_REPO}" \
25 "${work_dir}/config"
26fi
27readonly cros_config_subdir="config/proto"
Lann Martind8f0c0c2019-03-08 11:00:32 -070028
Prathmesh Prabhu6ade1ae2020-03-09 12:46:39 -070029cd "${script_dir}"
Lann Martind8f0c0c2019-03-08 11:00:32 -070030
Prathmesh Prabhu6ade1ae2020-03-09 12:46:39 -070031echo "Generating go bindings..."
32# Clean up existing go bindings.
33find go -name '*.pb.go' -exec rm '{}' \;
Lann Martind8f0c0c2019-03-08 11:00:32 -070034# Go files need to be processed individually until this is fixed:
35# https://github.com/golang/protobuf/issues/39
36find src -name '*.proto' -exec \
Prathmesh Prabhu6ade1ae2020-03-09 12:46:39 -070037 protoc -Isrc -I"${work_dir}/${cros_config_subdir}" \
Sean Abraham17db9e82021-02-03 14:05:53 -070038 --go_out=go/ --go_opt=paths=source_relative \
39 --go-grpc_out=go/ --go-grpc_opt=paths=source_relative '{}' \;
Vadim Bendebury7dc1e3a2020-11-13 11:08:27 -080040
41chromite_root="$(readlink -f "$(dirname "$0")/../..")"
42chromite_api_compiler="${chromite_root}/api/compile_build_api_proto"
43if [[ -x "${chromite_api_compiler}" ]]; then
44 echo "Running chromite compiler"
45 "${chromite_api_compiler}"
46 echo "Don't forget to upload changes generated in ${chromite_root}, if any"
47fi