blob: 65114a4acab27ca6a6b80ce8415b5bb4aa3acddd [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}" \
38 --go_out=paths=source_relative,plugins=grpc:go '{}' \;
Vadim Bendebury7dc1e3a2020-11-13 11:08:27 -080039
40chromite_root="$(readlink -f "$(dirname "$0")/../..")"
41chromite_api_compiler="${chromite_root}/api/compile_build_api_proto"
42if [[ -x "${chromite_api_compiler}" ]]; then
43 echo "Running chromite compiler"
44 "${chromite_api_compiler}"
45 echo "Don't forget to upload changes generated in ${chromite_root}, if any"
46fi