Jacob Kopczynski | c681785 | 2020-06-09 14:17:55 -0700 | [diff] [blame] | 1 | #!/bin/bash -e |
| 2 | # Copyright 2020 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | # Obtain the most recent proto descriptors from chromiumos/infra/proto protos. |
| 7 | # This is needed to work with these protos from *.star code. |
| 8 | |
| 9 | set -eu |
| 10 | |
| 11 | CROS_CONFIG_REPO="https://chromium.googlesource.com/chromiumos/config" |
| 12 | |
| 13 | CIPD_PROTOC_VERSION='v3.6.1' |
| 14 | CIPD_PROTOC_GEN_GO_VERSION='v1.3.2' |
| 15 | |
| 16 | readonly script_dir="$(dirname "$(realpath -e "${BASH_SOURCE[0]}")")" |
| 17 | readonly target="${script_dir}/proto/descpb.bin" |
| 18 | |
| 19 | readonly work_dir=$(mktemp --tmpdir -d genprotodescXXXXXX) |
| 20 | trap "rm -rf ${work_dir}" EXIT |
| 21 | echo "Using temporary directory ${work_dir}" |
| 22 | |
| 23 | if [[ -n ${CHROMIUMOS_CONFIG_DIR+x} ]]; then |
| 24 | echo "CHROMIUMOS_CONFIG_DIR is set: " \ |
| 25 | "Copying sources from ${CHROMIUMOS_CONFIG_DIR}/" |
| 26 | cp -r "${CHROMIUMOS_CONFIG_DIR}/" "${work_dir}/config" |
| 27 | else |
| 28 | echo "Creating a shallow clone of ${CROS_CONFIG_REPO}" |
| 29 | git clone -q --depth=1 --shallow-submodules "${CROS_CONFIG_REPO}" \ |
| 30 | "${work_dir}/config" |
| 31 | fi |
| 32 | readonly cros_config_subdir="config/proto" |
| 33 | |
| 34 | echo "Grabbing protoc from CIPD" |
| 35 | cipd_root=.cipd_bin |
| 36 | cipd ensure \ |
| 37 | -log-level warning \ |
| 38 | -root "${cipd_root}" \ |
| 39 | -ensure-file - \ |
| 40 | <<ENSURE_FILE |
| 41 | infra/tools/protoc/\${platform} protobuf_version:${CIPD_PROTOC_VERSION} |
| 42 | chromiumos/infra/tools/protoc-gen-go version:${CIPD_PROTOC_GEN_GO_VERSION} |
| 43 | ENSURE_FILE |
| 44 | |
| 45 | # Need full path here for cipd as there is a cd to a different directory. |
| 46 | export PATH="${script_dir}/${cipd_root}:${PATH}" |
| 47 | |
| 48 | echo "Generating protobuf descriptors" |
| 49 | readonly all_protos=$( |
| 50 | cd "${work_dir}" && |
| 51 | find "${cros_config_subdir}" -name "*.proto" | sort |
| 52 | ) |
| 53 | ( |
| 54 | cd "${work_dir}" && |
| 55 | export LC_ALL=C # for stable sorting order |
| 56 | protoc -I"${cros_config_subdir}" \ |
| 57 | --descriptor_set_out=descpb.bin ${all_protos} |
| 58 | ) |
| 59 | |
| 60 | echo "Copying generated descriptors" |
| 61 | cp "${work_dir}/descpb.bin" "${target}" |