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 | |
Sean Abraham | bcf2e70 | 2021-02-04 10:36:06 -0700 | [diff] [blame] | 18 | if [[ "$(uname -s)" != "Linux" || "$(uname -m)" != "x86_64" ]]; then |
| 19 | echo "Error: currently generate.sh can only run on Linux x86_64 systems." |
| 20 | echo "This is because we use checked-in binaries for protoc-gen-go(-grpc)?." |
| 21 | echo "This will change soon though. See https://crbug.com/1174238" |
| 22 | exit 1 |
| 23 | fi |
| 24 | |
Prathmesh Prabhu | 6ade1ae | 2020-03-09 12:46:39 -0700 | [diff] [blame] | 25 | if [[ -n ${CHROMIUMOS_CONFIG_DIR+x} ]]; then |
| 26 | echo "CHROMIUMOS_CONFIG_DIR is set: " \ |
| 27 | "Copying sources from ${CHROMIUMOS_CONFIG_DIR}/" |
| 28 | cp -r "${CHROMIUMOS_CONFIG_DIR}/" "${work_dir}/config" |
| 29 | else |
| 30 | echo "Creating a shallow clone of ${CROS_CONFIG_REPO}" |
| 31 | git clone -q --depth=1 --shallow-submodules "${CROS_CONFIG_REPO}" \ |
| 32 | "${work_dir}/config" |
| 33 | fi |
| 34 | readonly cros_config_subdir="config/proto" |
Lann Martin | d8f0c0c | 2019-03-08 11:00:32 -0700 | [diff] [blame] | 35 | |
Prathmesh Prabhu | 6ade1ae | 2020-03-09 12:46:39 -0700 | [diff] [blame] | 36 | cd "${script_dir}" |
Lann Martin | d8f0c0c | 2019-03-08 11:00:32 -0700 | [diff] [blame] | 37 | |
Prathmesh Prabhu | 6ade1ae | 2020-03-09 12:46:39 -0700 | [diff] [blame] | 38 | echo "Generating go bindings..." |
| 39 | # Clean up existing go bindings. |
| 40 | find go -name '*.pb.go' -exec rm '{}' \; |
Lann Martin | d8f0c0c | 2019-03-08 11:00:32 -0700 | [diff] [blame] | 41 | # Go files need to be processed individually until this is fixed: |
| 42 | # https://github.com/golang/protobuf/issues/39 |
| 43 | find src -name '*.proto' -exec \ |
Prathmesh Prabhu | 6ade1ae | 2020-03-09 12:46:39 -0700 | [diff] [blame] | 44 | protoc -Isrc -I"${work_dir}/${cros_config_subdir}" \ |
Sean Abraham | 17db9e8 | 2021-02-03 14:05:53 -0700 | [diff] [blame] | 45 | --go_out=go/ --go_opt=paths=source_relative \ |
| 46 | --go-grpc_out=go/ --go-grpc_opt=paths=source_relative '{}' \; |
Vadim Bendebury | 7dc1e3a | 2020-11-13 11:08:27 -0800 | [diff] [blame] | 47 | |
| 48 | chromite_root="$(readlink -f "$(dirname "$0")/../..")" |
| 49 | chromite_api_compiler="${chromite_root}/api/compile_build_api_proto" |
LaMont Jones | fea7df0 | 2021-05-18 10:55:45 -0600 | [diff] [blame^] | 50 | if [[ ${USER} = chrome-bot ]]; then |
| 51 | echo "Not running chromite compiler" |
| 52 | elif [[ -x "${chromite_api_compiler}" ]]; then |
Vadim Bendebury | 7dc1e3a | 2020-11-13 11:08:27 -0800 | [diff] [blame] | 53 | echo "Running chromite compiler" |
| 54 | "${chromite_api_compiler}" |
| 55 | echo "Don't forget to upload changes generated in ${chromite_root}, if any" |
| 56 | fi |