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 | |
Andrew Lamb | bc029d3 | 2020-02-24 12:42:50 -0700 | [diff] [blame] | 18 | # Collect all the protos. |
David Burger | 1b84536 | 2020-02-13 14:43:37 -0700 | [diff] [blame] | 19 | protos=(proto/**/*.proto) |
David Burger | 1b84536 | 2020-02-13 14:43:37 -0700 | [diff] [blame] | 20 | |
Andrew Lamb | bc029d3 | 2020-02-24 12:42:50 -0700 | [diff] [blame] | 21 | protoc -Iproto --descriptor_set_out=util/bindings/descpb.bin \ |
Prathmesh Prabhu | 72f8a00 | 2020-04-10 09:57:53 -0700 | [diff] [blame] | 22 | --python_out=python "${protos[@]}" |
Andrew Lamb | bc029d3 | 2020-02-24 12:42:50 -0700 | [diff] [blame] | 23 | |
Prathmesh Prabhu | 72f8a00 | 2020-04-10 09:57:53 -0700 | [diff] [blame] | 24 | |
| 25 | # Go bindings are already namespaced under go.chromium.org/chromiumos/config/go |
| 26 | # We remove the "chromiumos/config" prefix from local path to avoid redundant |
| 27 | # namespaceing. |
| 28 | readonly GO_TEMP_DIR=$(mktemp -d) |
| 29 | trap "rm -rf ${GO_TEMP_DIR}" EXIT |
Andrew Lamb | bc029d3 | 2020-02-24 12:42:50 -0700 | [diff] [blame] | 30 | # Go files need to be processed individually until this is fixed: |
| 31 | # https://github.com/golang/protobuf/issues/39 |
| 32 | for proto in "${protos[@]}"; do |
Prathmesh Prabhu | d5dbe87 | 2020-04-20 22:48:16 -0700 | [diff] [blame] | 33 | protoc -I"proto" \ |
| 34 | --go_out=plugins=grpc,paths=source_relative:"${GO_TEMP_DIR}" \ |
Prathmesh Prabhu | 72f8a00 | 2020-04-10 09:57:53 -0700 | [diff] [blame] | 35 | "${proto}" |
C Shapiro | b8cd5f9 | 2020-03-10 09:47:10 -0500 | [diff] [blame] | 36 | done |
Prathmesh Prabhu | 72f8a00 | 2020-04-10 09:57:53 -0700 | [diff] [blame] | 37 | cp -rf "${GO_TEMP_DIR}"/chromiumos/config/* go/ |