blob: 954fab5ee3434ef35e48337d71d5f0485824bec0 [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
David Burger78d3e622020-05-07 19:18:25 -060018# Remove files from prior python protocol buffer code generation in
19# case any .proto files have been removed.
20find python/ -type f -name '*_pb2.py' -delete
21find python/chromiumos -mindepth 1 -type d -not -name __pycache__ \
22 -exec rm -f '{}/__init__.py' \;
23
Andrew Lambbc029d32020-02-24 12:42:50 -070024# Collect all the protos.
David Burger1b845362020-02-13 14:43:37 -070025protos=(proto/**/*.proto)
David Burger1b845362020-02-13 14:43:37 -070026
Andrew Lambbc029d32020-02-24 12:42:50 -070027protoc -Iproto --descriptor_set_out=util/bindings/descpb.bin \
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070028 --python_out=python "${protos[@]}"
David Riley996c5242020-05-06 11:31:25 -070029find python/chromiumos -mindepth 1 -type d -not -name __pycache__ \
30 -exec touch '{}/__init__.py' \;
Andrew Lambbc029d32020-02-24 12:42:50 -070031
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070032
33# Go bindings are already namespaced under go.chromium.org/chromiumos/config/go
34# We remove the "chromiumos/config" prefix from local path to avoid redundant
35# namespaceing.
David Burger78d3e622020-05-07 19:18:25 -060036
37# Remove files from prior go protocol buffer code generation in
38# case any .proto files have been removed.
39find go/ -name '*pb.go' -delete
40
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070041readonly GO_TEMP_DIR=$(mktemp -d)
42trap "rm -rf ${GO_TEMP_DIR}" EXIT
Andrew Lambbc029d32020-02-24 12:42:50 -070043# Go files need to be processed individually until this is fixed:
44# https://github.com/golang/protobuf/issues/39
45for proto in "${protos[@]}"; do
Prathmesh Prabhud5dbe872020-04-20 22:48:16 -070046 protoc -I"proto" \
47 --go_out=plugins=grpc,paths=source_relative:"${GO_TEMP_DIR}" \
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070048 "${proto}"
C Shapirob8cd5f92020-03-10 09:47:10 -050049done
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070050cp -rf "${GO_TEMP_DIR}"/chromiumos/config/* go/