Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the gRPC module name to be customised when generating code #945

Merged
merged 4 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ the following line to your `Podfile`:
Then, run `pod install` from command line and use your project's generated
`.xcworkspace` file. You might also need to add `use_frameworks!` to your `Podfile`.

*⚠️ If you have conficting modules as a result of having a transitive
dependency on '[gRPC-Core][grpc-core-pod]' see [grpc/grpc-swift#945][grpc-swift-945].*

### Getting the `protoc` Plugins

Binary releases of `protoc`, the Protocol Buffer Compiler, are available on
Expand Down Expand Up @@ -171,6 +174,8 @@ Please get involved! See our [guidelines for contributing](CONTRIBUTING.md).
[docs-keepalive]: ./docs/keepalive.md
[docs-tutorial]: ./docs/basic-tutorial.md
[grpc]: https://github.com/grpc/grpc
[grpc-core-pod]: https://cocoapods.org/pods/gRPC-Core
[grpc-swift-945]: https://github.com/grpc/grpc-swift/pull/945
[protobuf-releases]: https://github.com/protocolbuffers/protobuf/releases
[swift-nio-platforms]: https://github.com/apple/swift-nio#supported-platforms
[swift-nio]: https://github.com/apple/swift-nio
Expand Down
3 changes: 0 additions & 3 deletions Sources/Examples/Echo/Model/echo.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
import GRPC
import NIO
import NIOHTTP1
import SwiftProtobuf


/// Usage: instantiate Echo_EchoClient, then call methods of this protocol to make API calls.
Expand Down
3 changes: 0 additions & 3 deletions Sources/Examples/HelloWorld/Model/helloworld.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
import GRPC
import NIO
import NIOHTTP1
import SwiftProtobuf


/// Usage: instantiate Helloworld_GreeterClient, then call methods of this protocol to make API calls.
Expand Down
3 changes: 0 additions & 3 deletions Sources/Examples/RouteGuide/Model/route_guide.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
import GRPC
import NIO
import NIOHTTP1
import SwiftProtobuf


/// Usage: instantiate Routeguide_RouteGuideClient, then call methods of this protocol to make API calls.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
import GRPC
import NIO
import NIOHTTP1
import SwiftProtobuf


/// Usage: instantiate Grpc_Testing_TestServiceClient, then call methods of this protocol to make API calls.
Expand Down
5 changes: 1 addition & 4 deletions Sources/protoc-gen-grpc-swift/Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,8 @@ class Generator {
""")

let moduleNames = [
"Foundation",
self.options.gRPCModuleName,
"NIO",
"NIOHTTP1",
"GRPC",
"SwiftProtobuf",
]

for moduleName in (moduleNames + self.options.extraModuleImports).sorted() {
Expand Down
8 changes: 8 additions & 0 deletions Sources/protoc-gen-grpc-swift/options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ final class GeneratorOptions {
private(set) var protoToModuleMappings = ProtoFileToModuleMappings()
private(set) var fileNaming = FileNaming.FullPath
private(set) var extraModuleImports: [String] = []
private(set) var gRPCModuleName = "GRPC"

init(parameter: String?) throws {
for pair in GeneratorOptions.parseParameter(string: parameter) {
Expand Down Expand Up @@ -116,6 +117,13 @@ final class GeneratorOptions {
throw GenerationError.invalidParameterValue(name: pair.key, value: pair.value)
}

case "GRPCModuleName":
if !pair.value.isEmpty {
self.gRPCModuleName = pair.value
} else {
throw GenerationError.invalidParameterValue(name: pair.key, value: pair.value)
}

default:
throw GenerationError.unknownParameter(name: pair.key)
}
Expand Down
3 changes: 0 additions & 3 deletions dev/codegen-tests/01-echo/golden/echo.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
import GRPC
import NIO
import NIOHTTP1
import SwiftProtobuf


/// Usage: instantiate Echo_EchoClient, then call methods of this protocol to make API calls.
Expand Down
3 changes: 0 additions & 3 deletions dev/codegen-tests/02-multifile/golden/a.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
import GRPC
import NIO
import NIOHTTP1
import SwiftProtobuf


/// Usage: instantiate A_ServiceAClient, then call methods of this protocol to make API calls.
Expand Down
3 changes: 0 additions & 3 deletions dev/codegen-tests/02-multifile/golden/b.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
import GRPC
import NIO
import NIOHTTP1
import SwiftProtobuf


/// Usage: instantiate B_ServiceBClient, then call methods of this protocol to make API calls.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
import GRPC
import NIO
import NIOHTTP1
import SwiftProtobuf
import ModuleB


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
import GRPC
import NIO
import NIOHTTP1
import SwiftProtobuf


/// Usage: instantiate B_ServiceBClient, then call methods of this protocol to make API calls.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
import GRPC
import NIO
import NIOHTTP1
import SwiftProtobuf


/// Usage: instantiate Codegentest_FooClient, then call methods of this protocol to make API calls.
Expand Down
3 changes: 0 additions & 3 deletions dev/codegen-tests/05-service-only/golden/test.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
import GRPC
import NIO
import NIOHTTP1
import SwiftProtobuf


/// Usage: instantiate Codegentest_FooClient, then call methods of this protocol to make API calls.
Expand Down
3 changes: 0 additions & 3 deletions dev/codegen-tests/06-test-client-only/golden/test.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
import GRPC
import NIO
import NIOHTTP1
import SwiftProtobuf


internal final class Codegentest_FooTestClient: Codegentest_FooClientProtocol {
Expand Down
9 changes: 9 additions & 0 deletions docs/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ The **FileNaming** option determines how generated source files should be named.
The **ProtoPathModuleMappings** option allows module mappings to be specified.
See the [SwiftProtobuf documentation][swift-protobuf-module-mappings].

### GRPCModuleName

The **GRPCModuleName** option allows the name of the gRPC Swift runtime module
to be specified. The value, if not specified, defaults to "GRPC".

*Note: most users will not need to use this option. It is intended as a
workaround for CocoaPods users who may end up with a transitive dependency on
the gRPC core C library whose module name is also "GRPC".*

## Specifying Options

To pass extra parameters to the plugin, use a comma-separated parameter list
Expand Down