blob: dda225f007b11f4ef0fca09414be1ad34a00019d [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
Lann Martin55b94682019-03-15 14:39:38 -060011# Versions of packages to get from CIPD.
Lann Martind8f0c0c2019-03-08 11:00:32 -070012CIPD_PROTOC_VERSION='v3.6.1'
Allen Li474624a2019-12-11 23:55:40 -080013CIPD_PROTOC_GEN_GO_VERSION='v1.3.2'
Lann Martind8f0c0c2019-03-08 11:00:32 -070014
Prathmesh Prabhu6ade1ae2020-03-09 12:46:39 -070015readonly script_dir="$(dirname "$(realpath -e "${BASH_SOURCE[0]}")")"
16
17readonly work_dir=$(mktemp --tmpdir -d genprotoXXXXXX)
18trap "rm -rf ${work_dir}" EXIT
19echo "Using temporary directory ${work_dir}"
20
21if [[ -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"
25else
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"
29fi
30readonly cros_config_subdir="config/proto"
Lann Martind8f0c0c2019-03-08 11:00:32 -070031
32# Get protobuf compiler from CIPD.
Prathmesh Prabhu6ade1ae2020-03-09 12:46:39 -070033readonly cipd_root="${script_dir}/.cipd_bin"
Lann Martind8f0c0c2019-03-08 11:00:32 -070034cipd ensure \
35 -log-level warning \
36 -root "${cipd_root}" \
37 -ensure-file - \
Lann Martin55b94682019-03-15 14:39:38 -060038 <<ENSURE_FILE
39infra/tools/protoc/\${platform} protobuf_version:${CIPD_PROTOC_VERSION}
40chromiumos/infra/tools/protoc-gen-go version:${CIPD_PROTOC_GEN_GO_VERSION}
41ENSURE_FILE
Lann Martind8f0c0c2019-03-08 11:00:32 -070042
Lann Martin55b94682019-03-15 14:39:38 -060043PATH="${cipd_root}:${PATH}"
Lann Martind8f0c0c2019-03-08 11:00:32 -070044
Prathmesh Prabhu6ade1ae2020-03-09 12:46:39 -070045cd "${script_dir}"
Lann Martind8f0c0c2019-03-08 11:00:32 -070046
Prathmesh Prabhu6ade1ae2020-03-09 12:46:39 -070047echo "Generating go bindings..."
48# Clean up existing go bindings.
49find go -name '*.pb.go' -exec rm '{}' \;
Lann Martind8f0c0c2019-03-08 11:00:32 -070050# Go files need to be processed individually until this is fixed:
51# https://github.com/golang/protobuf/issues/39
52find src -name '*.proto' -exec \
Prathmesh Prabhu6ade1ae2020-03-09 12:46:39 -070053 protoc -Isrc -I"${work_dir}/${cros_config_subdir}" \
54 --go_out=paths=source_relative,plugins=grpc:go '{}' \;