blob: 6e137f165c343dffa40f11b153bd66840b63fd05 [file] [log] [blame]
David Burgerc33d1eb2020-01-21 14:24:50 -07001#!/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
9# Versions of packages to get from CIPD.
10CIPD_PROTOC_VERSION='v3.6.1'
Andrew Lamb9aadbc82020-01-30 09:41:35 -070011CIPD_PROTOC_GEN_GO_VERSION='v1.3.2'
David Burgerc33d1eb2020-01-21 14:24:50 -070012
13# Move to this script's directory.
14cd "$(dirname "$0")"
15
16# Get protobuf compiler from CIPD.
17cipd_root=.cipd_bin
18cipd ensure \
19 -log-level warning \
20 -root "${cipd_root}" \
21 -ensure-file - \
22 <<ENSURE_FILE
23infra/tools/protoc/\${platform} protobuf_version:${CIPD_PROTOC_VERSION}
Andrew Lamb9aadbc82020-01-30 09:41:35 -070024chromiumos/infra/tools/protoc-gen-go version:${CIPD_PROTOC_GEN_GO_VERSION}
David Burgerc33d1eb2020-01-21 14:24:50 -070025ENSURE_FILE
26
27PATH="${cipd_root}:${PATH}"
28
Andrew Lamb9aadbc82020-01-30 09:41:35 -070029all_protos=(
30 chromite/infra/proto/src/chromiumos/common.proto
31 src/config/api/build_config.proto
32 src/config/api/component.proto
33 src/config/api/component_id.proto
34 src/config/api/config_bundle.proto
35 src/config/api/design.proto
36 src/config/api/design_config_id.proto
37 src/config/api/design_id.proto
38 src/config/api/device_brand.proto
39 src/config/api/device_brand_id.proto
40 src/config/api/hardware_topology.proto
41 src/config/api/partner.proto
42 src/config/api/partner_id.proto
43 src/config/api/program.proto
44 src/config/api/program_id.proto
45 src/config/api/topology.proto
46 src/third_party/chromiumos-overlay/proto/audio_config.proto
47 src/third_party/chromiumos-overlay/proto/brand_config.proto
48 src/third_party/chromiumos-overlay/proto/build_target_config_id.proto
49 src/third_party/chromiumos-overlay/proto/design_variant_config.proto
50 src/third_party/chromiumos-overlay/proto/firmware_config.proto
51 src/platform2/bluetooth/proto/config.proto
52 src/platform2/chromeos-config/proto/design_variant_id_scan_config.proto
53 src/platform2/chromeos-config/proto/brand_id_scan_config.proto
Andrew Lamb95561d82020-01-21 16:36:51 -070054 src/platform2/power_manager/config.proto
Andrew Lamb9aadbc82020-01-30 09:41:35 -070055)
56
57protoc -I../../ --descriptor_set_out=proto/descpb.bin "${all_protos[@]}"
58
59# Clean up existing generated Go files.
60find go -name '*.pb.go' -exec rm '{}' \;
61
62# Go files need to be processed individually until this is fixed:
63# https://github.com/golang/protobuf/issues/39
64for proto in "${all_protos[@]}"; do
65 # platform2 protos currently do not specify a go_package, so any proto
66 # importing them specifies an invalid import path and cannot compile.
67 # TODO(crbug.com/1046074): Compile platform2 protos once crrev.com/c/2023308
68 # is submitted.
69 if [[ $proto == src/config/* && $proto != src/config/api/build_config.proto ]]
70 then
71 protoc -I../../ --go_out=paths=source_relative:go "${proto}"
72 fi
73done
74
75cd ./go
76go test ./...