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 | |
David Burger | c33d1eb | 2020-01-21 14:24:50 -0700 | [diff] [blame] | 12 | # Versions of packages to get from CIPD. |
| 13 | CIPD_PROTOC_VERSION='v3.6.1' |
Andrew Lamb | bc029d3 | 2020-02-24 12:42:50 -0700 | [diff] [blame] | 14 | CIPD_PROTOC_GEN_GO_VERSION='v1.3.2' |
David Burger | c33d1eb | 2020-01-21 14:24:50 -0700 | [diff] [blame] | 15 | |
| 16 | # Move to this script's directory. |
| 17 | cd "$(dirname "$0")" |
| 18 | |
| 19 | # Get protobuf compiler from CIPD. |
| 20 | cipd_root=.cipd_bin |
| 21 | cipd ensure \ |
| 22 | -log-level warning \ |
| 23 | -root "${cipd_root}" \ |
| 24 | -ensure-file - \ |
| 25 | <<ENSURE_FILE |
| 26 | infra/tools/protoc/\${platform} protobuf_version:${CIPD_PROTOC_VERSION} |
Andrew Lamb | bc029d3 | 2020-02-24 12:42:50 -0700 | [diff] [blame] | 27 | chromiumos/infra/tools/protoc-gen-go version:${CIPD_PROTOC_GEN_GO_VERSION} |
David Burger | c33d1eb | 2020-01-21 14:24:50 -0700 | [diff] [blame] | 28 | ENSURE_FILE |
| 29 | |
| 30 | PATH="${cipd_root}:${PATH}" |
| 31 | |
Andrew Lamb | bc029d3 | 2020-02-24 12:42:50 -0700 | [diff] [blame] | 32 | # Collect all the protos. |
David Burger | 1b84536 | 2020-02-13 14:43:37 -0700 | [diff] [blame] | 33 | protos=(proto/**/*.proto) |
David Burger | 1b84536 | 2020-02-13 14:43:37 -0700 | [diff] [blame] | 34 | |
Andrew Lamb | bc029d3 | 2020-02-24 12:42:50 -0700 | [diff] [blame] | 35 | protoc -Iproto --descriptor_set_out=util/bindings/descpb.bin \ |
Prathmesh Prabhu | 72f8a00 | 2020-04-10 09:57:53 -0700 | [diff] [blame] | 36 | --python_out=python "${protos[@]}" |
Andrew Lamb | bc029d3 | 2020-02-24 12:42:50 -0700 | [diff] [blame] | 37 | |
Prathmesh Prabhu | 72f8a00 | 2020-04-10 09:57:53 -0700 | [diff] [blame] | 38 | |
| 39 | # Go bindings are already namespaced under go.chromium.org/chromiumos/config/go |
| 40 | # We remove the "chromiumos/config" prefix from local path to avoid redundant |
| 41 | # namespaceing. |
| 42 | readonly GO_TEMP_DIR=$(mktemp -d) |
| 43 | trap "rm -rf ${GO_TEMP_DIR}" EXIT |
Andrew Lamb | bc029d3 | 2020-02-24 12:42:50 -0700 | [diff] [blame] | 44 | # Go files need to be processed individually until this is fixed: |
| 45 | # https://github.com/golang/protobuf/issues/39 |
| 46 | for proto in "${protos[@]}"; do |
Prathmesh Prabhu | d5dbe87 | 2020-04-20 22:48:16 -0700 | [diff] [blame^] | 47 | protoc -I"proto" \ |
| 48 | --go_out=plugins=grpc,paths=source_relative:"${GO_TEMP_DIR}" \ |
Prathmesh Prabhu | 72f8a00 | 2020-04-10 09:57:53 -0700 | [diff] [blame] | 49 | "${proto}" |
C Shapiro | b8cd5f9 | 2020-03-10 09:47:10 -0500 | [diff] [blame] | 50 | done |
Prathmesh Prabhu | 72f8a00 | 2020-04-10 09:57:53 -0700 | [diff] [blame] | 51 | cp -rf "${GO_TEMP_DIR}"/chromiumos/config/* go/ |