blob: 84a420ee36ab11fd7d401fdf1ea3268c59cdff96 [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[@]}"
David Riley996c5242020-05-06 11:31:25 -070023find python/chromiumos -mindepth 1 -type d -not -name __pycache__ \
24 -exec touch '{}/__init__.py' \;
Andrew Lambbc029d32020-02-24 12:42:50 -070025
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070026
27# Go bindings are already namespaced under go.chromium.org/chromiumos/config/go
28# We remove the "chromiumos/config" prefix from local path to avoid redundant
29# namespaceing.
30readonly GO_TEMP_DIR=$(mktemp -d)
31trap "rm -rf ${GO_TEMP_DIR}" EXIT
Andrew Lambbc029d32020-02-24 12:42:50 -070032# Go files need to be processed individually until this is fixed:
33# https://github.com/golang/protobuf/issues/39
34for proto in "${protos[@]}"; do
Prathmesh Prabhud5dbe872020-04-20 22:48:16 -070035 protoc -I"proto" \
36 --go_out=plugins=grpc,paths=source_relative:"${GO_TEMP_DIR}" \
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070037 "${proto}"
C Shapirob8cd5f92020-03-10 09:47:10 -050038done
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070039cp -rf "${GO_TEMP_DIR}"/chromiumos/config/* go/