blob: fab44214ba1af606897ba35983f785431cf2751b [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
Congbin Guoab994fd2020-05-15 13:08:18 -070024readonly google_api_repo_dir=$(mktemp -d)
25readonly go_temp_dir=$(mktemp -d)
26trap "rm -rf ${google_api_repo_dir} ${go_temp_dir}" EXIT
27
28# We need `google.longrunning` from the below repo for long running operations,
29# see http://aip.dev/151 for details.
30readonly google_apis_repo_url="https://github.com/googleapis/api-common-protos"
31readonly google_apis_repo_version="1.50.0"
32wget -q -O - ${google_apis_repo_url}/tarball/${google_apis_repo_version} | \
33 tar xz --strip-components=1 -C "${google_api_repo_dir}"
34# We must generate descriptor for `google.longrunning.operations` separately
35# since it is imported by not included in `descpb.bin` in below.
36protoc -I${google_api_repo_dir} \
37 --descriptor_set_out=util/bindings/google_longrunning_operations_descpb.bin \
38 google/longrunning/operations.proto \
39 google/api/annotations.proto \
40 google/api/http.proto \
41 google/rpc/status.proto
42
Andrew Lambbc029d32020-02-24 12:42:50 -070043# Collect all the protos.
David Burger1b845362020-02-13 14:43:37 -070044protos=(proto/**/*.proto)
David Burger1b845362020-02-13 14:43:37 -070045
Congbin Guoab994fd2020-05-15 13:08:18 -070046readonly protoc_opts="-Iproto -I${google_api_repo_dir}"
47
48PATH="${CIPD_ROOT}" protoc ${protoc_opts} \
David Burger7f5a8fb2020-06-01 10:17:32 -060049 --descriptor_set_out=util/bindings/descpb.bin \
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070050 --python_out=python "${protos[@]}"
David Riley996c5242020-05-06 11:31:25 -070051find python/chromiumos -mindepth 1 -type d -not -name __pycache__ \
52 -exec touch '{}/__init__.py' \;
Andrew Lambbc029d32020-02-24 12:42:50 -070053
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070054
55# Go bindings are already namespaced under go.chromium.org/chromiumos/config/go
56# We remove the "chromiumos/config" prefix from local path to avoid redundant
57# namespaceing.
David Burger78d3e622020-05-07 19:18:25 -060058
59# Remove files from prior go protocol buffer code generation in
60# case any .proto files have been removed.
61find go/ -name '*pb.go' -delete
62
Andrew Lambbc029d32020-02-24 12:42:50 -070063# Go files need to be processed individually until this is fixed:
64# https://github.com/golang/protobuf/issues/39
65for proto in "${protos[@]}"; do
Congbin Guoab994fd2020-05-15 13:08:18 -070066 PATH="${CIPD_ROOT}" protoc ${protoc_opts} \
67 --go_out=plugins=grpc,paths=source_relative:"${go_temp_dir}" \
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070068 "${proto}"
C Shapirob8cd5f92020-03-10 09:47:10 -050069done
Congbin Guoab994fd2020-05-15 13:08:18 -070070cp -rf "${go_temp_dir}"/chromiumos/config/* go/