David Burger | c33d1eb | 2020-01-21 14:24:50 -0700 | [diff] [blame] | 1 | #!/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 Burger | 1b84536 | 2020-02-13 14:43:37 -0700 | [diff] [blame] | 9 | # Allows the recursive glob for proto files below to work. |
| 10 | shopt -s globstar |
| 11 | |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 12 | readonly script_dir="$(dirname "$(realpath -e "${BASH_SOURCE[0]}")")" |
David Burger | c33d1eb | 2020-01-21 14:24:50 -0700 | [diff] [blame] | 13 | # Move to this script's directory. |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 14 | cd "${script_dir}" |
| 15 | # Uses ${script_dir} |
| 16 | source "./setup_cipd.sh" |
David Burger | c33d1eb | 2020-01-21 14:24:50 -0700 | [diff] [blame] | 17 | |
David Burger | 78d3e62 | 2020-05-07 19:18:25 -0600 | [diff] [blame] | 18 | # Remove files from prior python protocol buffer code generation in |
| 19 | # case any .proto files have been removed. |
| 20 | find python/ -type f -name '*_pb2.py' -delete |
| 21 | find python/chromiumos -mindepth 1 -type d -not -name __pycache__ \ |
| 22 | -exec rm -f '{}/__init__.py' \; |
| 23 | |
Congbin Guo | ab994fd | 2020-05-15 13:08:18 -0700 | [diff] [blame^] | 24 | readonly google_api_repo_dir=$(mktemp -d) |
| 25 | readonly go_temp_dir=$(mktemp -d) |
| 26 | trap "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. |
| 30 | readonly google_apis_repo_url="https://github.com/googleapis/api-common-protos" |
| 31 | readonly google_apis_repo_version="1.50.0" |
| 32 | wget -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. |
| 36 | protoc -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 Lamb | bc029d3 | 2020-02-24 12:42:50 -0700 | [diff] [blame] | 43 | # Collect all the protos. |
David Burger | 1b84536 | 2020-02-13 14:43:37 -0700 | [diff] [blame] | 44 | protos=(proto/**/*.proto) |
David Burger | 1b84536 | 2020-02-13 14:43:37 -0700 | [diff] [blame] | 45 | |
Congbin Guo | ab994fd | 2020-05-15 13:08:18 -0700 | [diff] [blame^] | 46 | readonly protoc_opts="-Iproto -I${google_api_repo_dir}" |
| 47 | |
| 48 | PATH="${CIPD_ROOT}" protoc ${protoc_opts} \ |
David Burger | 7f5a8fb | 2020-06-01 10:17:32 -0600 | [diff] [blame] | 49 | --descriptor_set_out=util/bindings/descpb.bin \ |
Prathmesh Prabhu | 72f8a00 | 2020-04-10 09:57:53 -0700 | [diff] [blame] | 50 | --python_out=python "${protos[@]}" |
David Riley | 996c524 | 2020-05-06 11:31:25 -0700 | [diff] [blame] | 51 | find python/chromiumos -mindepth 1 -type d -not -name __pycache__ \ |
| 52 | -exec touch '{}/__init__.py' \; |
Andrew Lamb | bc029d3 | 2020-02-24 12:42:50 -0700 | [diff] [blame] | 53 | |
Prathmesh Prabhu | 72f8a00 | 2020-04-10 09:57:53 -0700 | [diff] [blame] | 54 | |
| 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 Burger | 78d3e62 | 2020-05-07 19:18:25 -0600 | [diff] [blame] | 58 | |
| 59 | # Remove files from prior go protocol buffer code generation in |
| 60 | # case any .proto files have been removed. |
| 61 | find go/ -name '*pb.go' -delete |
| 62 | |
Andrew Lamb | bc029d3 | 2020-02-24 12:42:50 -0700 | [diff] [blame] | 63 | # Go files need to be processed individually until this is fixed: |
| 64 | # https://github.com/golang/protobuf/issues/39 |
| 65 | for proto in "${protos[@]}"; do |
Congbin Guo | ab994fd | 2020-05-15 13:08:18 -0700 | [diff] [blame^] | 66 | PATH="${CIPD_ROOT}" protoc ${protoc_opts} \ |
| 67 | --go_out=plugins=grpc,paths=source_relative:"${go_temp_dir}" \ |
Prathmesh Prabhu | 72f8a00 | 2020-04-10 09:57:53 -0700 | [diff] [blame] | 68 | "${proto}" |
C Shapiro | b8cd5f9 | 2020-03-10 09:47:10 -0500 | [diff] [blame] | 69 | done |
Congbin Guo | ab994fd | 2020-05-15 13:08:18 -0700 | [diff] [blame^] | 70 | cp -rf "${go_temp_dir}"/chromiumos/config/* go/ |