Skip to content

Commit 37ac1fd

Browse files
authored
Merge pull request #3956 from AkihiroSuda/fix-3953
make check-generated: check reproducibility of *.pb.go too
2 parents e3fb75a + b314ed8 commit 37ac1fd

File tree

8 files changed

+37
-9
lines changed

8 files changed

+37
-9
lines changed

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,8 @@ uninstall:
501501

502502
.PHONY: check-generated
503503
check-generated:
504-
@test -z "$$(git status --short | grep ".pb.desc" | tee /dev/stderr)" || \
505-
((git diff $$(find . -name '*.pb.desc') | cat) && \
506-
(echo "Please run 'make generate' when making changes to proto files and check-in the generated file changes" && false))
504+
git diff --exit-code || \
505+
(echo "Please run 'make generate' when making changes to proto files and check-in the generated file changes" && false)
507506

508507
.PHONY: lint
509508
lint: check-generated

hack/gogenerate/protoc.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh
2+
3+
# SPDX-FileCopyrightText: Copyright The Lima Authors
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
# Generate Go code from a .proto file.
7+
# Expected to be called from `//go:generate` directive.
8+
9+
set -eu
10+
if [ "$#" -ne 1 ]; then
11+
echo >&2 "Usage: $0 FILE"
12+
exit 1
13+
fi
14+
15+
PROTO="$1" ## a.proto
16+
BASE="$(basename "$PROTO" .proto)" ## a
17+
PB_DESC="${BASE}.pb.desc" ## a.pb.desc
18+
PB_GO="${BASE}.pb.go" ## a.pb.go
19+
GRPC_PB_GO="${BASE}_grpc.pb.go" ## a_grpc.pb.go
20+
21+
set -x
22+
23+
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative "$PROTO" --descriptor_set_out="$PB_DESC"
24+
25+
# -// - protoc v6.32.0
26+
# +// - protoc version [omitted for reproducibility]
27+
#
28+
# perl is used because `sed -i` is not portable across BSD (macOS) and GNU.
29+
perl -pi -E 's@(^//.*)protoc[[:blank:]]+v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+@\1protoc version [omitted for reproducibility]@g' "$PB_GO" "$GRPC_PB_GO"

pkg/driver/external/driver.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/driver/external/driver_grpc.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/driver/external/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative driver.proto --descriptor_set_out=driver.pb.desc
1+
//go:generate ../../../hack/gogenerate/protoc.sh driver.proto
22

33
// SPDX-FileCopyrightText: Copyright The Lima Authors
44
// SPDX-License-Identifier: Apache-2.0

pkg/guestagent/api/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative guestservice.proto --descriptor_set_out=guestservice.pb.desc
1+
//go:generate ../../../hack/gogenerate/protoc.sh guestservice.proto
22

33
// SPDX-FileCopyrightText: Copyright The Lima Authors
44
// SPDX-License-Identifier: Apache-2.0

pkg/guestagent/api/guestservice.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/guestagent/api/guestservice_grpc.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)