blob: 7f6476e17f3986dec068bb579993cf2c285fe76d [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
Alex Zamorzaev6f41e3d2020-06-08 19:46:01 +000027PATH="${CIPD_ROOT}" protoc -Iproto \
David Burger7f5a8fb2020-06-01 10:17:32 -060028 --descriptor_set_out=util/bindings/descpb.bin \
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070029 --python_out=python "${protos[@]}"
David Riley996c5242020-05-06 11:31:25 -070030find python/chromiumos -mindepth 1 -type d -not -name __pycache__ \
31 -exec touch '{}/__init__.py' \;
Andrew Lambbc029d32020-02-24 12:42:50 -070032
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070033
34# Go bindings are already namespaced under go.chromium.org/chromiumos/config/go
35# We remove the "chromiumos/config" prefix from local path to avoid redundant
36# namespaceing.
David Burger78d3e622020-05-07 19:18:25 -060037
38# Remove files from prior go protocol buffer code generation in
39# case any .proto files have been removed.
40find go/ -name '*pb.go' -delete
41
Alex Zamorzaev6f41e3d2020-06-08 19:46:01 +000042readonly GO_TEMP_DIR=$(mktemp -d)
43trap "rm -rf ${GO_TEMP_DIR}" EXIT
Andrew Lambbc029d32020-02-24 12:42:50 -070044# Go files need to be processed individually until this is fixed:
45# https://github.com/golang/protobuf/issues/39
46for proto in "${protos[@]}"; do
Alex Zamorzaev6f41e3d2020-06-08 19:46:01 +000047 PATH="${CIPD_ROOT}" protoc -I"proto" \
48 --go_out=plugins=grpc,paths=source_relative:"${GO_TEMP_DIR}" \
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070049 "${proto}"
C Shapirob8cd5f92020-03-10 09:47:10 -050050done
C Shapiro0eba6392021-05-05 11:57:19 -050051
Alex Zamorzaev6f41e3d2020-06-08 19:46:01 +000052cp -rf "${GO_TEMP_DIR}"/chromiumos/config/* go/
C Shapiroca31c6d2021-05-05 09:29:19 -050053cp "${GO_TEMP_DIR}"/chromiumos/*.go go/
C Shapiro0eba6392021-05-05 11:57:19 -050054cp "${GO_TEMP_DIR}"/chromiumos/longrunning/*.go go/longrunning
C Shapiro5ff61db2021-02-11 10:32:14 -060055cp -rf "${GO_TEMP_DIR}"/chromiumos/build/api/* go/build/api
Andrew Lamb7a582872021-03-29 15:09:24 -060056cp -rf "${GO_TEMP_DIR}"/chromiumos/test/* go/test