Skip to content

Commit 0aafe89

Browse files
committed
Update scripts
1 parent a222088 commit 0aafe89

File tree

11 files changed

+553
-11
lines changed

11 files changed

+553
-11
lines changed

dev/check-generated-code.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
# Copyright 2024, gRPC Authors All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -euo pipefail
18+
19+
log() { printf -- "** %s\n" "$*" >&2; }
20+
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
21+
fatal() { error "$@"; exit 1; }
22+
23+
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
24+
25+
# Re-generate everything.
26+
log "Regenerating protos..."
27+
"$here"/protos/generate.sh
28+
29+
# Check for changes.
30+
GIT_PAGER='' git diff --exit-code '*.swift'
31+
32+
log "Generated code is up-to-date"

dev/format.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ if "$lint"; then
6060
--parallel --recursive --strict \
6161
"${repo}/Sources" \
6262
"${repo}/Tests" \
63-
"${repo}/Plugins" \
64-
"${repo}/Performance/Benchmarks/Benchmarks/GRPCSwiftBenchmark" \
6563
&& SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$?
6664

6765
if [[ "${SWIFT_FORMAT_RC}" -ne 0 ]]; then
@@ -80,8 +78,6 @@ elif "$format"; then
8078
--parallel --recursive --in-place \
8179
"${repo}/Sources" \
8280
"${repo}/Tests" \
83-
"${repo}/Plugins" \
84-
"${repo}/Performance/Benchmarks/Benchmarks/GRPCSwiftBenchmark" \
8581
&& SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$?
8682

8783
if [[ "${SWIFT_FORMAT_RC}" -ne 0 ]]; then

dev/license-check.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,6 @@ check_copyright_headers() {
105105
done < <(find . -name '*.swift' \
106106
! -name '*.pb.swift' \
107107
! -name '*.grpc.swift' \
108-
! -name 'LinuxMain.swift' \
109-
! -name 'XCTestManifests.swift' \
110-
! -path './Sources/GRPCCore/Documentation.docc/*' \
111-
! -path './FuzzTesting/.build/*' \
112-
! -path './Performance/QPSBenchmark/.build/*' \
113-
! -path './Performance/Benchmarks/.build/*' \
114-
! -path './scripts/.swift-format-source/*' \
115108
! -path './.build/*')
116109
}
117110

dev/protos/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Protos
2+
3+
This directory contains proto messages used by gRPC Swift. These are split
4+
across different directories:
5+
6+
- `upstream` contains `.proto` files pulled from upstream sources. You can
7+
update them using `fetch.sh`. Note that doing so will replace `upstream` in
8+
its entirety.
9+
- `examples` contains `.proto` files used in common examples.
10+
- `tests` contains `.proto` files used in tests.
11+
12+
You can run `generate.sh` to re-generate all files generated using `protoc` with
13+
the Swift and gRPC Swift plugins.

dev/protos/fetch.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2024, gRPC Authors All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -eu
18+
19+
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
20+
upstream="$here/upstream"
21+
22+
# Create a temporary directory for the repo checkouts.
23+
checkouts="$(mktemp -d)"
24+
25+
# Clone the grpc and google protos into the staging area.
26+
git clone --depth 1 https://github.com/grpc/grpc-proto "$checkouts/grpc-proto"
27+
28+
# Remove the old protos.
29+
rm -rf "$upstream"
30+
31+
# Create new directories to poulate. These are based on proto package name
32+
# rather than source repository name.
33+
mkdir -p "$upstream/grpc/health/v1"
34+
35+
# Copy over the grpc-proto protos.
36+
cp -rp "$checkouts/grpc-proto/grpc/health/v1/health.proto" "$upstream/grpc/health/v1/health.proto"

dev/protos/generate.sh

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2024, gRPC Authors All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -eu
18+
19+
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
20+
root="$here/../.."
21+
protoc=$(which protoc)
22+
23+
# Build the protoc plugins.
24+
swift build -c release --product protoc-gen-swift
25+
swift build -c release --product protoc-gen-grpc-swift
26+
27+
# Grab the plugin paths.
28+
bin_path=$(swift build -c release --show-bin-path)
29+
protoc_gen_swift="$bin_path/protoc-gen-swift"
30+
protoc_generate_grpc_swift="$bin_path/protoc-gen-grpc-swift"
31+
32+
# Generates gRPC by invoking protoc with the gRPC Swift plugin.
33+
# Parameters:
34+
# - $1: .proto file
35+
# - $2: proto path
36+
# - $3: output path
37+
# - $4 onwards: options to forward to the plugin
38+
function generate_grpc {
39+
local proto=$1
40+
local args=("--plugin=$protoc_generate_grpc_swift" "--proto_path=${2}" "--grpc-swift_out=${3}")
41+
42+
for option in "${@:4}"; do
43+
args+=("--grpc-swift_opt=$option")
44+
done
45+
46+
invoke_protoc "${args[@]}" "$proto"
47+
}
48+
49+
# Generates messages by invoking protoc with the Swift plugin.
50+
# Parameters:
51+
# - $1: .proto file
52+
# - $2: proto path
53+
# - $3: output path
54+
# - $4 onwards: options to forward to the plugin
55+
function generate_message {
56+
local proto=$1
57+
local args=("--plugin=$protoc_gen_swift" "--proto_path=$2" "--swift_out=$3")
58+
59+
for option in "${@:4}"; do
60+
args+=("--swift_opt=$option")
61+
done
62+
63+
invoke_protoc "${args[@]}" "$proto"
64+
}
65+
66+
function invoke_protoc {
67+
# Setting -x when running the script produces a lot of output, instead boil
68+
# just echo out the protoc invocations.
69+
echo "$protoc" "$@"
70+
"$protoc" "$@"
71+
}
72+
73+
#------------------------------------------------------------------------------
74+
75+
function generate_interop_test_service {
76+
local protos=(
77+
"$here/tests/interoperability/src/proto/grpc/testing/empty_service.proto"
78+
"$here/tests/interoperability/src/proto/grpc/testing/empty.proto"
79+
"$here/tests/interoperability/src/proto/grpc/testing/messages.proto"
80+
"$here/tests/interoperability/src/proto/grpc/testing/test.proto"
81+
)
82+
local output="$root/Sources/GRPCInteropTests/Generated"
83+
84+
for proto in "${protos[@]}"; do
85+
generate_message "$proto" "$here/tests/interoperability" "$output" "Visibility=Public" "FileNaming=DropPath" "UseAccessLevelOnImports=true"
86+
generate_grpc "$proto" "$here/tests/interoperability" "$output" "Visibility=Public" "Server=true" "FileNaming=DropPath" "UseAccessLevelOnImports=true"
87+
done
88+
}
89+
90+
function generate_health_service {
91+
local proto="$here/upstream/grpc/health/v1/health.proto"
92+
local output="$root/Sources/GRPCHealthService/Generated"
93+
94+
generate_message "$proto" "$(dirname "$proto")" "$output" "Visibility=Package" "UseAccessLevelOnImports=true"
95+
generate_grpc "$proto" "$(dirname "$proto")" "$output" "Visibility=Package" "Client=true" "Server=true" "UseAccessLevelOnImports=true"
96+
}
97+
98+
#------------------------------------------------------------------------------
99+
100+
# Interoperability tests
101+
generate_interop_test_service
102+
103+
# Health service
104+
generate_health_service
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
// Copyright 2015 gRPC authors.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
syntax = "proto3";
17+
18+
package grpc.testing;
19+
20+
// An empty message that you can re-use to avoid defining duplicated empty
21+
// messages in your project. A typical example is to use it as argument or the
22+
// return value of a service API. For instance:
23+
//
24+
// service Foo {
25+
// rpc Bar (grpc.testing.Empty) returns (grpc.testing.Empty) { };
26+
// };
27+
//
28+
message Empty {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
// Copyright 2018 gRPC authors.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
syntax = "proto3";
17+
18+
package grpc.testing;
19+
20+
// A service that has zero methods.
21+
// See https://github.com/grpc/grpc/issues/15574
22+
service EmptyService {
23+
}

0 commit comments

Comments
 (0)