From 4e477a609f427a808bd458c266f0c94611f66d9c Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Tue, 21 Jan 2025 15:45:21 +0000 Subject: [PATCH 1/8] Integration tests for the build plugin Motivation: To protect against regressions in common use-cases of the grpc-swift-protobuf build plugin. Modifications: Add test cases which make use of the build plugin as a dependency and ensure that they can compile and use the generated code * top level config file * peer config file * separate service message protos * cross directory imports * two definitions * nested definitions The new tests are run as part of CI on PRs Result: More CI. --- .github/workflows/main.yml | 7 ++ .github/workflows/matrices/plugin-tests.json | 1 + .github/workflows/pull_request.yml | 7 ++ .licenseignore | 1 + .../test_01_top_level_config_file/.gitignore | 8 ++ .../Package.swift | 51 +++++++++++++ .../Sources/Protos/HelloWorld.proto | 37 ++++++++++ .../Sources/adopter.swift | 51 +++++++++++++ .../grpc-swift-proto-generator-config.json | 5 ++ .../test_02_peer_config_file/.gitignore | 8 ++ .../test_02_peer_config_file/Package.swift | 51 +++++++++++++ .../Sources/Protos/HelloWorld.proto | 37 ++++++++++ .../grpc-swift-proto-generator-config.json | 5 ++ .../Sources/adopter.swift | 51 +++++++++++++ .../.gitignore | 8 ++ .../Package.swift | 51 +++++++++++++ .../Sources/Protos/Messages.proto | 31 ++++++++ .../Sources/Protos/Service.proto | 29 ++++++++ .../grpc-swift-proto-generator-config.json | 5 ++ .../Sources/adopter.swift | 51 +++++++++++++ .../.gitignore | 8 ++ .../Package.swift | 51 +++++++++++++ .../Sources/Protos/directory_1/Messages.proto | 31 ++++++++ .../grpc-swift-proto-generator-config.json | 5 ++ .../Sources/Protos/directory_2/Service.proto | 29 ++++++++ .../grpc-swift-proto-generator-config.json | 11 +++ .../Sources/adopter.swift | 51 +++++++++++++ .../test_05_two_definitions/Package.swift | 51 +++++++++++++ .../Sources/Protos/Foo/foo-messages.proto | 1 + .../Sources/Protos/Foo/foo-service.proto | 13 ++++ .../Protos/HelloWorld/HelloWorld.proto | 37 ++++++++++ .../grpc-swift-proto-generator-config.json | 3 + .../Sources/adopter.swift | 74 +++++++++++++++++++ .../test_06_nested_definitions/Package.swift | 51 +++++++++++++ .../FooDefinitions/Foo/foo-messages.proto | 1 + .../FooDefinitions/Foo/foo-service.proto | 1 + .../grpc-swift-proto-generator-config.json | 6 ++ .../Protos/HelloWorld/HelloWorld.proto | 37 ++++++++++ .../grpc-swift-proto-generator-config.json | 6 ++ .../Sources/adopter.swift | 74 +++++++++++++++++++ dev/plugin-tests.sh | 38 ++++++++++ 41 files changed, 1074 insertions(+) create mode 100644 .github/workflows/matrices/plugin-tests.json create mode 100644 IntegrationTests/PluginTests/test_01_top_level_config_file/.gitignore create mode 100644 IntegrationTests/PluginTests/test_01_top_level_config_file/Package.swift create mode 100644 IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/Protos/HelloWorld.proto create mode 100644 IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/adopter.swift create mode 100644 IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/grpc-swift-proto-generator-config.json create mode 100644 IntegrationTests/PluginTests/test_02_peer_config_file/.gitignore create mode 100644 IntegrationTests/PluginTests/test_02_peer_config_file/Package.swift create mode 100644 IntegrationTests/PluginTests/test_02_peer_config_file/Sources/Protos/HelloWorld.proto create mode 100644 IntegrationTests/PluginTests/test_02_peer_config_file/Sources/Protos/grpc-swift-proto-generator-config.json create mode 100644 IntegrationTests/PluginTests/test_02_peer_config_file/Sources/adopter.swift create mode 100644 IntegrationTests/PluginTests/test_03_separate_service_message_protos/.gitignore create mode 100644 IntegrationTests/PluginTests/test_03_separate_service_message_protos/Package.swift create mode 100644 IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/Messages.proto create mode 100644 IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/Service.proto create mode 100644 IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/grpc-swift-proto-generator-config.json create mode 100644 IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/adopter.swift create mode 100644 IntegrationTests/PluginTests/test_04_cross_directory_imports/.gitignore create mode 100644 IntegrationTests/PluginTests/test_04_cross_directory_imports/Package.swift create mode 100644 IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_1/Messages.proto create mode 100644 IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_1/grpc-swift-proto-generator-config.json create mode 100644 IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_2/Service.proto create mode 100644 IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_2/grpc-swift-proto-generator-config.json create mode 100644 IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/adopter.swift create mode 100644 IntegrationTests/PluginTests/test_05_two_definitions/Package.swift create mode 120000 IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/Foo/foo-messages.proto create mode 100644 IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/Foo/foo-service.proto create mode 100644 IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/HelloWorld/HelloWorld.proto create mode 100644 IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/grpc-swift-proto-generator-config.json create mode 100644 IntegrationTests/PluginTests/test_05_two_definitions/Sources/adopter.swift create mode 100644 IntegrationTests/PluginTests/test_06_nested_definitions/Package.swift create mode 120000 IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/Foo/foo-messages.proto create mode 120000 IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/Foo/foo-service.proto create mode 100644 IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/grpc-swift-proto-generator-config.json create mode 100644 IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/HelloWorld.proto create mode 100644 IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/grpc-swift-proto-generator-config.json create mode 100644 IntegrationTests/PluginTests/test_06_nested_definitions/Sources/adopter.swift create mode 100755 dev/plugin-tests.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f26b60d..60d04ff 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,3 +16,10 @@ jobs: linux_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + + plugin-tests: + name: Plugin tests + uses: apple/swift-nio/.github/workflows/swift_load_test_matrix.yml@main + with: + name: "Plugin tests" + matrix_path: ".github/workflows/matrices/plugin-tests.json" diff --git a/.github/workflows/matrices/plugin-tests.json b/.github/workflows/matrices/plugin-tests.json new file mode 100644 index 0000000..d27466e --- /dev/null +++ b/.github/workflows/matrices/plugin-tests.json @@ -0,0 +1 @@ +{"config":[{"name":"Plugin tests (6.0)","swift_version":"6.0","runner":"ubuntu-latest","image":"swift:6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-6.0)","swift_version":"nightly-6.0","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-main)","swift_version":"nightly-main","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-main-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""}]} diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index a60a4c0..29c7ce8 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -26,6 +26,13 @@ jobs: linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + plugin-tests: + name: Plugin tests + uses: apple/swift-nio/.github/workflows/swift_load_test_matrix.yml@main + with: + name: "Plugin tests" + matrix_path: ".github/workflows/matrices/plugin-tests.json" + cxx-interop: name: Cxx interop uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main diff --git a/.licenseignore b/.licenseignore index 11cc071..74da854 100644 --- a/.licenseignore +++ b/.licenseignore @@ -36,6 +36,7 @@ dev/git.commit.template dev/version-bump.commit.template dev/protos/local/* dev/protos/upstream/* +IntegrationTests/PluginTests/**/*.proto .unacceptablelanguageignore LICENSE **/*.swift diff --git a/IntegrationTests/PluginTests/test_01_top_level_config_file/.gitignore b/IntegrationTests/PluginTests/test_01_top_level_config_file/.gitignore new file mode 100644 index 0000000..0023a53 --- /dev/null +++ b/IntegrationTests/PluginTests/test_01_top_level_config_file/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +/.build +/Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/IntegrationTests/PluginTests/test_01_top_level_config_file/Package.swift b/IntegrationTests/PluginTests/test_01_top_level_config_file/Package.swift new file mode 100644 index 0000000..a6fda30 --- /dev/null +++ b/IntegrationTests/PluginTests/test_01_top_level_config_file/Package.swift @@ -0,0 +1,51 @@ +// swift-tools-version: 6.0 +/* + * Copyright 2024, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import PackageDescription + +let package = Package( + name: "grpc-adopter", + platforms: [ + .macOS(.v15), + .iOS(.v18), + .tvOS(.v18), + .watchOS(.v11), + .visionOS(.v2), + ], + dependencies: [ + .package( + path: "../../../../grpc-swift-protobuf" + ), + .package( + url: "https://github.com/grpc/grpc-swift.git", + exact: "2.0.0-beta.3" + ), + ], + targets: [ + .executableTarget( + name: "grpc-adopter", + dependencies: [ + .product(name: "GRPCCore", package: "grpc-swift"), + .product(name: "GRPCInProcessTransport", package: "grpc-swift"), + .product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), + ], + plugins: [ + .plugin(name: "GRPCProtobufGenerator", package: "grpc-swift-protobuf") + ] + ) + ] +) diff --git a/IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/Protos/HelloWorld.proto b/IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/Protos/HelloWorld.proto new file mode 100644 index 0000000..32aab3a --- /dev/null +++ b/IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/Protos/HelloWorld.proto @@ -0,0 +1,37 @@ +// Copyright 2015, gRPC Authors All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.examples.helloworld"; +option java_outer_classname = "HelloWorldProto"; +option objc_class_prefix = "HLW"; + +package helloworld; + +// The greeting service definition. +service Greeter { + // Sends a greeting + rpc SayHello (HelloRequest) returns (HelloReply) {} +} + +// The request message containing the user's name. +message HelloRequest { + string name = 1; +} + +// The response message containing the greetings +message HelloReply { + string message = 1; +} diff --git a/IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/adopter.swift b/IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/adopter.swift new file mode 100644 index 0000000..8d69c5f --- /dev/null +++ b/IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/adopter.swift @@ -0,0 +1,51 @@ +/* + * Copyright 2024, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import GRPCCore +import GRPCInProcessTransport +import GRPCProtobuf + +@main +struct PluginAdopter { + static func main() async throws { + let inProcess = InProcessTransport() + try await withGRPCServer(transport: inProcess.server, services: [Greeter()]) { server in + try await withGRPCClient(transport: inProcess.client) { client in + try await Self.doRPC(Helloworld_Greeter.Client(wrapping: client)) + } + } + } + + static func doRPC(_ greeter: Helloworld_Greeter.Client) async throws { + do { + let reply = try await greeter.sayHello(.with { $0.name = "(ignored)" }) + print("Reply: \(reply.message)") + } catch { + print("Error: \(error)") + } + } +} + +struct Greeter: Helloworld_Greeter.SimpleServiceProtocol { + func sayHello( + request: Helloworld_HelloRequest, + context: ServerContext + ) async throws -> Helloworld_HelloReply { + return .with { reply in + reply.message = "Hello, world!" + } + } +} diff --git a/IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/grpc-swift-proto-generator-config.json b/IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/grpc-swift-proto-generator-config.json new file mode 100644 index 0000000..6b9ff0b --- /dev/null +++ b/IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/grpc-swift-proto-generator-config.json @@ -0,0 +1,5 @@ +{ + "generatedSource": { + "accessLevel": "internal" + } +} diff --git a/IntegrationTests/PluginTests/test_02_peer_config_file/.gitignore b/IntegrationTests/PluginTests/test_02_peer_config_file/.gitignore new file mode 100644 index 0000000..0023a53 --- /dev/null +++ b/IntegrationTests/PluginTests/test_02_peer_config_file/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +/.build +/Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/IntegrationTests/PluginTests/test_02_peer_config_file/Package.swift b/IntegrationTests/PluginTests/test_02_peer_config_file/Package.swift new file mode 100644 index 0000000..a6fda30 --- /dev/null +++ b/IntegrationTests/PluginTests/test_02_peer_config_file/Package.swift @@ -0,0 +1,51 @@ +// swift-tools-version: 6.0 +/* + * Copyright 2024, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import PackageDescription + +let package = Package( + name: "grpc-adopter", + platforms: [ + .macOS(.v15), + .iOS(.v18), + .tvOS(.v18), + .watchOS(.v11), + .visionOS(.v2), + ], + dependencies: [ + .package( + path: "../../../../grpc-swift-protobuf" + ), + .package( + url: "https://github.com/grpc/grpc-swift.git", + exact: "2.0.0-beta.3" + ), + ], + targets: [ + .executableTarget( + name: "grpc-adopter", + dependencies: [ + .product(name: "GRPCCore", package: "grpc-swift"), + .product(name: "GRPCInProcessTransport", package: "grpc-swift"), + .product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), + ], + plugins: [ + .plugin(name: "GRPCProtobufGenerator", package: "grpc-swift-protobuf") + ] + ) + ] +) diff --git a/IntegrationTests/PluginTests/test_02_peer_config_file/Sources/Protos/HelloWorld.proto b/IntegrationTests/PluginTests/test_02_peer_config_file/Sources/Protos/HelloWorld.proto new file mode 100644 index 0000000..32aab3a --- /dev/null +++ b/IntegrationTests/PluginTests/test_02_peer_config_file/Sources/Protos/HelloWorld.proto @@ -0,0 +1,37 @@ +// Copyright 2015, gRPC Authors All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.examples.helloworld"; +option java_outer_classname = "HelloWorldProto"; +option objc_class_prefix = "HLW"; + +package helloworld; + +// The greeting service definition. +service Greeter { + // Sends a greeting + rpc SayHello (HelloRequest) returns (HelloReply) {} +} + +// The request message containing the user's name. +message HelloRequest { + string name = 1; +} + +// The response message containing the greetings +message HelloReply { + string message = 1; +} diff --git a/IntegrationTests/PluginTests/test_02_peer_config_file/Sources/Protos/grpc-swift-proto-generator-config.json b/IntegrationTests/PluginTests/test_02_peer_config_file/Sources/Protos/grpc-swift-proto-generator-config.json new file mode 100644 index 0000000..6b9ff0b --- /dev/null +++ b/IntegrationTests/PluginTests/test_02_peer_config_file/Sources/Protos/grpc-swift-proto-generator-config.json @@ -0,0 +1,5 @@ +{ + "generatedSource": { + "accessLevel": "internal" + } +} diff --git a/IntegrationTests/PluginTests/test_02_peer_config_file/Sources/adopter.swift b/IntegrationTests/PluginTests/test_02_peer_config_file/Sources/adopter.swift new file mode 100644 index 0000000..8d69c5f --- /dev/null +++ b/IntegrationTests/PluginTests/test_02_peer_config_file/Sources/adopter.swift @@ -0,0 +1,51 @@ +/* + * Copyright 2024, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import GRPCCore +import GRPCInProcessTransport +import GRPCProtobuf + +@main +struct PluginAdopter { + static func main() async throws { + let inProcess = InProcessTransport() + try await withGRPCServer(transport: inProcess.server, services: [Greeter()]) { server in + try await withGRPCClient(transport: inProcess.client) { client in + try await Self.doRPC(Helloworld_Greeter.Client(wrapping: client)) + } + } + } + + static func doRPC(_ greeter: Helloworld_Greeter.Client) async throws { + do { + let reply = try await greeter.sayHello(.with { $0.name = "(ignored)" }) + print("Reply: \(reply.message)") + } catch { + print("Error: \(error)") + } + } +} + +struct Greeter: Helloworld_Greeter.SimpleServiceProtocol { + func sayHello( + request: Helloworld_HelloRequest, + context: ServerContext + ) async throws -> Helloworld_HelloReply { + return .with { reply in + reply.message = "Hello, world!" + } + } +} diff --git a/IntegrationTests/PluginTests/test_03_separate_service_message_protos/.gitignore b/IntegrationTests/PluginTests/test_03_separate_service_message_protos/.gitignore new file mode 100644 index 0000000..0023a53 --- /dev/null +++ b/IntegrationTests/PluginTests/test_03_separate_service_message_protos/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +/.build +/Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Package.swift b/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Package.swift new file mode 100644 index 0000000..a6fda30 --- /dev/null +++ b/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Package.swift @@ -0,0 +1,51 @@ +// swift-tools-version: 6.0 +/* + * Copyright 2024, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import PackageDescription + +let package = Package( + name: "grpc-adopter", + platforms: [ + .macOS(.v15), + .iOS(.v18), + .tvOS(.v18), + .watchOS(.v11), + .visionOS(.v2), + ], + dependencies: [ + .package( + path: "../../../../grpc-swift-protobuf" + ), + .package( + url: "https://github.com/grpc/grpc-swift.git", + exact: "2.0.0-beta.3" + ), + ], + targets: [ + .executableTarget( + name: "grpc-adopter", + dependencies: [ + .product(name: "GRPCCore", package: "grpc-swift"), + .product(name: "GRPCInProcessTransport", package: "grpc-swift"), + .product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), + ], + plugins: [ + .plugin(name: "GRPCProtobufGenerator", package: "grpc-swift-protobuf") + ] + ) + ] +) diff --git a/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/Messages.proto b/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/Messages.proto new file mode 100644 index 0000000..ce0db32 --- /dev/null +++ b/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/Messages.proto @@ -0,0 +1,31 @@ +// Copyright 2015, gRPC Authors All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.examples.helloworld"; +option java_outer_classname = "HelloWorldProto"; +option objc_class_prefix = "HLW"; + +package helloworld; + +// The request message containing the user's name. +message HelloRequest { + string name = 1; +} + +// The response message containing the greetings +message HelloReply { + string message = 1; +} diff --git a/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/Service.proto b/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/Service.proto new file mode 100644 index 0000000..aadc01e --- /dev/null +++ b/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/Service.proto @@ -0,0 +1,29 @@ +// Copyright 2015, gRPC Authors All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.examples.helloworld"; +option java_outer_classname = "HelloWorldProto"; +option objc_class_prefix = "HLW"; + +package helloworld; + +import "Messages.proto"; + +// The greeting service definition. +service Greeter { + // Sends a greeting + rpc SayHello (HelloRequest) returns (HelloReply) {} +} diff --git a/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/grpc-swift-proto-generator-config.json b/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/grpc-swift-proto-generator-config.json new file mode 100644 index 0000000..6b9ff0b --- /dev/null +++ b/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/grpc-swift-proto-generator-config.json @@ -0,0 +1,5 @@ +{ + "generatedSource": { + "accessLevel": "internal" + } +} diff --git a/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/adopter.swift b/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/adopter.swift new file mode 100644 index 0000000..8d69c5f --- /dev/null +++ b/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/adopter.swift @@ -0,0 +1,51 @@ +/* + * Copyright 2024, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import GRPCCore +import GRPCInProcessTransport +import GRPCProtobuf + +@main +struct PluginAdopter { + static func main() async throws { + let inProcess = InProcessTransport() + try await withGRPCServer(transport: inProcess.server, services: [Greeter()]) { server in + try await withGRPCClient(transport: inProcess.client) { client in + try await Self.doRPC(Helloworld_Greeter.Client(wrapping: client)) + } + } + } + + static func doRPC(_ greeter: Helloworld_Greeter.Client) async throws { + do { + let reply = try await greeter.sayHello(.with { $0.name = "(ignored)" }) + print("Reply: \(reply.message)") + } catch { + print("Error: \(error)") + } + } +} + +struct Greeter: Helloworld_Greeter.SimpleServiceProtocol { + func sayHello( + request: Helloworld_HelloRequest, + context: ServerContext + ) async throws -> Helloworld_HelloReply { + return .with { reply in + reply.message = "Hello, world!" + } + } +} diff --git a/IntegrationTests/PluginTests/test_04_cross_directory_imports/.gitignore b/IntegrationTests/PluginTests/test_04_cross_directory_imports/.gitignore new file mode 100644 index 0000000..0023a53 --- /dev/null +++ b/IntegrationTests/PluginTests/test_04_cross_directory_imports/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +/.build +/Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/IntegrationTests/PluginTests/test_04_cross_directory_imports/Package.swift b/IntegrationTests/PluginTests/test_04_cross_directory_imports/Package.swift new file mode 100644 index 0000000..a6fda30 --- /dev/null +++ b/IntegrationTests/PluginTests/test_04_cross_directory_imports/Package.swift @@ -0,0 +1,51 @@ +// swift-tools-version: 6.0 +/* + * Copyright 2024, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import PackageDescription + +let package = Package( + name: "grpc-adopter", + platforms: [ + .macOS(.v15), + .iOS(.v18), + .tvOS(.v18), + .watchOS(.v11), + .visionOS(.v2), + ], + dependencies: [ + .package( + path: "../../../../grpc-swift-protobuf" + ), + .package( + url: "https://github.com/grpc/grpc-swift.git", + exact: "2.0.0-beta.3" + ), + ], + targets: [ + .executableTarget( + name: "grpc-adopter", + dependencies: [ + .product(name: "GRPCCore", package: "grpc-swift"), + .product(name: "GRPCInProcessTransport", package: "grpc-swift"), + .product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), + ], + plugins: [ + .plugin(name: "GRPCProtobufGenerator", package: "grpc-swift-protobuf") + ] + ) + ] +) diff --git a/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_1/Messages.proto b/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_1/Messages.proto new file mode 100644 index 0000000..ce0db32 --- /dev/null +++ b/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_1/Messages.proto @@ -0,0 +1,31 @@ +// Copyright 2015, gRPC Authors All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.examples.helloworld"; +option java_outer_classname = "HelloWorldProto"; +option objc_class_prefix = "HLW"; + +package helloworld; + +// The request message containing the user's name. +message HelloRequest { + string name = 1; +} + +// The response message containing the greetings +message HelloReply { + string message = 1; +} diff --git a/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_1/grpc-swift-proto-generator-config.json b/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_1/grpc-swift-proto-generator-config.json new file mode 100644 index 0000000..6b9ff0b --- /dev/null +++ b/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_1/grpc-swift-proto-generator-config.json @@ -0,0 +1,5 @@ +{ + "generatedSource": { + "accessLevel": "internal" + } +} diff --git a/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_2/Service.proto b/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_2/Service.proto new file mode 100644 index 0000000..aadc01e --- /dev/null +++ b/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_2/Service.proto @@ -0,0 +1,29 @@ +// Copyright 2015, gRPC Authors All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.examples.helloworld"; +option java_outer_classname = "HelloWorldProto"; +option objc_class_prefix = "HLW"; + +package helloworld; + +import "Messages.proto"; + +// The greeting service definition. +service Greeter { + // Sends a greeting + rpc SayHello (HelloRequest) returns (HelloReply) {} +} diff --git a/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_2/grpc-swift-proto-generator-config.json b/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_2/grpc-swift-proto-generator-config.json new file mode 100644 index 0000000..4f4367e --- /dev/null +++ b/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_2/grpc-swift-proto-generator-config.json @@ -0,0 +1,11 @@ +{ + "generatedSource": { + "accessLevel": "internal" + }, + "protoc": { + "importPaths": [ + ".", + "../directory_1" + ] + } +} diff --git a/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/adopter.swift b/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/adopter.swift new file mode 100644 index 0000000..8d69c5f --- /dev/null +++ b/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/adopter.swift @@ -0,0 +1,51 @@ +/* + * Copyright 2024, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import GRPCCore +import GRPCInProcessTransport +import GRPCProtobuf + +@main +struct PluginAdopter { + static func main() async throws { + let inProcess = InProcessTransport() + try await withGRPCServer(transport: inProcess.server, services: [Greeter()]) { server in + try await withGRPCClient(transport: inProcess.client) { client in + try await Self.doRPC(Helloworld_Greeter.Client(wrapping: client)) + } + } + } + + static func doRPC(_ greeter: Helloworld_Greeter.Client) async throws { + do { + let reply = try await greeter.sayHello(.with { $0.name = "(ignored)" }) + print("Reply: \(reply.message)") + } catch { + print("Error: \(error)") + } + } +} + +struct Greeter: Helloworld_Greeter.SimpleServiceProtocol { + func sayHello( + request: Helloworld_HelloRequest, + context: ServerContext + ) async throws -> Helloworld_HelloReply { + return .with { reply in + reply.message = "Hello, world!" + } + } +} diff --git a/IntegrationTests/PluginTests/test_05_two_definitions/Package.swift b/IntegrationTests/PluginTests/test_05_two_definitions/Package.swift new file mode 100644 index 0000000..a6fda30 --- /dev/null +++ b/IntegrationTests/PluginTests/test_05_two_definitions/Package.swift @@ -0,0 +1,51 @@ +// swift-tools-version: 6.0 +/* + * Copyright 2024, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import PackageDescription + +let package = Package( + name: "grpc-adopter", + platforms: [ + .macOS(.v15), + .iOS(.v18), + .tvOS(.v18), + .watchOS(.v11), + .visionOS(.v2), + ], + dependencies: [ + .package( + path: "../../../../grpc-swift-protobuf" + ), + .package( + url: "https://github.com/grpc/grpc-swift.git", + exact: "2.0.0-beta.3" + ), + ], + targets: [ + .executableTarget( + name: "grpc-adopter", + dependencies: [ + .product(name: "GRPCCore", package: "grpc-swift"), + .product(name: "GRPCInProcessTransport", package: "grpc-swift"), + .product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), + ], + plugins: [ + .plugin(name: "GRPCProtobufGenerator", package: "grpc-swift-protobuf") + ] + ) + ] +) diff --git a/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/Foo/foo-messages.proto b/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/Foo/foo-messages.proto new file mode 120000 index 0000000..7700ad5 --- /dev/null +++ b/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/Foo/foo-messages.proto @@ -0,0 +1 @@ +../../../../../../dev/protos/local/foo-messages.proto \ No newline at end of file diff --git a/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/Foo/foo-service.proto b/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/Foo/foo-service.proto new file mode 100644 index 0000000..ac0e51e --- /dev/null +++ b/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/Foo/foo-service.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +import "Foo/foo-messages.proto"; + +package foo; + +service FooService1 { + rpc Foo (FooInput) returns (FooOutput) {} +} + +service FooService2 { + rpc Foo (FooInput) returns (FooOutput) {} +} diff --git a/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/HelloWorld/HelloWorld.proto b/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/HelloWorld/HelloWorld.proto new file mode 100644 index 0000000..32aab3a --- /dev/null +++ b/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/HelloWorld/HelloWorld.proto @@ -0,0 +1,37 @@ +// Copyright 2015, gRPC Authors All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.examples.helloworld"; +option java_outer_classname = "HelloWorldProto"; +option objc_class_prefix = "HLW"; + +package helloworld; + +// The greeting service definition. +service Greeter { + // Sends a greeting + rpc SayHello (HelloRequest) returns (HelloReply) {} +} + +// The request message containing the user's name. +message HelloRequest { + string name = 1; +} + +// The response message containing the greetings +message HelloReply { + string message = 1; +} diff --git a/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/grpc-swift-proto-generator-config.json b/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/grpc-swift-proto-generator-config.json new file mode 100644 index 0000000..b57834e --- /dev/null +++ b/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/grpc-swift-proto-generator-config.json @@ -0,0 +1,3 @@ +{ + "accessLevel": "internal" +} diff --git a/IntegrationTests/PluginTests/test_05_two_definitions/Sources/adopter.swift b/IntegrationTests/PluginTests/test_05_two_definitions/Sources/adopter.swift new file mode 100644 index 0000000..5769f82 --- /dev/null +++ b/IntegrationTests/PluginTests/test_05_two_definitions/Sources/adopter.swift @@ -0,0 +1,74 @@ +/* + * Copyright 2024, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import GRPCCore +import GRPCInProcessTransport +import GRPCProtobuf + +@main +struct PluginAdopter { + static func main() async throws { + let inProcess = InProcessTransport() + try await withGRPCServer(transport: inProcess.server, services: [Greeter()]) { server in + try await withGRPCClient(transport: inProcess.client) { client in + try await Self.doRPC(Helloworld_Greeter.Client(wrapping: client)) + } + } + + try await withGRPCServer(transport: inProcess.server, services: [FooService1()]) { server in + try await withGRPCClient(transport: inProcess.client) { client in + try await Self.doRPC(Foo_FooService1.Client(wrapping: client)) + } + } + } + + static func doRPC(_ greeter: Helloworld_Greeter.Client) async throws { + do { + let reply = try await greeter.sayHello(.with { $0.name = "(ignored)" }) + print("Reply: \(reply.message)") + } catch { + print("Error: \(error)") + } + } + + static func doRPC(_ fooService1: Foo_FooService1.Client) async throws { + do { + let reply = try await fooService1.foo(.with { _ in () }) + print("Reply: \(reply.hashValue)") + } catch { + print("Error: \(error)") + } + } +} + +struct Greeter: Helloworld_Greeter.SimpleServiceProtocol { + func sayHello( + request: Helloworld_HelloRequest, + context: ServerContext + ) async throws -> Helloworld_HelloReply { + return .with { reply in + reply.message = "Hello, world!" + } + } +} + +struct FooService1: Foo_FooService1.SimpleServiceProtocol { + func foo(request: Foo_FooInput, context: GRPCCore.ServerContext) async throws -> Foo_FooOutput { + return .with { _ in + () + } + } +} diff --git a/IntegrationTests/PluginTests/test_06_nested_definitions/Package.swift b/IntegrationTests/PluginTests/test_06_nested_definitions/Package.swift new file mode 100644 index 0000000..a6fda30 --- /dev/null +++ b/IntegrationTests/PluginTests/test_06_nested_definitions/Package.swift @@ -0,0 +1,51 @@ +// swift-tools-version: 6.0 +/* + * Copyright 2024, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import PackageDescription + +let package = Package( + name: "grpc-adopter", + platforms: [ + .macOS(.v15), + .iOS(.v18), + .tvOS(.v18), + .watchOS(.v11), + .visionOS(.v2), + ], + dependencies: [ + .package( + path: "../../../../grpc-swift-protobuf" + ), + .package( + url: "https://github.com/grpc/grpc-swift.git", + exact: "2.0.0-beta.3" + ), + ], + targets: [ + .executableTarget( + name: "grpc-adopter", + dependencies: [ + .product(name: "GRPCCore", package: "grpc-swift"), + .product(name: "GRPCInProcessTransport", package: "grpc-swift"), + .product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), + ], + plugins: [ + .plugin(name: "GRPCProtobufGenerator", package: "grpc-swift-protobuf") + ] + ) + ] +) diff --git a/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/Foo/foo-messages.proto b/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/Foo/foo-messages.proto new file mode 120000 index 0000000..c13ca07 --- /dev/null +++ b/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/Foo/foo-messages.proto @@ -0,0 +1 @@ +../../../../../../../../dev/protos/local/foo-messages.proto \ No newline at end of file diff --git a/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/Foo/foo-service.proto b/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/Foo/foo-service.proto new file mode 120000 index 0000000..6424a22 --- /dev/null +++ b/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/Foo/foo-service.proto @@ -0,0 +1 @@ +../../../../../../test_05_two_definitions/Sources/Protos/Foo/foo-service.proto \ No newline at end of file diff --git a/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/grpc-swift-proto-generator-config.json b/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/grpc-swift-proto-generator-config.json new file mode 100644 index 0000000..4a57fa1 --- /dev/null +++ b/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/grpc-swift-proto-generator-config.json @@ -0,0 +1,6 @@ +{ + "generatedSource": { + "accessLevel": "public" + } +} + diff --git a/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/HelloWorld.proto b/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/HelloWorld.proto new file mode 100644 index 0000000..32aab3a --- /dev/null +++ b/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/HelloWorld.proto @@ -0,0 +1,37 @@ +// Copyright 2015, gRPC Authors All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.examples.helloworld"; +option java_outer_classname = "HelloWorldProto"; +option objc_class_prefix = "HLW"; + +package helloworld; + +// The greeting service definition. +service Greeter { + // Sends a greeting + rpc SayHello (HelloRequest) returns (HelloReply) {} +} + +// The request message containing the user's name. +message HelloRequest { + string name = 1; +} + +// The response message containing the greetings +message HelloReply { + string message = 1; +} diff --git a/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/grpc-swift-proto-generator-config.json b/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/grpc-swift-proto-generator-config.json new file mode 100644 index 0000000..db4bbc6 --- /dev/null +++ b/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/grpc-swift-proto-generator-config.json @@ -0,0 +1,6 @@ +{ + "generatedSource": { + "accessLevel": "internal" + } +} + diff --git a/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/adopter.swift b/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/adopter.swift new file mode 100644 index 0000000..5769f82 --- /dev/null +++ b/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/adopter.swift @@ -0,0 +1,74 @@ +/* + * Copyright 2024, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import GRPCCore +import GRPCInProcessTransport +import GRPCProtobuf + +@main +struct PluginAdopter { + static func main() async throws { + let inProcess = InProcessTransport() + try await withGRPCServer(transport: inProcess.server, services: [Greeter()]) { server in + try await withGRPCClient(transport: inProcess.client) { client in + try await Self.doRPC(Helloworld_Greeter.Client(wrapping: client)) + } + } + + try await withGRPCServer(transport: inProcess.server, services: [FooService1()]) { server in + try await withGRPCClient(transport: inProcess.client) { client in + try await Self.doRPC(Foo_FooService1.Client(wrapping: client)) + } + } + } + + static func doRPC(_ greeter: Helloworld_Greeter.Client) async throws { + do { + let reply = try await greeter.sayHello(.with { $0.name = "(ignored)" }) + print("Reply: \(reply.message)") + } catch { + print("Error: \(error)") + } + } + + static func doRPC(_ fooService1: Foo_FooService1.Client) async throws { + do { + let reply = try await fooService1.foo(.with { _ in () }) + print("Reply: \(reply.hashValue)") + } catch { + print("Error: \(error)") + } + } +} + +struct Greeter: Helloworld_Greeter.SimpleServiceProtocol { + func sayHello( + request: Helloworld_HelloRequest, + context: ServerContext + ) async throws -> Helloworld_HelloReply { + return .with { reply in + reply.message = "Hello, world!" + } + } +} + +struct FooService1: Foo_FooService1.SimpleServiceProtocol { + func foo(request: Foo_FooInput, context: GRPCCore.ServerContext) async throws -> Foo_FooOutput { + return .with { _ in + () + } + } +} diff --git a/dev/plugin-tests.sh b/dev/plugin-tests.sh new file mode 100755 index 0000000..81478fa --- /dev/null +++ b/dev/plugin-tests.sh @@ -0,0 +1,38 @@ +#!/bin/bash +## Copyright 2024, gRPC Authors All rights reserved. +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. + +set -euo pipefail + +log() { printf -- "** %s\n" "$*" >&2; } +error() { printf -- "** ERROR: %s\n" "$*" >&2; } +fatal() { error "$@"; exit 1; } + +source_dir=$(pwd) +pluginTests="${source_dir}/IntegrationTests/PluginTests" + +for dir in "$pluginTests"/test_*/ ; do + if [[ -f "$dir/Package.swift" ]]; then + pluginTest=$(basename "$dir") + log "Building '$pluginTest' plugin test" + + if ! build_output=$(swift build --package-path "$dir" 2>&1); then + # Only print the build output on failure. + echo "$build_output" + fatal "Build failed for '$pluginTest'" + else + log "Build succeeded for '$pluginTest'" + fi + fi +done From 3c5b627de5c636cd7bdcc654c373fc6acea43915 Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Wed, 22 Jan 2025 06:52:49 +0000 Subject: [PATCH 2/8] review comments --- .github/workflows/matrices/plugin-tests.json | 2 +- .../test_05_two_definitions/Sources/adopter.swift | 2 +- .../Sources/adopter.swift | 2 +- dev/plugin-tests.sh | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/matrices/plugin-tests.json b/.github/workflows/matrices/plugin-tests.json index d27466e..39fee47 100644 --- a/.github/workflows/matrices/plugin-tests.json +++ b/.github/workflows/matrices/plugin-tests.json @@ -1 +1 @@ -{"config":[{"name":"Plugin tests (6.0)","swift_version":"6.0","runner":"ubuntu-latest","image":"swift:6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-6.0)","swift_version":"nightly-6.0","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-main)","swift_version":"nightly-main","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-main-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""}]} +{"config":[{"name":"Plugin tests (6.0)","swift_version":"6.0","runner":"ubuntu-latest","image":"swift:6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-6.1)","swift_version":"nightly-6.1","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-6.1-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-main)","swift_version":"nightly-main","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-main-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""}]} diff --git a/IntegrationTests/PluginTests/test_05_two_definitions/Sources/adopter.swift b/IntegrationTests/PluginTests/test_05_two_definitions/Sources/adopter.swift index 5769f82..ce95cd1 100644 --- a/IntegrationTests/PluginTests/test_05_two_definitions/Sources/adopter.swift +++ b/IntegrationTests/PluginTests/test_05_two_definitions/Sources/adopter.swift @@ -44,7 +44,7 @@ struct PluginAdopter { } } - static func doRPC(_ fooService1: Foo_FooService1.Client) async throws { + static func doRPC(_ fooService1: Foo_FooService1.Client) async throws { do { let reply = try await fooService1.foo(.with { _ in () }) print("Reply: \(reply.hashValue)") diff --git a/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/adopter.swift b/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/adopter.swift index 5769f82..ce95cd1 100644 --- a/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/adopter.swift +++ b/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/adopter.swift @@ -44,7 +44,7 @@ struct PluginAdopter { } } - static func doRPC(_ fooService1: Foo_FooService1.Client) async throws { + static func doRPC(_ fooService1: Foo_FooService1.Client) async throws { do { let reply = try await fooService1.foo(.with { _ in () }) print("Reply: \(reply.hashValue)") diff --git a/dev/plugin-tests.sh b/dev/plugin-tests.sh index 81478fa..9041faf 100755 --- a/dev/plugin-tests.sh +++ b/dev/plugin-tests.sh @@ -19,20 +19,20 @@ log() { printf -- "** %s\n" "$*" >&2; } error() { printf -- "** ERROR: %s\n" "$*" >&2; } fatal() { error "$@"; exit 1; } -source_dir=$(pwd) -pluginTests="${source_dir}/IntegrationTests/PluginTests" +here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +plugin_tests="${here}/../IntegrationTests/PluginTests" -for dir in "$pluginTests"/test_*/ ; do +for dir in "$plugin_tests"/test_*/ ; do if [[ -f "$dir/Package.swift" ]]; then - pluginTest=$(basename "$dir") - log "Building '$pluginTest' plugin test" + plugin_test=$(basename "$dir") + log "Building '$plugin_test' plugin test" if ! build_output=$(swift build --package-path "$dir" 2>&1); then # Only print the build output on failure. echo "$build_output" - fatal "Build failed for '$pluginTest'" + fatal "Build failed for '$plugin_test'" else - log "Build succeeded for '$pluginTest'" + log "Build succeeded for '$plugin_test'" fi fi done From e2d4cab3465d690ce62ec18394ee1104af5c0ff0 Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Thu, 23 Jan 2025 08:39:51 +0000 Subject: [PATCH 3/8] dynamically create plugin tests --- .github/workflows/matrices/plugin-tests.json | 2 +- .../Resources/Foo/foo-messages.proto | 7 ++ .../Foo/foo-service.proto | 0 .../FooHelloWorldAdopter.swift} | 0 .../HelloWorld}/HelloWorld.proto | 0 .../HelloWorld}/Messages.proto | 0 .../HelloWorld}/Service.proto | 0 .../HelloWorldAdopter.swift} | 0 .../Package.swift | 9 +- ...-1-grpc-swift-proto-generator-config.json} | 0 ...al-grpc-swift-proto-generator-config.json} | 0 ...ic-grpc-swift-proto-generator-config.json} | 0 .../test_01_top_level_config_file/.gitignore | 8 -- .../Package.swift | 51 ---------- .../test_02_peer_config_file/.gitignore | 8 -- .../test_02_peer_config_file/Package.swift | 51 ---------- .../Sources/Protos/HelloWorld.proto | 37 ------- .../grpc-swift-proto-generator-config.json | 5 - .../Sources/adopter.swift | 51 ---------- .../.gitignore | 8 -- .../grpc-swift-proto-generator-config.json | 5 - .../Sources/adopter.swift | 51 ---------- .../.gitignore | 8 -- .../Package.swift | 51 ---------- .../Sources/Protos/directory_1/Messages.proto | 31 ------ .../grpc-swift-proto-generator-config.json | 5 - .../Sources/Protos/directory_2/Service.proto | 29 ------ .../Sources/adopter.swift | 51 ---------- .../test_05_two_definitions/Package.swift | 51 ---------- .../Sources/Protos/Foo/foo-messages.proto | 1 - .../Protos/HelloWorld/HelloWorld.proto | 37 ------- .../grpc-swift-proto-generator-config.json | 3 - .../test_06_nested_definitions/Package.swift | 51 ---------- .../FooDefinitions/Foo/foo-messages.proto | 1 - .../FooDefinitions/Foo/foo-service.proto | 1 - .../Protos/HelloWorld/HelloWorld.proto | 37 ------- .../grpc-swift-proto-generator-config.json | 6 -- .../Sources/adopter.swift | 74 -------------- dev/execute-plugin-tests.sh | 40 ++++++++ dev/plugin-tests.sh | 20 +--- dev/setup-plugin-tests.sh | 96 +++++++++++++++++++ 41 files changed, 152 insertions(+), 734 deletions(-) create mode 100644 IntegrationTests/PluginTests/Resources/Foo/foo-messages.proto rename IntegrationTests/PluginTests/{test_05_two_definitions/Sources/Protos => Resources}/Foo/foo-service.proto (100%) rename IntegrationTests/PluginTests/{test_05_two_definitions/Sources/adopter.swift => Resources/FooHelloWorldAdopter.swift} (100%) rename IntegrationTests/PluginTests/{test_01_top_level_config_file/Sources/Protos => Resources/HelloWorld}/HelloWorld.proto (100%) rename IntegrationTests/PluginTests/{test_03_separate_service_message_protos/Sources/Protos => Resources/HelloWorld}/Messages.proto (100%) rename IntegrationTests/PluginTests/{test_03_separate_service_message_protos/Sources/Protos => Resources/HelloWorld}/Service.proto (100%) rename IntegrationTests/PluginTests/{test_01_top_level_config_file/Sources/adopter.swift => Resources/HelloWorldAdopter.swift} (100%) rename IntegrationTests/PluginTests/{test_03_separate_service_message_protos => Resources}/Package.swift (91%) rename IntegrationTests/PluginTests/{test_04_cross_directory_imports/Sources/Protos/directory_2/grpc-swift-proto-generator-config.json => Resources/import-directory-1-grpc-swift-proto-generator-config.json} (100%) rename IntegrationTests/PluginTests/{test_01_top_level_config_file/Sources/grpc-swift-proto-generator-config.json => Resources/internal-grpc-swift-proto-generator-config.json} (100%) rename IntegrationTests/PluginTests/{test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/grpc-swift-proto-generator-config.json => Resources/public-grpc-swift-proto-generator-config.json} (100%) delete mode 100644 IntegrationTests/PluginTests/test_01_top_level_config_file/.gitignore delete mode 100644 IntegrationTests/PluginTests/test_01_top_level_config_file/Package.swift delete mode 100644 IntegrationTests/PluginTests/test_02_peer_config_file/.gitignore delete mode 100644 IntegrationTests/PluginTests/test_02_peer_config_file/Package.swift delete mode 100644 IntegrationTests/PluginTests/test_02_peer_config_file/Sources/Protos/HelloWorld.proto delete mode 100644 IntegrationTests/PluginTests/test_02_peer_config_file/Sources/Protos/grpc-swift-proto-generator-config.json delete mode 100644 IntegrationTests/PluginTests/test_02_peer_config_file/Sources/adopter.swift delete mode 100644 IntegrationTests/PluginTests/test_03_separate_service_message_protos/.gitignore delete mode 100644 IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/grpc-swift-proto-generator-config.json delete mode 100644 IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/adopter.swift delete mode 100644 IntegrationTests/PluginTests/test_04_cross_directory_imports/.gitignore delete mode 100644 IntegrationTests/PluginTests/test_04_cross_directory_imports/Package.swift delete mode 100644 IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_1/Messages.proto delete mode 100644 IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_1/grpc-swift-proto-generator-config.json delete mode 100644 IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_2/Service.proto delete mode 100644 IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/adopter.swift delete mode 100644 IntegrationTests/PluginTests/test_05_two_definitions/Package.swift delete mode 120000 IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/Foo/foo-messages.proto delete mode 100644 IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/HelloWorld/HelloWorld.proto delete mode 100644 IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/grpc-swift-proto-generator-config.json delete mode 100644 IntegrationTests/PluginTests/test_06_nested_definitions/Package.swift delete mode 120000 IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/Foo/foo-messages.proto delete mode 120000 IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/Foo/foo-service.proto delete mode 100644 IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/HelloWorld.proto delete mode 100644 IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/grpc-swift-proto-generator-config.json delete mode 100644 IntegrationTests/PluginTests/test_06_nested_definitions/Sources/adopter.swift create mode 100755 dev/execute-plugin-tests.sh create mode 100755 dev/setup-plugin-tests.sh diff --git a/.github/workflows/matrices/plugin-tests.json b/.github/workflows/matrices/plugin-tests.json index 39fee47..9295a07 100644 --- a/.github/workflows/matrices/plugin-tests.json +++ b/.github/workflows/matrices/plugin-tests.json @@ -1 +1 @@ -{"config":[{"name":"Plugin tests (6.0)","swift_version":"6.0","runner":"ubuntu-latest","image":"swift:6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-6.1)","swift_version":"nightly-6.1","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-6.1-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-main)","swift_version":"nightly-main","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-main-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""}]} +{"config":[{"name":"Plugin tests (6.0)","swift_version":"6.0","runner":"ubuntu-latest","image":"swift:6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s http://raw.githubusercontent.com/grpc/grpc-swift-protobuf/main/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-6.1)","swift_version":"nightly-6.1","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-6.1-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s http://raw.githubusercontent.com/grpc/grpc-swift-protobuf/main/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-main)","swift_version":"nightly-main","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-main-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s http://raw.githubusercontent.com/grpc/grpc-swift-protobuf/main/dev/plugin-tests.sh | bash","command_arguments":""}]} diff --git a/IntegrationTests/PluginTests/Resources/Foo/foo-messages.proto b/IntegrationTests/PluginTests/Resources/Foo/foo-messages.proto new file mode 100644 index 0000000..bc79d13 --- /dev/null +++ b/IntegrationTests/PluginTests/Resources/Foo/foo-messages.proto @@ -0,0 +1,7 @@ +// Leading trivia. +syntax = "proto3"; + +package foo; + +message FooInput {} +message FooOutput {} diff --git a/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/Foo/foo-service.proto b/IntegrationTests/PluginTests/Resources/Foo/foo-service.proto similarity index 100% rename from IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/Foo/foo-service.proto rename to IntegrationTests/PluginTests/Resources/Foo/foo-service.proto diff --git a/IntegrationTests/PluginTests/test_05_two_definitions/Sources/adopter.swift b/IntegrationTests/PluginTests/Resources/FooHelloWorldAdopter.swift similarity index 100% rename from IntegrationTests/PluginTests/test_05_two_definitions/Sources/adopter.swift rename to IntegrationTests/PluginTests/Resources/FooHelloWorldAdopter.swift diff --git a/IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/Protos/HelloWorld.proto b/IntegrationTests/PluginTests/Resources/HelloWorld/HelloWorld.proto similarity index 100% rename from IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/Protos/HelloWorld.proto rename to IntegrationTests/PluginTests/Resources/HelloWorld/HelloWorld.proto diff --git a/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/Messages.proto b/IntegrationTests/PluginTests/Resources/HelloWorld/Messages.proto similarity index 100% rename from IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/Messages.proto rename to IntegrationTests/PluginTests/Resources/HelloWorld/Messages.proto diff --git a/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/Service.proto b/IntegrationTests/PluginTests/Resources/HelloWorld/Service.proto similarity index 100% rename from IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/Service.proto rename to IntegrationTests/PluginTests/Resources/HelloWorld/Service.proto diff --git a/IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/adopter.swift b/IntegrationTests/PluginTests/Resources/HelloWorldAdopter.swift similarity index 100% rename from IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/adopter.swift rename to IntegrationTests/PluginTests/Resources/HelloWorldAdopter.swift diff --git a/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Package.swift b/IntegrationTests/PluginTests/Resources/Package.swift similarity index 91% rename from IntegrationTests/PluginTests/test_03_separate_service_message_protos/Package.swift rename to IntegrationTests/PluginTests/Resources/Package.swift index a6fda30..3482097 100644 --- a/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Package.swift +++ b/IntegrationTests/PluginTests/Resources/Package.swift @@ -17,7 +17,7 @@ import PackageDescription -let package = Package( +var package = Package( name: "grpc-adopter", platforms: [ .macOS(.v15), @@ -27,12 +27,11 @@ let package = Package( .visionOS(.v2), ], dependencies: [ - .package( - path: "../../../../grpc-swift-protobuf" - ), + // Dependency on grpc-swift-protobuf to be added by setup-plugin-tests.sh script + .package( url: "https://github.com/grpc/grpc-swift.git", - exact: "2.0.0-beta.3" + branch: "main" ), ], targets: [ diff --git a/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_2/grpc-swift-proto-generator-config.json b/IntegrationTests/PluginTests/Resources/import-directory-1-grpc-swift-proto-generator-config.json similarity index 100% rename from IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_2/grpc-swift-proto-generator-config.json rename to IntegrationTests/PluginTests/Resources/import-directory-1-grpc-swift-proto-generator-config.json diff --git a/IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/grpc-swift-proto-generator-config.json b/IntegrationTests/PluginTests/Resources/internal-grpc-swift-proto-generator-config.json similarity index 100% rename from IntegrationTests/PluginTests/test_01_top_level_config_file/Sources/grpc-swift-proto-generator-config.json rename to IntegrationTests/PluginTests/Resources/internal-grpc-swift-proto-generator-config.json diff --git a/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/grpc-swift-proto-generator-config.json b/IntegrationTests/PluginTests/Resources/public-grpc-swift-proto-generator-config.json similarity index 100% rename from IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/grpc-swift-proto-generator-config.json rename to IntegrationTests/PluginTests/Resources/public-grpc-swift-proto-generator-config.json diff --git a/IntegrationTests/PluginTests/test_01_top_level_config_file/.gitignore b/IntegrationTests/PluginTests/test_01_top_level_config_file/.gitignore deleted file mode 100644 index 0023a53..0000000 --- a/IntegrationTests/PluginTests/test_01_top_level_config_file/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -.DS_Store -/.build -/Packages -xcuserdata/ -DerivedData/ -.swiftpm/configuration/registries.json -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc diff --git a/IntegrationTests/PluginTests/test_01_top_level_config_file/Package.swift b/IntegrationTests/PluginTests/test_01_top_level_config_file/Package.swift deleted file mode 100644 index a6fda30..0000000 --- a/IntegrationTests/PluginTests/test_01_top_level_config_file/Package.swift +++ /dev/null @@ -1,51 +0,0 @@ -// swift-tools-version: 6.0 -/* - * Copyright 2024, gRPC Authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import PackageDescription - -let package = Package( - name: "grpc-adopter", - platforms: [ - .macOS(.v15), - .iOS(.v18), - .tvOS(.v18), - .watchOS(.v11), - .visionOS(.v2), - ], - dependencies: [ - .package( - path: "../../../../grpc-swift-protobuf" - ), - .package( - url: "https://github.com/grpc/grpc-swift.git", - exact: "2.0.0-beta.3" - ), - ], - targets: [ - .executableTarget( - name: "grpc-adopter", - dependencies: [ - .product(name: "GRPCCore", package: "grpc-swift"), - .product(name: "GRPCInProcessTransport", package: "grpc-swift"), - .product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), - ], - plugins: [ - .plugin(name: "GRPCProtobufGenerator", package: "grpc-swift-protobuf") - ] - ) - ] -) diff --git a/IntegrationTests/PluginTests/test_02_peer_config_file/.gitignore b/IntegrationTests/PluginTests/test_02_peer_config_file/.gitignore deleted file mode 100644 index 0023a53..0000000 --- a/IntegrationTests/PluginTests/test_02_peer_config_file/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -.DS_Store -/.build -/Packages -xcuserdata/ -DerivedData/ -.swiftpm/configuration/registries.json -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc diff --git a/IntegrationTests/PluginTests/test_02_peer_config_file/Package.swift b/IntegrationTests/PluginTests/test_02_peer_config_file/Package.swift deleted file mode 100644 index a6fda30..0000000 --- a/IntegrationTests/PluginTests/test_02_peer_config_file/Package.swift +++ /dev/null @@ -1,51 +0,0 @@ -// swift-tools-version: 6.0 -/* - * Copyright 2024, gRPC Authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import PackageDescription - -let package = Package( - name: "grpc-adopter", - platforms: [ - .macOS(.v15), - .iOS(.v18), - .tvOS(.v18), - .watchOS(.v11), - .visionOS(.v2), - ], - dependencies: [ - .package( - path: "../../../../grpc-swift-protobuf" - ), - .package( - url: "https://github.com/grpc/grpc-swift.git", - exact: "2.0.0-beta.3" - ), - ], - targets: [ - .executableTarget( - name: "grpc-adopter", - dependencies: [ - .product(name: "GRPCCore", package: "grpc-swift"), - .product(name: "GRPCInProcessTransport", package: "grpc-swift"), - .product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), - ], - plugins: [ - .plugin(name: "GRPCProtobufGenerator", package: "grpc-swift-protobuf") - ] - ) - ] -) diff --git a/IntegrationTests/PluginTests/test_02_peer_config_file/Sources/Protos/HelloWorld.proto b/IntegrationTests/PluginTests/test_02_peer_config_file/Sources/Protos/HelloWorld.proto deleted file mode 100644 index 32aab3a..0000000 --- a/IntegrationTests/PluginTests/test_02_peer_config_file/Sources/Protos/HelloWorld.proto +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2015, gRPC Authors All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -syntax = "proto3"; - -option java_multiple_files = true; -option java_package = "io.grpc.examples.helloworld"; -option java_outer_classname = "HelloWorldProto"; -option objc_class_prefix = "HLW"; - -package helloworld; - -// The greeting service definition. -service Greeter { - // Sends a greeting - rpc SayHello (HelloRequest) returns (HelloReply) {} -} - -// The request message containing the user's name. -message HelloRequest { - string name = 1; -} - -// The response message containing the greetings -message HelloReply { - string message = 1; -} diff --git a/IntegrationTests/PluginTests/test_02_peer_config_file/Sources/Protos/grpc-swift-proto-generator-config.json b/IntegrationTests/PluginTests/test_02_peer_config_file/Sources/Protos/grpc-swift-proto-generator-config.json deleted file mode 100644 index 6b9ff0b..0000000 --- a/IntegrationTests/PluginTests/test_02_peer_config_file/Sources/Protos/grpc-swift-proto-generator-config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "generatedSource": { - "accessLevel": "internal" - } -} diff --git a/IntegrationTests/PluginTests/test_02_peer_config_file/Sources/adopter.swift b/IntegrationTests/PluginTests/test_02_peer_config_file/Sources/adopter.swift deleted file mode 100644 index 8d69c5f..0000000 --- a/IntegrationTests/PluginTests/test_02_peer_config_file/Sources/adopter.swift +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2024, gRPC Authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import GRPCCore -import GRPCInProcessTransport -import GRPCProtobuf - -@main -struct PluginAdopter { - static func main() async throws { - let inProcess = InProcessTransport() - try await withGRPCServer(transport: inProcess.server, services: [Greeter()]) { server in - try await withGRPCClient(transport: inProcess.client) { client in - try await Self.doRPC(Helloworld_Greeter.Client(wrapping: client)) - } - } - } - - static func doRPC(_ greeter: Helloworld_Greeter.Client) async throws { - do { - let reply = try await greeter.sayHello(.with { $0.name = "(ignored)" }) - print("Reply: \(reply.message)") - } catch { - print("Error: \(error)") - } - } -} - -struct Greeter: Helloworld_Greeter.SimpleServiceProtocol { - func sayHello( - request: Helloworld_HelloRequest, - context: ServerContext - ) async throws -> Helloworld_HelloReply { - return .with { reply in - reply.message = "Hello, world!" - } - } -} diff --git a/IntegrationTests/PluginTests/test_03_separate_service_message_protos/.gitignore b/IntegrationTests/PluginTests/test_03_separate_service_message_protos/.gitignore deleted file mode 100644 index 0023a53..0000000 --- a/IntegrationTests/PluginTests/test_03_separate_service_message_protos/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -.DS_Store -/.build -/Packages -xcuserdata/ -DerivedData/ -.swiftpm/configuration/registries.json -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc diff --git a/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/grpc-swift-proto-generator-config.json b/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/grpc-swift-proto-generator-config.json deleted file mode 100644 index 6b9ff0b..0000000 --- a/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/Protos/grpc-swift-proto-generator-config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "generatedSource": { - "accessLevel": "internal" - } -} diff --git a/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/adopter.swift b/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/adopter.swift deleted file mode 100644 index 8d69c5f..0000000 --- a/IntegrationTests/PluginTests/test_03_separate_service_message_protos/Sources/adopter.swift +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2024, gRPC Authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import GRPCCore -import GRPCInProcessTransport -import GRPCProtobuf - -@main -struct PluginAdopter { - static func main() async throws { - let inProcess = InProcessTransport() - try await withGRPCServer(transport: inProcess.server, services: [Greeter()]) { server in - try await withGRPCClient(transport: inProcess.client) { client in - try await Self.doRPC(Helloworld_Greeter.Client(wrapping: client)) - } - } - } - - static func doRPC(_ greeter: Helloworld_Greeter.Client) async throws { - do { - let reply = try await greeter.sayHello(.with { $0.name = "(ignored)" }) - print("Reply: \(reply.message)") - } catch { - print("Error: \(error)") - } - } -} - -struct Greeter: Helloworld_Greeter.SimpleServiceProtocol { - func sayHello( - request: Helloworld_HelloRequest, - context: ServerContext - ) async throws -> Helloworld_HelloReply { - return .with { reply in - reply.message = "Hello, world!" - } - } -} diff --git a/IntegrationTests/PluginTests/test_04_cross_directory_imports/.gitignore b/IntegrationTests/PluginTests/test_04_cross_directory_imports/.gitignore deleted file mode 100644 index 0023a53..0000000 --- a/IntegrationTests/PluginTests/test_04_cross_directory_imports/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -.DS_Store -/.build -/Packages -xcuserdata/ -DerivedData/ -.swiftpm/configuration/registries.json -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc diff --git a/IntegrationTests/PluginTests/test_04_cross_directory_imports/Package.swift b/IntegrationTests/PluginTests/test_04_cross_directory_imports/Package.swift deleted file mode 100644 index a6fda30..0000000 --- a/IntegrationTests/PluginTests/test_04_cross_directory_imports/Package.swift +++ /dev/null @@ -1,51 +0,0 @@ -// swift-tools-version: 6.0 -/* - * Copyright 2024, gRPC Authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import PackageDescription - -let package = Package( - name: "grpc-adopter", - platforms: [ - .macOS(.v15), - .iOS(.v18), - .tvOS(.v18), - .watchOS(.v11), - .visionOS(.v2), - ], - dependencies: [ - .package( - path: "../../../../grpc-swift-protobuf" - ), - .package( - url: "https://github.com/grpc/grpc-swift.git", - exact: "2.0.0-beta.3" - ), - ], - targets: [ - .executableTarget( - name: "grpc-adopter", - dependencies: [ - .product(name: "GRPCCore", package: "grpc-swift"), - .product(name: "GRPCInProcessTransport", package: "grpc-swift"), - .product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), - ], - plugins: [ - .plugin(name: "GRPCProtobufGenerator", package: "grpc-swift-protobuf") - ] - ) - ] -) diff --git a/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_1/Messages.proto b/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_1/Messages.proto deleted file mode 100644 index ce0db32..0000000 --- a/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_1/Messages.proto +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2015, gRPC Authors All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -syntax = "proto3"; - -option java_multiple_files = true; -option java_package = "io.grpc.examples.helloworld"; -option java_outer_classname = "HelloWorldProto"; -option objc_class_prefix = "HLW"; - -package helloworld; - -// The request message containing the user's name. -message HelloRequest { - string name = 1; -} - -// The response message containing the greetings -message HelloReply { - string message = 1; -} diff --git a/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_1/grpc-swift-proto-generator-config.json b/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_1/grpc-swift-proto-generator-config.json deleted file mode 100644 index 6b9ff0b..0000000 --- a/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_1/grpc-swift-proto-generator-config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "generatedSource": { - "accessLevel": "internal" - } -} diff --git a/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_2/Service.proto b/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_2/Service.proto deleted file mode 100644 index aadc01e..0000000 --- a/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/Protos/directory_2/Service.proto +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2015, gRPC Authors All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -syntax = "proto3"; - -option java_multiple_files = true; -option java_package = "io.grpc.examples.helloworld"; -option java_outer_classname = "HelloWorldProto"; -option objc_class_prefix = "HLW"; - -package helloworld; - -import "Messages.proto"; - -// The greeting service definition. -service Greeter { - // Sends a greeting - rpc SayHello (HelloRequest) returns (HelloReply) {} -} diff --git a/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/adopter.swift b/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/adopter.swift deleted file mode 100644 index 8d69c5f..0000000 --- a/IntegrationTests/PluginTests/test_04_cross_directory_imports/Sources/adopter.swift +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2024, gRPC Authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import GRPCCore -import GRPCInProcessTransport -import GRPCProtobuf - -@main -struct PluginAdopter { - static func main() async throws { - let inProcess = InProcessTransport() - try await withGRPCServer(transport: inProcess.server, services: [Greeter()]) { server in - try await withGRPCClient(transport: inProcess.client) { client in - try await Self.doRPC(Helloworld_Greeter.Client(wrapping: client)) - } - } - } - - static func doRPC(_ greeter: Helloworld_Greeter.Client) async throws { - do { - let reply = try await greeter.sayHello(.with { $0.name = "(ignored)" }) - print("Reply: \(reply.message)") - } catch { - print("Error: \(error)") - } - } -} - -struct Greeter: Helloworld_Greeter.SimpleServiceProtocol { - func sayHello( - request: Helloworld_HelloRequest, - context: ServerContext - ) async throws -> Helloworld_HelloReply { - return .with { reply in - reply.message = "Hello, world!" - } - } -} diff --git a/IntegrationTests/PluginTests/test_05_two_definitions/Package.swift b/IntegrationTests/PluginTests/test_05_two_definitions/Package.swift deleted file mode 100644 index a6fda30..0000000 --- a/IntegrationTests/PluginTests/test_05_two_definitions/Package.swift +++ /dev/null @@ -1,51 +0,0 @@ -// swift-tools-version: 6.0 -/* - * Copyright 2024, gRPC Authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import PackageDescription - -let package = Package( - name: "grpc-adopter", - platforms: [ - .macOS(.v15), - .iOS(.v18), - .tvOS(.v18), - .watchOS(.v11), - .visionOS(.v2), - ], - dependencies: [ - .package( - path: "../../../../grpc-swift-protobuf" - ), - .package( - url: "https://github.com/grpc/grpc-swift.git", - exact: "2.0.0-beta.3" - ), - ], - targets: [ - .executableTarget( - name: "grpc-adopter", - dependencies: [ - .product(name: "GRPCCore", package: "grpc-swift"), - .product(name: "GRPCInProcessTransport", package: "grpc-swift"), - .product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), - ], - plugins: [ - .plugin(name: "GRPCProtobufGenerator", package: "grpc-swift-protobuf") - ] - ) - ] -) diff --git a/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/Foo/foo-messages.proto b/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/Foo/foo-messages.proto deleted file mode 120000 index 7700ad5..0000000 --- a/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/Foo/foo-messages.proto +++ /dev/null @@ -1 +0,0 @@ -../../../../../../dev/protos/local/foo-messages.proto \ No newline at end of file diff --git a/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/HelloWorld/HelloWorld.proto b/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/HelloWorld/HelloWorld.proto deleted file mode 100644 index 32aab3a..0000000 --- a/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/HelloWorld/HelloWorld.proto +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2015, gRPC Authors All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -syntax = "proto3"; - -option java_multiple_files = true; -option java_package = "io.grpc.examples.helloworld"; -option java_outer_classname = "HelloWorldProto"; -option objc_class_prefix = "HLW"; - -package helloworld; - -// The greeting service definition. -service Greeter { - // Sends a greeting - rpc SayHello (HelloRequest) returns (HelloReply) {} -} - -// The request message containing the user's name. -message HelloRequest { - string name = 1; -} - -// The response message containing the greetings -message HelloReply { - string message = 1; -} diff --git a/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/grpc-swift-proto-generator-config.json b/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/grpc-swift-proto-generator-config.json deleted file mode 100644 index b57834e..0000000 --- a/IntegrationTests/PluginTests/test_05_two_definitions/Sources/Protos/grpc-swift-proto-generator-config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "accessLevel": "internal" -} diff --git a/IntegrationTests/PluginTests/test_06_nested_definitions/Package.swift b/IntegrationTests/PluginTests/test_06_nested_definitions/Package.swift deleted file mode 100644 index a6fda30..0000000 --- a/IntegrationTests/PluginTests/test_06_nested_definitions/Package.swift +++ /dev/null @@ -1,51 +0,0 @@ -// swift-tools-version: 6.0 -/* - * Copyright 2024, gRPC Authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import PackageDescription - -let package = Package( - name: "grpc-adopter", - platforms: [ - .macOS(.v15), - .iOS(.v18), - .tvOS(.v18), - .watchOS(.v11), - .visionOS(.v2), - ], - dependencies: [ - .package( - path: "../../../../grpc-swift-protobuf" - ), - .package( - url: "https://github.com/grpc/grpc-swift.git", - exact: "2.0.0-beta.3" - ), - ], - targets: [ - .executableTarget( - name: "grpc-adopter", - dependencies: [ - .product(name: "GRPCCore", package: "grpc-swift"), - .product(name: "GRPCInProcessTransport", package: "grpc-swift"), - .product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"), - ], - plugins: [ - .plugin(name: "GRPCProtobufGenerator", package: "grpc-swift-protobuf") - ] - ) - ] -) diff --git a/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/Foo/foo-messages.proto b/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/Foo/foo-messages.proto deleted file mode 120000 index c13ca07..0000000 --- a/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/Foo/foo-messages.proto +++ /dev/null @@ -1 +0,0 @@ -../../../../../../../../dev/protos/local/foo-messages.proto \ No newline at end of file diff --git a/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/Foo/foo-service.proto b/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/Foo/foo-service.proto deleted file mode 120000 index 6424a22..0000000 --- a/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/FooDefinitions/Foo/foo-service.proto +++ /dev/null @@ -1 +0,0 @@ -../../../../../../test_05_two_definitions/Sources/Protos/Foo/foo-service.proto \ No newline at end of file diff --git a/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/HelloWorld.proto b/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/HelloWorld.proto deleted file mode 100644 index 32aab3a..0000000 --- a/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/HelloWorld.proto +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2015, gRPC Authors All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -syntax = "proto3"; - -option java_multiple_files = true; -option java_package = "io.grpc.examples.helloworld"; -option java_outer_classname = "HelloWorldProto"; -option objc_class_prefix = "HLW"; - -package helloworld; - -// The greeting service definition. -service Greeter { - // Sends a greeting - rpc SayHello (HelloRequest) returns (HelloReply) {} -} - -// The request message containing the user's name. -message HelloRequest { - string name = 1; -} - -// The response message containing the greetings -message HelloReply { - string message = 1; -} diff --git a/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/grpc-swift-proto-generator-config.json b/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/grpc-swift-proto-generator-config.json deleted file mode 100644 index db4bbc6..0000000 --- a/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/Protos/HelloWorld/grpc-swift-proto-generator-config.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "generatedSource": { - "accessLevel": "internal" - } -} - diff --git a/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/adopter.swift b/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/adopter.swift deleted file mode 100644 index ce95cd1..0000000 --- a/IntegrationTests/PluginTests/test_06_nested_definitions/Sources/adopter.swift +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2024, gRPC Authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import GRPCCore -import GRPCInProcessTransport -import GRPCProtobuf - -@main -struct PluginAdopter { - static func main() async throws { - let inProcess = InProcessTransport() - try await withGRPCServer(transport: inProcess.server, services: [Greeter()]) { server in - try await withGRPCClient(transport: inProcess.client) { client in - try await Self.doRPC(Helloworld_Greeter.Client(wrapping: client)) - } - } - - try await withGRPCServer(transport: inProcess.server, services: [FooService1()]) { server in - try await withGRPCClient(transport: inProcess.client) { client in - try await Self.doRPC(Foo_FooService1.Client(wrapping: client)) - } - } - } - - static func doRPC(_ greeter: Helloworld_Greeter.Client) async throws { - do { - let reply = try await greeter.sayHello(.with { $0.name = "(ignored)" }) - print("Reply: \(reply.message)") - } catch { - print("Error: \(error)") - } - } - - static func doRPC(_ fooService1: Foo_FooService1.Client) async throws { - do { - let reply = try await fooService1.foo(.with { _ in () }) - print("Reply: \(reply.hashValue)") - } catch { - print("Error: \(error)") - } - } -} - -struct Greeter: Helloworld_Greeter.SimpleServiceProtocol { - func sayHello( - request: Helloworld_HelloRequest, - context: ServerContext - ) async throws -> Helloworld_HelloReply { - return .with { reply in - reply.message = "Hello, world!" - } - } -} - -struct FooService1: Foo_FooService1.SimpleServiceProtocol { - func foo(request: Foo_FooInput, context: GRPCCore.ServerContext) async throws -> Foo_FooOutput { - return .with { _ in - () - } - } -} diff --git a/dev/execute-plugin-tests.sh b/dev/execute-plugin-tests.sh new file mode 100755 index 0000000..d9362bb --- /dev/null +++ b/dev/execute-plugin-tests.sh @@ -0,0 +1,40 @@ +#!/bin/bash +## Copyright 2024, gRPC Authors All rights reserved. +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. + +set -euo pipefail + +log() { printf -- "** %s\n" "$*" >&2; } +error() { printf -- "** ERROR: %s\n" "$*" >&2; } +fatal() { error "$@"; exit 1; } + +tests_directory="${PLUGIN_TESTS_DIRECTORY:=""}" +if [[ -z "$tests_directory" ]]; then + fatal "Tests parent directory must be specified." +fi + +for dir in "$tests_directory"/test_*/ ; do + if [[ -f "$dir/Package.swift" ]]; then + plugin_test=$(basename "$dir") + log "Building '$plugin_test' plugin test" + + if ! build_output=$(swift build --package-path "$dir" 2>&1); then + # Only print the build output on failure. + echo "$build_output" + fatal "Build failed for '$plugin_test'" + else + log "Build succeeded for '$plugin_test'" + fi + fi +done diff --git a/dev/plugin-tests.sh b/dev/plugin-tests.sh index 9041faf..1230170 100755 --- a/dev/plugin-tests.sh +++ b/dev/plugin-tests.sh @@ -19,20 +19,8 @@ log() { printf -- "** %s\n" "$*" >&2; } error() { printf -- "** ERROR: %s\n" "$*" >&2; } fatal() { error "$@"; exit 1; } -here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -plugin_tests="${here}/../IntegrationTests/PluginTests" +here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +tests_directory="${PLUGIN_TESTS_OUTPUT_DIRECTORY:=$(mktemp -d -t grpc-swift-protobuf-plugin-tests)}" -for dir in "$plugin_tests"/test_*/ ; do - if [[ -f "$dir/Package.swift" ]]; then - plugin_test=$(basename "$dir") - log "Building '$plugin_test' plugin test" - - if ! build_output=$(swift build --package-path "$dir" 2>&1); then - # Only print the build output on failure. - echo "$build_output" - fatal "Build failed for '$plugin_test'" - else - log "Build succeeded for '$plugin_test'" - fi - fi -done +PLUGIN_TESTS_OUTPUT_DIRECTORY="$tests_directory" "$here/setup-plugin-tests.sh" +PLUGIN_TESTS_DIRECTORY="$tests_directory" "$here/execute-plugin-tests.sh" diff --git a/dev/setup-plugin-tests.sh b/dev/setup-plugin-tests.sh new file mode 100755 index 0000000..b3c1ae4 --- /dev/null +++ b/dev/setup-plugin-tests.sh @@ -0,0 +1,96 @@ +#!/bin/bash +## Copyright 2024, gRPC Authors All rights reserved. +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. + +set -euo pipefail + +log() { printf -- "** %s\n" "$*" >&2; } +error() { printf -- "** ERROR: %s\n" "$*" >&2; } +fatal() { error "$@"; exit 1; } + +output_directory="${PLUGIN_TESTS_OUTPUT_DIRECTORY:=$(mktemp -d -t grpc-swift-protobuf-plugin-tests)}" + +here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +grpc_swift_protobuf_directory="$(readlink -f "${here}/..")" +resources_directory="$(readlink -f "${grpc_swift_protobuf_directory}/IntegrationTests/PluginTests/Resources")" +scratch_directory="$(mktemp -d -t grpc-swift-protobuf-plugin-tests-scratch)" + +echo "Output directory: $output_directory" +echo "grpc-swift-protobuf directory: $grpc_swift_protobuf_directory" + +# modify Package.swift +cp "${resources_directory}/Package.swift" "${scratch_directory}/" +cat >> "${scratch_directory}/Package.swift" <<- EOM +package.dependencies.append( + .package(path: "$grpc_swift_protobuf_directory") +) +EOM + +# test_01_top_level_config_file +test_01_output_directory="${output_directory}/test_01_top_level_config_file" +mkdir -p "${test_01_output_directory}/Sources/Protos" +cp "${scratch_directory}/Package.swift" "${test_01_output_directory}/" +cp "${resources_directory}/HelloWorldAdopter.swift" "${test_01_output_directory}/Sources/adopter.swift" +cp "${resources_directory}/HelloWorld/HelloWorld.proto" "${test_01_output_directory}/Sources/Protos" +cp "${resources_directory}/internal-grpc-swift-proto-generator-config.json" "${test_01_output_directory}/Sources/grpc-swift-proto-generator-config.json" + +# test_02_peer_config_file +test_02_output_directory="${output_directory}/test_02_peer_config_file" +mkdir -p "${test_02_output_directory}/Sources/Protos" +cp "${scratch_directory}/Package.swift" "${test_02_output_directory}/" +cp "${resources_directory}/HelloWorldAdopter.swift" "${test_02_output_directory}/Sources/adopter.swift" +cp "${resources_directory}/HelloWorld/HelloWorld.proto" "${test_02_output_directory}/Sources/Protos/" +cp "${resources_directory}/internal-grpc-swift-proto-generator-config.json" "${test_02_output_directory}/Sources/Protos/grpc-swift-proto-generator-config.json" + +# test_03_separate_service_message_protos +test_03_output_directory="${output_directory}/test_03_separate_service_message_protos" +mkdir -p "${test_03_output_directory}/Sources/Protos" +cp "${scratch_directory}/Package.swift" "${test_03_output_directory}/" +cp "${resources_directory}/HelloWorldAdopter.swift" "${test_03_output_directory}/Sources/adopter.swift" +cp "${resources_directory}/internal-grpc-swift-proto-generator-config.json" "${test_03_output_directory}/Sources/Protos/grpc-swift-proto-generator-config.json" +cp "${resources_directory}/HelloWorld/Service.proto" "${test_03_output_directory}/Sources/Protos/" +cp "${resources_directory}/HelloWorld/Messages.proto" "${test_03_output_directory}/Sources/Protos/" + +# test_04_cross_directory_imports +test_04_output_directory="${output_directory}/test_04_cross_directory_imports" +mkdir -p "${test_04_output_directory}/Sources/Protos/directory_1" +mkdir -p "${test_04_output_directory}/Sources/Protos/directory_2" +cp "${scratch_directory}/Package.swift" "${test_04_output_directory}/" +cp "${resources_directory}/HelloWorldAdopter.swift" "${test_04_output_directory}/Sources/adopter.swift" +cp "${resources_directory}/internal-grpc-swift-proto-generator-config.json" "${test_04_output_directory}/Sources/Protos/directory_1/grpc-swift-proto-generator-config.json" +cp "${resources_directory}/import-directory-1-grpc-swift-proto-generator-config.json" "${test_04_output_directory}/Sources/Protos/directory_2/grpc-swift-proto-generator-config.json" +cp "${resources_directory}/HelloWorld/Service.proto" "${test_04_output_directory}/Sources/Protos/directory_2/" +cp "${resources_directory}/HelloWorld/Messages.proto" "${test_04_output_directory}/Sources/Protos/directory_1/" + +# test_05_two_definitions +test_05_output_directory="${output_directory}/test_05_two_definitions" +mkdir -p "${test_05_output_directory}/Sources/Protos/HelloWorld" +mkdir -p "${test_05_output_directory}/Sources/Protos/Foo" +cp "${scratch_directory}/Package.swift" "${test_05_output_directory}/" +cp "${resources_directory}/FooHelloWorldAdopter.swift" "${test_05_output_directory}/Sources/adopter.swift" +cp "${resources_directory}/HelloWorld/HelloWorld.proto" "${test_05_output_directory}/Sources/Protos/HelloWorld/" +cp "${resources_directory}/internal-grpc-swift-proto-generator-config.json" "${test_05_output_directory}/Sources/Protos/grpc-swift-proto-generator-config.json" +cp "${resources_directory}/Foo/foo-messages.proto" "${test_05_output_directory}/Sources/Protos/Foo/" +cp "${resources_directory}/Foo/foo-service.proto" "${test_05_output_directory}/Sources/Protos/Foo/" + +# test_06_nested_definitions +test_06_output_directory="${output_directory}/test_06_nested_definitions" +mkdir -p "${test_06_output_directory}/Sources/Protos/HelloWorld/FooDefinitions/Foo" +cp "${scratch_directory}/Package.swift" "${test_06_output_directory}/" +cp "${resources_directory}/FooHelloWorldAdopter.swift" "${test_06_output_directory}/Sources/adopter.swift" +cp "${resources_directory}/HelloWorld/HelloWorld.proto" "${test_06_output_directory}/Sources/Protos/HelloWorld/" +cp "${resources_directory}/internal-grpc-swift-proto-generator-config.json" "${test_06_output_directory}/Sources/Protos/HelloWorld/grpc-swift-proto-generator-config.json" +cp "${resources_directory}/public-grpc-swift-proto-generator-config.json" "${test_06_output_directory}/Sources/Protos/HelloWorld/FooDefinitions/grpc-swift-proto-generator-config.json" +cp "${resources_directory}/Foo/foo-messages.proto" "${test_06_output_directory}/Sources/Protos/HelloWorld/FooDefinitions/Foo/" +cp "${resources_directory}/Foo/foo-service.proto" "${test_06_output_directory}/Sources/Protos/HelloWorld/FooDefinitions/Foo/" From 7105fb7aae94f61fa528462d7e2b16b546073904 Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Thu, 23 Jan 2025 08:52:29 +0000 Subject: [PATCH 4/8] TEMPORARY URL --- .github/workflows/matrices/plugin-tests.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/matrices/plugin-tests.json b/.github/workflows/matrices/plugin-tests.json index 9295a07..033c80b 100644 --- a/.github/workflows/matrices/plugin-tests.json +++ b/.github/workflows/matrices/plugin-tests.json @@ -1 +1 @@ -{"config":[{"name":"Plugin tests (6.0)","swift_version":"6.0","runner":"ubuntu-latest","image":"swift:6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s http://raw.githubusercontent.com/grpc/grpc-swift-protobuf/main/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-6.1)","swift_version":"nightly-6.1","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-6.1-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s http://raw.githubusercontent.com/grpc/grpc-swift-protobuf/main/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-main)","swift_version":"nightly-main","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-main-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s http://raw.githubusercontent.com/grpc/grpc-swift-protobuf/main/dev/plugin-tests.sh | bash","command_arguments":""}]} +{"config":[{"name":"Plugin tests (6.0)","swift_version":"6.0","runner":"ubuntu-latest","image":"swift:6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/refs/heads/build_plugin_integration_tests/dev/plugin-tests.sh| bash","command_arguments":""},{"name":"Plugin tests (nightly-6.1)","swift_version":"nightly-6.1","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-6.1-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/refs/heads/build_plugin_integration_tests/dev/plugin-tests.sh| bash","command_arguments":""},{"name":"Plugin tests (nightly-main)","swift_version":"nightly-main","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-main-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/refs/heads/build_plugin_integration_tests/dev/plugin-tests.sh| bash","command_arguments":""}]} From 658670fd0ba0fd0a32529e49a1987cd9e0f7b717 Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Thu, 23 Jan 2025 08:54:55 +0000 Subject: [PATCH 5/8] remove custom temp dir prefix --- dev/plugin-tests.sh | 2 +- dev/setup-plugin-tests.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dev/plugin-tests.sh b/dev/plugin-tests.sh index 1230170..31e5d6c 100755 --- a/dev/plugin-tests.sh +++ b/dev/plugin-tests.sh @@ -20,7 +20,7 @@ error() { printf -- "** ERROR: %s\n" "$*" >&2; } fatal() { error "$@"; exit 1; } here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -tests_directory="${PLUGIN_TESTS_OUTPUT_DIRECTORY:=$(mktemp -d -t grpc-swift-protobuf-plugin-tests)}" +tests_directory="${PLUGIN_TESTS_OUTPUT_DIRECTORY:=$(mktemp -d)}" PLUGIN_TESTS_OUTPUT_DIRECTORY="$tests_directory" "$here/setup-plugin-tests.sh" PLUGIN_TESTS_DIRECTORY="$tests_directory" "$here/execute-plugin-tests.sh" diff --git a/dev/setup-plugin-tests.sh b/dev/setup-plugin-tests.sh index b3c1ae4..666c535 100755 --- a/dev/setup-plugin-tests.sh +++ b/dev/setup-plugin-tests.sh @@ -19,12 +19,12 @@ log() { printf -- "** %s\n" "$*" >&2; } error() { printf -- "** ERROR: %s\n" "$*" >&2; } fatal() { error "$@"; exit 1; } -output_directory="${PLUGIN_TESTS_OUTPUT_DIRECTORY:=$(mktemp -d -t grpc-swift-protobuf-plugin-tests)}" +output_directory="${PLUGIN_TESTS_OUTPUT_DIRECTORY:=$(mktemp -d)}" here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" grpc_swift_protobuf_directory="$(readlink -f "${here}/..")" resources_directory="$(readlink -f "${grpc_swift_protobuf_directory}/IntegrationTests/PluginTests/Resources")" -scratch_directory="$(mktemp -d -t grpc-swift-protobuf-plugin-tests-scratch)" +scratch_directory="$(mktemp -d)" echo "Output directory: $output_directory" echo "grpc-swift-protobuf directory: $grpc_swift_protobuf_directory" From d8dc44405ee4bfdd5916753e33793b324c014dd2 Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Thu, 23 Jan 2025 08:55:27 +0000 Subject: [PATCH 6/8] formatting --- IntegrationTests/PluginTests/Resources/Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IntegrationTests/PluginTests/Resources/Package.swift b/IntegrationTests/PluginTests/Resources/Package.swift index 3482097..deef566 100644 --- a/IntegrationTests/PluginTests/Resources/Package.swift +++ b/IntegrationTests/PluginTests/Resources/Package.swift @@ -32,7 +32,7 @@ var package = Package( .package( url: "https://github.com/grpc/grpc-swift.git", branch: "main" - ), + ) ], targets: [ .executableTarget( From 63dc0bf5f738cec175b48ea5d82de13e720c88c6 Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Thu, 23 Jan 2025 09:22:39 +0000 Subject: [PATCH 7/8] plugin-tests.sh handles being sourced --- .github/workflows/matrices/plugin-tests.json | 2 +- dev/plugin-tests.sh | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/matrices/plugin-tests.json b/.github/workflows/matrices/plugin-tests.json index 033c80b..481580a 100644 --- a/.github/workflows/matrices/plugin-tests.json +++ b/.github/workflows/matrices/plugin-tests.json @@ -1 +1 @@ -{"config":[{"name":"Plugin tests (6.0)","swift_version":"6.0","runner":"ubuntu-latest","image":"swift:6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/refs/heads/build_plugin_integration_tests/dev/plugin-tests.sh| bash","command_arguments":""},{"name":"Plugin tests (nightly-6.1)","swift_version":"nightly-6.1","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-6.1-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/refs/heads/build_plugin_integration_tests/dev/plugin-tests.sh| bash","command_arguments":""},{"name":"Plugin tests (nightly-main)","swift_version":"nightly-main","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-main-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/refs/heads/build_plugin_integration_tests/dev/plugin-tests.sh| bash","command_arguments":""}]} +{"config":[{"name":"Plugin tests (6.0)","swift_version":"6.0","runner":"ubuntu-latest","image":"swift:6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/refs/heads/build_plugin_integration_tests/dev/plugin-tests.sh| GITHUB_ACTIONS=true bash","command_arguments":""},{"name":"Plugin tests (nightly-6.1)","swift_version":"nightly-6.1","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-6.1-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/refs/heads/build_plugin_integration_tests/dev/plugin-tests.sh| GITHUB_ACTIONS=true bash","command_arguments":""},{"name":"Plugin tests (nightly-main)","swift_version":"nightly-main","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-main-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/refs/heads/build_plugin_integration_tests/dev/plugin-tests.sh| GITHUB_ACTIONS=true bash","command_arguments":""}]} diff --git a/dev/plugin-tests.sh b/dev/plugin-tests.sh index 31e5d6c..ace8488 100755 --- a/dev/plugin-tests.sh +++ b/dev/plugin-tests.sh @@ -19,8 +19,15 @@ log() { printf -- "** %s\n" "$*" >&2; } error() { printf -- "** ERROR: %s\n" "$*" >&2; } fatal() { error "$@"; exit 1; } -here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +if [[ -n ${GITHUB_ACTIONS:=""} ]]; then + # we will have been piped to bash and won't know the location of the script + echo "Running in GitHub Actions" + source_directory="$(pwd)" +else + here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + source_directory="$(readlink -f "${here}/..")" +fi tests_directory="${PLUGIN_TESTS_OUTPUT_DIRECTORY:=$(mktemp -d)}" -PLUGIN_TESTS_OUTPUT_DIRECTORY="$tests_directory" "$here/setup-plugin-tests.sh" -PLUGIN_TESTS_DIRECTORY="$tests_directory" "$here/execute-plugin-tests.sh" +PLUGIN_TESTS_OUTPUT_DIRECTORY="$tests_directory" "${source_directory}/dev/setup-plugin-tests.sh" +PLUGIN_TESTS_DIRECTORY="$tests_directory" "${source_directory}/dev/execute-plugin-tests.sh" From 6c3f38aae69b057a6592578427e1333c2824068e Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Fri, 24 Jan 2025 11:49:47 +0000 Subject: [PATCH 8/8] CI generate plugin test matrix --- .github/workflows/main.yml | 25 ++++++++++++++++--- .github/workflows/matrices/plugin-tests.json | 1 - .github/workflows/pull_request.yml | 25 ++++++++++++++++--- .../PluginTests/Resources/Package.swift | 2 +- 4 files changed, 45 insertions(+), 8 deletions(-) delete mode 100644 .github/workflows/matrices/plugin-tests.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 60d04ff..9ea03af 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,9 +17,28 @@ jobs: linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" - plugin-tests: + construct-plugin-tests-matrix: + name: Construct plugin tests matrix + runs-on: ubuntu-latest + outputs: + plugin-tests-matrix: '${{ steps.generate-matrix.outputs.plugin-tests-matrix }}' + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + persist-credentials: false + - id: generate-matrix + run: echo "plugin-tests-matrix=$(curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/generate_matrix.sh | bash)" >> "$GITHUB_OUTPUT" + env: + MATRIX_LINUX_5_9_ENABLED: false + MATRIX_LINUX_5_10_ENABLED: false + MATRIX_LINUX_COMMAND: "curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/refs/heads/build_plugin_integration_tests/dev/plugin-tests.sh | GITHUB_ACTIONS=true bash" + MATRIX_LINUX_SETUP_COMMAND: "apt-get update -y -q && apt-get install -y -q curl protobuf-compiler" + + plugin-tests-matrix: name: Plugin tests - uses: apple/swift-nio/.github/workflows/swift_load_test_matrix.yml@main + needs: construct-plugin-tests-matrix + uses: apple/swift-nio/.github/workflows/swift_test_matrix.yml@main with: name: "Plugin tests" - matrix_path: ".github/workflows/matrices/plugin-tests.json" + matrix_string: '${{ needs.construct-plugin-tests-matrix.outputs.plugin-tests-matrix }}' diff --git a/.github/workflows/matrices/plugin-tests.json b/.github/workflows/matrices/plugin-tests.json deleted file mode 100644 index 481580a..0000000 --- a/.github/workflows/matrices/plugin-tests.json +++ /dev/null @@ -1 +0,0 @@ -{"config":[{"name":"Plugin tests (6.0)","swift_version":"6.0","runner":"ubuntu-latest","image":"swift:6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/refs/heads/build_plugin_integration_tests/dev/plugin-tests.sh| GITHUB_ACTIONS=true bash","command_arguments":""},{"name":"Plugin tests (nightly-6.1)","swift_version":"nightly-6.1","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-6.1-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/refs/heads/build_plugin_integration_tests/dev/plugin-tests.sh| GITHUB_ACTIONS=true bash","command_arguments":""},{"name":"Plugin tests (nightly-main)","swift_version":"nightly-main","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-main-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/refs/heads/build_plugin_integration_tests/dev/plugin-tests.sh| GITHUB_ACTIONS=true bash","command_arguments":""}]} diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 29c7ce8..686d537 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -26,12 +26,31 @@ jobs: linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" - plugin-tests: + construct-plugin-tests-matrix: + name: Construct plugin tests matrix + runs-on: ubuntu-latest + outputs: + plugin-tests-matrix: '${{ steps.generate-matrix.outputs.plugin-tests-matrix }}' + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + persist-credentials: false + - id: generate-matrix + run: echo "plugin-tests-matrix=$(curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/generate_matrix.sh | bash)" >> "$GITHUB_OUTPUT" + env: + MATRIX_LINUX_5_9_ENABLED: false + MATRIX_LINUX_5_10_ENABLED: false + MATRIX_LINUX_COMMAND: "curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/refs/heads/build_plugin_integration_tests/dev/plugin-tests.sh | GITHUB_ACTIONS=true bash" + MATRIX_LINUX_SETUP_COMMAND: "apt-get update -y -q && apt-get install -y -q curl protobuf-compiler" + + plugin-tests-matrix: name: Plugin tests - uses: apple/swift-nio/.github/workflows/swift_load_test_matrix.yml@main + needs: construct-plugin-tests-matrix + uses: apple/swift-nio/.github/workflows/swift_test_matrix.yml@main with: name: "Plugin tests" - matrix_path: ".github/workflows/matrices/plugin-tests.json" + matrix_string: '${{ needs.construct-plugin-tests-matrix.outputs.plugin-tests-matrix }}' cxx-interop: name: Cxx interop diff --git a/IntegrationTests/PluginTests/Resources/Package.swift b/IntegrationTests/PluginTests/Resources/Package.swift index deef566..18807b3 100644 --- a/IntegrationTests/PluginTests/Resources/Package.swift +++ b/IntegrationTests/PluginTests/Resources/Package.swift @@ -17,7 +17,7 @@ import PackageDescription -var package = Package( +let package = Package( name: "grpc-adopter", platforms: [ .macOS(.v15),