Lann Martin | d8f0c0c | 2019-03-08 11:00:32 -0700 | [diff] [blame] | 1 | #!/bin/bash -e |
Sean Abraham | fdabbe7 | 2019-03-13 09:03:37 -0600 | [diff] [blame] | 2 | # |
| 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 Martin | d8f0c0c | 2019-03-08 11:00:32 -0700 | [diff] [blame] | 8 | |
Prathmesh Prabhu | 6ade1ae | 2020-03-09 12:46:39 -0700 | [diff] [blame] | 9 | CROS_CONFIG_REPO="https://chromium.googlesource.com/chromiumos/config" |
| 10 | |
Prathmesh Prabhu | 6ade1ae | 2020-03-09 12:46:39 -0700 | [diff] [blame] | 11 | readonly script_dir="$(dirname "$(realpath -e "${BASH_SOURCE[0]}")")" |
Allen Li | 4f21114 | 2020-02-21 17:31:10 -0800 | [diff] [blame] | 12 | source "${script_dir}/setup_cipd.sh" |
Prathmesh Prabhu | 6ade1ae | 2020-03-09 12:46:39 -0700 | [diff] [blame] | 13 | |
| 14 | readonly work_dir=$(mktemp --tmpdir -d genprotoXXXXXX) |
| 15 | trap "rm -rf ${work_dir}" EXIT |
| 16 | echo "Using temporary directory ${work_dir}" |
| 17 | |
| 18 | if [[ -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" |
| 22 | else |
| 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" |
| 26 | fi |
| 27 | readonly cros_config_subdir="config/proto" |
Lann Martin | d8f0c0c | 2019-03-08 11:00:32 -0700 | [diff] [blame] | 28 | |
Prathmesh Prabhu | 6ade1ae | 2020-03-09 12:46:39 -0700 | [diff] [blame] | 29 | cd "${script_dir}" |
Lann Martin | d8f0c0c | 2019-03-08 11:00:32 -0700 | [diff] [blame] | 30 | |
Prathmesh Prabhu | 6ade1ae | 2020-03-09 12:46:39 -0700 | [diff] [blame] | 31 | echo "Generating go bindings..." |
| 32 | # Clean up existing go bindings. |
| 33 | find go -name '*.pb.go' -exec rm '{}' \; |
Lann Martin | d8f0c0c | 2019-03-08 11:00:32 -0700 | [diff] [blame] | 34 | # Go files need to be processed individually until this is fixed: |
| 35 | # https://github.com/golang/protobuf/issues/39 |
| 36 | find src -name '*.proto' -exec \ |
Prathmesh Prabhu | 6ade1ae | 2020-03-09 12:46:39 -0700 | [diff] [blame] | 37 | protoc -Isrc -I"${work_dir}/${cros_config_subdir}" \ |
| 38 | --go_out=paths=source_relative,plugins=grpc:go '{}' \; |
Vadim Bendebury | 7dc1e3a | 2020-11-13 11:08:27 -0800 | [diff] [blame^] | 39 | |
| 40 | chromite_root="$(readlink -f "$(dirname "$0")/../..")" |
| 41 | chromite_api_compiler="${chromite_root}/api/compile_build_api_proto" |
| 42 | if [[ -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" |
| 46 | fi |