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 | |
Lann Martin | 55b9468 | 2019-03-15 14:39:38 -0600 | [diff] [blame] | 11 | # Versions of packages to get from CIPD. |
Lann Martin | d8f0c0c | 2019-03-08 11:00:32 -0700 | [diff] [blame] | 12 | CIPD_PROTOC_VERSION='v3.6.1' |
Allen Li | 474624a | 2019-12-11 23:55:40 -0800 | [diff] [blame] | 13 | CIPD_PROTOC_GEN_GO_VERSION='v1.3.2' |
Lann Martin | d8f0c0c | 2019-03-08 11:00:32 -0700 | [diff] [blame] | 14 | |
Prathmesh Prabhu | 6ade1ae | 2020-03-09 12:46:39 -0700 | [diff] [blame^] | 15 | readonly script_dir="$(dirname "$(realpath -e "${BASH_SOURCE[0]}")")" |
| 16 | |
| 17 | readonly work_dir=$(mktemp --tmpdir -d genprotoXXXXXX) |
| 18 | trap "rm -rf ${work_dir}" EXIT |
| 19 | echo "Using temporary directory ${work_dir}" |
| 20 | |
| 21 | if [[ -n ${CHROMIUMOS_CONFIG_DIR+x} ]]; then |
| 22 | echo "CHROMIUMOS_CONFIG_DIR is set: " \ |
| 23 | "Copying sources from ${CHROMIUMOS_CONFIG_DIR}/" |
| 24 | cp -r "${CHROMIUMOS_CONFIG_DIR}/" "${work_dir}/config" |
| 25 | else |
| 26 | echo "Creating a shallow clone of ${CROS_CONFIG_REPO}" |
| 27 | git clone -q --depth=1 --shallow-submodules "${CROS_CONFIG_REPO}" \ |
| 28 | "${work_dir}/config" |
| 29 | fi |
| 30 | readonly cros_config_subdir="config/proto" |
Lann Martin | d8f0c0c | 2019-03-08 11:00:32 -0700 | [diff] [blame] | 31 | |
| 32 | # Get protobuf compiler from CIPD. |
Prathmesh Prabhu | 6ade1ae | 2020-03-09 12:46:39 -0700 | [diff] [blame^] | 33 | readonly cipd_root="${script_dir}/.cipd_bin" |
Lann Martin | d8f0c0c | 2019-03-08 11:00:32 -0700 | [diff] [blame] | 34 | cipd ensure \ |
| 35 | -log-level warning \ |
| 36 | -root "${cipd_root}" \ |
| 37 | -ensure-file - \ |
Lann Martin | 55b9468 | 2019-03-15 14:39:38 -0600 | [diff] [blame] | 38 | <<ENSURE_FILE |
| 39 | infra/tools/protoc/\${platform} protobuf_version:${CIPD_PROTOC_VERSION} |
| 40 | chromiumos/infra/tools/protoc-gen-go version:${CIPD_PROTOC_GEN_GO_VERSION} |
| 41 | ENSURE_FILE |
Lann Martin | d8f0c0c | 2019-03-08 11:00:32 -0700 | [diff] [blame] | 42 | |
Lann Martin | 55b9468 | 2019-03-15 14:39:38 -0600 | [diff] [blame] | 43 | PATH="${cipd_root}:${PATH}" |
Lann Martin | d8f0c0c | 2019-03-08 11:00:32 -0700 | [diff] [blame] | 44 | |
Prathmesh Prabhu | 6ade1ae | 2020-03-09 12:46:39 -0700 | [diff] [blame^] | 45 | cd "${script_dir}" |
Lann Martin | d8f0c0c | 2019-03-08 11:00:32 -0700 | [diff] [blame] | 46 | |
Prathmesh Prabhu | 6ade1ae | 2020-03-09 12:46:39 -0700 | [diff] [blame^] | 47 | echo "Generating go bindings..." |
| 48 | # Clean up existing go bindings. |
| 49 | find go -name '*.pb.go' -exec rm '{}' \; |
Lann Martin | d8f0c0c | 2019-03-08 11:00:32 -0700 | [diff] [blame] | 50 | # Go files need to be processed individually until this is fixed: |
| 51 | # https://github.com/golang/protobuf/issues/39 |
| 52 | find src -name '*.proto' -exec \ |
Prathmesh Prabhu | 6ade1ae | 2020-03-09 12:46:39 -0700 | [diff] [blame^] | 53 | protoc -Isrc -I"${work_dir}/${cros_config_subdir}" \ |
| 54 | --go_out=paths=source_relative,plugins=grpc:go '{}' \; |