Skip to content

Commit

Permalink
Revert "[CSHARP] Add base_namespace experimental option to C# plugin" (
Browse files Browse the repository at this point in the history
…#32957)

Reverts #32636

```
src/compiler/csharp_generator_helpers.h:25:7: error: no member named 'compiler' in namespace ...
src/compiler/csharp_generator_helpers.h:25:25: error: no member named 'csharp' in namespace 'compiler' ...
```
  • Loading branch information
drfloob committed Apr 27, 2023
1 parent a9afd1c commit d63f8d4
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 208 deletions.
23 changes: 3 additions & 20 deletions src/compiler/csharp_generator_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,13 @@
#include "src/compiler/config.h"
#include "src/compiler/generator_helpers.h"

using google::protobuf::compiler::csharp::GetOutputFile;

namespace grpc_csharp_generator {

inline bool ServicesFilename(const grpc::protobuf::FileDescriptor* file,
const std::string& file_suffix,
const std::string& base_namespace,
std::string& out_file, std::string* error) {
// Support for base_namespace option is **experimental**.
//
// If base_namespace is provided then slightly different name mangling
// is used to generate the service file name. This is because this
// uses common code with protoc. For most file names this will not
// make a difference (only files with punctuation or numbers in the
// name.)
// Otherwise the behavior remains the same as before.
if (base_namespace.empty()) {
out_file = grpc_generator::FileNameInUpperCamel(file, false) + file_suffix;
} else {
out_file = GetOutputFile(file, file_suffix, true, base_namespace, error);
if (out_file.empty()) {
return false;
}
}
std::string& out_file_name_or_error) {
out_file_name_or_error =
grpc_generator::FileNameInUpperCamel(file, false) + file_suffix;
return true;
}

Expand Down
11 changes: 2 additions & 9 deletions src/compiler/csharp_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
bool generate_client = true;
bool generate_server = true;
bool internal_access = false;
std::string base_namespace = "";

// the suffix that will get appended to the name generated from the name
// of the original .proto file
std::string file_suffix = "Grpc.cs";
Expand All @@ -57,11 +55,6 @@ class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
internal_access = true;
} else if (options[i].first == "file_suffix") {
file_suffix = options[i].second;
} else if (options[i].first == "base_namespace") {
// Support for base_namespace option in this plugin is experimental.
// The option may be removed or file names generated may change
// in the future.
base_namespace = options[i].second;
} else {
*error = "Unknown generator option: " + options[i].first;
return false;
Expand All @@ -76,8 +69,8 @@ class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {

// Get output file name.
std::string file_name;
if (!grpc_csharp_generator::ServicesFilename(
file, file_suffix, base_namespace, file_name, error)) {
if (!grpc_csharp_generator::ServicesFilename(file, file_suffix,
file_name)) {
return false;
}
std::unique_ptr<grpc::protobuf::io::ZeroCopyOutputStream> output(
Expand Down
31 changes: 5 additions & 26 deletions src/csharp/BUILD-INTEGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,33 +173,12 @@ to perform code generation. Here is an overview of the available `grpc_csharp_pl
| no_client | off | Don't generate the client stub |
| no_server | off | Don't generate the server-side stub |
| internal_access | off | Generate classes with "internal" visibility |
| file_suffix | Grpc.cs | The suffix that will get appended to the name of the generated file. **Can only be used on the command line.** |
| base_namespace | none | *Experimental - may change or be removed.* Same as `base_namespace` for `protoc` [C# options](https://protobuf.dev/reference/csharp/csharp-generated/#compiler_options) . **Can only be used on the command line.** |

To use these options with `Grpc.Tools` specify them in the __GrpcOutputOptions__
metadata in the `<Protobuf>` item.

Notes:
- `file_suffix` and `base_namespace` should not be used with `Grpc.Tools`. Using them will break the build.

- using `base_namespace` changes the algorithm for the generated file names to align it with the algorithm used by `protoc`.

This only affects files with punctuation or numbers in the name. E.g. `hello.world2d.proto` now generates file `HelloWorld2DGrpc.cs` instead of `Hello.world2dGrpc.cs`

To use these options on the command line specify them with the `--grpc_opt`
option.

Code generated by `protoc` is independent of the plugin and you may also need to specify C# options for this with `--csharp_opt`.
These are [documented here](https://protobuf.dev/reference/csharp/csharp-generated/#compiler_options).

e.g.:

```bash
protoc --plugin=protoc-gen-grpc=grpc_csharp_plugin \
--csharp_out=OUT_DIR \
--csharp_opt=base_namespace=Example \
--grpc_out=OUT_DIR \
--grpc_opt=no_server,base_namespace=Example \
Note that the protocol buffer compiler has a special commandline syntax for plugin options.
Example:
```
protoc --plugin=protoc-gen-grpc=grpc_csharp_plugin --csharp_out=OUT_DIR \
--grpc_out=OUT_DIR --grpc_opt=lite_client,no_server \
-I INCLUDE_DIR foo.proto
```
## Environment Variables
Expand Down
19 changes: 0 additions & 19 deletions test/csharp/codegen/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,3 @@ grpc_sh_test(
],
uses_polling = False,
)

grpc_sh_test(
name = "csharp_codegen_base_namespace_test",
size = "small",
srcs = ["csharp_codegen_base_namespace_test.sh"],
data = [
"basenamespace/proto/namespacetest.proto",
"//src/compiler:grpc_csharp_plugin",
"@com_google_protobuf//:protoc",
],
tags = [
"no_windows",
"noasan",
"nomsan",
"notsan",
"noubsan",
],
uses_polling = False,
)
37 changes: 0 additions & 37 deletions test/csharp/codegen/basenamespace/proto/namespacetest.proto

This file was deleted.

97 changes: 0 additions & 97 deletions test/csharp/codegen/csharp_codegen_base_namespace_test.sh

This file was deleted.

0 comments on commit d63f8d4

Please sign in to comment.