blob: c175fb170f589694169bded2ceb736832fc06786 [file] [log] [blame]
David Burgerc33d1eb2020-01-21 14:24:50 -07001#!/bin/bash -e
2#
3# Copyright 2020 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 configuration protos to produce generated proto code.
8
David Burger1b845362020-02-13 14:43:37 -07009# Allows the recursive glob for proto files below to work.
10shopt -s globstar
11
Prathmesh Prabhu42207542020-04-20 23:13:23 -070012readonly script_dir="$(dirname "$(realpath -e "${BASH_SOURCE[0]}")")"
David Burgerc33d1eb2020-01-21 14:24:50 -070013# Move to this script's directory.
Prathmesh Prabhu42207542020-04-20 23:13:23 -070014cd "${script_dir}"
15# Uses ${script_dir}
16source "./setup_cipd.sh"
David Burgerc33d1eb2020-01-21 14:24:50 -070017
Andrew Lambbc029d32020-02-24 12:42:50 -070018# Collect all the protos.
David Burger1b845362020-02-13 14:43:37 -070019protos=(proto/**/*.proto)
David Burger1b845362020-02-13 14:43:37 -070020
Andrew Lambbc029d32020-02-24 12:42:50 -070021protoc -Iproto --descriptor_set_out=util/bindings/descpb.bin \
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070022 --python_out=python "${protos[@]}"
Andrew Lambbc029d32020-02-24 12:42:50 -070023
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070024
25# Go bindings are already namespaced under go.chromium.org/chromiumos/config/go
26# We remove the "chromiumos/config" prefix from local path to avoid redundant
27# namespaceing.
28readonly GO_TEMP_DIR=$(mktemp -d)
29trap "rm -rf ${GO_TEMP_DIR}" EXIT
Andrew Lambbc029d32020-02-24 12:42:50 -070030# Go files need to be processed individually until this is fixed:
31# https://github.com/golang/protobuf/issues/39
32for proto in "${protos[@]}"; do
Prathmesh Prabhud5dbe872020-04-20 22:48:16 -070033 protoc -I"proto" \
34 --go_out=plugins=grpc,paths=source_relative:"${GO_TEMP_DIR}" \
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070035 "${proto}"
C Shapirob8cd5f92020-03-10 09:47:10 -050036done
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070037cp -rf "${GO_TEMP_DIR}"/chromiumos/config/* go/