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 | |
Andrew Lamb | bc029d3 | 2020-02-24 12:42:50 -0700 | [diff] [blame] | 24 | # Collect all the protos. |
David Burger | 1b84536 | 2020-02-13 14:43:37 -0700 | [diff] [blame] | 25 | protos=(proto/**/*.proto) |
David Burger | 1b84536 | 2020-02-13 14:43:37 -0700 | [diff] [blame] | 26 | |
Alex Zamorzaev | 6f41e3d | 2020-06-08 19:46:01 +0000 | [diff] [blame] | 27 | PATH="${CIPD_ROOT}" protoc -Iproto \ |
David Burger | 7f5a8fb | 2020-06-01 10:17:32 -0600 | [diff] [blame] | 28 | --descriptor_set_out=util/bindings/descpb.bin \ |
Prathmesh Prabhu | 72f8a00 | 2020-04-10 09:57:53 -0700 | [diff] [blame] | 29 | --python_out=python "${protos[@]}" |
David Riley | 996c524 | 2020-05-06 11:31:25 -0700 | [diff] [blame] | 30 | find python/chromiumos -mindepth 1 -type d -not -name __pycache__ \ |
| 31 | -exec touch '{}/__init__.py' \; |
Andrew Lamb | bc029d3 | 2020-02-24 12:42:50 -0700 | [diff] [blame] | 32 | |
Prathmesh Prabhu | 72f8a00 | 2020-04-10 09:57:53 -0700 | [diff] [blame] | 33 | |
| 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 Burger | 78d3e62 | 2020-05-07 19:18:25 -0600 | [diff] [blame] | 37 | |
| 38 | # Remove files from prior go protocol buffer code generation in |
| 39 | # case any .proto files have been removed. |
| 40 | find go/ -name '*pb.go' -delete |
| 41 | |
Alex Zamorzaev | 6f41e3d | 2020-06-08 19:46:01 +0000 | [diff] [blame] | 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 |
Alex Zamorzaev | 6f41e3d | 2020-06-08 19:46:01 +0000 | [diff] [blame] | 47 | PATH="${CIPD_ROOT}" 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 |
C Shapiro | 0eba639 | 2021-05-05 11:57:19 -0500 | [diff] [blame] | 51 | |
Alex Zamorzaev | 6f41e3d | 2020-06-08 19:46:01 +0000 | [diff] [blame] | 52 | cp -rf "${GO_TEMP_DIR}"/chromiumos/config/* go/ |
C Shapiro | ca31c6d | 2021-05-05 09:29:19 -0500 | [diff] [blame] | 53 | cp "${GO_TEMP_DIR}"/chromiumos/*.go go/ |
C Shapiro | 0eba639 | 2021-05-05 11:57:19 -0500 | [diff] [blame] | 54 | cp "${GO_TEMP_DIR}"/chromiumos/longrunning/*.go go/longrunning |
C Shapiro | 5ff61db | 2021-02-11 10:32:14 -0600 | [diff] [blame] | 55 | cp -rf "${GO_TEMP_DIR}"/chromiumos/build/api/* go/build/api |
Andrew Lamb | 7a58287 | 2021-03-29 15:09:24 -0600 | [diff] [blame] | 56 | cp -rf "${GO_TEMP_DIR}"/chromiumos/test/* go/test |