Skip to content

Commit 3684b98

Browse files
authored
Fix include path for the client libraries of the gapic artifact library. (googleapis#54)
The correct include path should be `ServiceDescriptor->full_path()`, which is service package + name. For example, for the service `LibraryService` from `library.proto`, which has `package google.example.library.v1;` the inluce paths should be the following: ```cc #include "google/example/library/v1/library_service.gapic.h" #include "google/example/library/v1/library_service_stub.gapic.h" ``` Also add optional args propagation from macro to the underlying rules (affects visibility attribute for example)
1 parent 55bbf10 commit 3684b98

File tree

6 files changed

+26
-16
lines changed

6 files changed

+26
-16
lines changed

generator/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ cc_binary(
5353
name = "protoc-gen-cpp_gapic",
5454
srcs = ["main.cc"],
5555
includes = ["."],
56-
deps = [":gapic_generator"],
5756
visibility = ["//visibility:public"],
57+
deps = [":gapic_generator"],
5858
)
5959

6060
cc_test(
@@ -69,6 +69,7 @@ cc_test(
6969
],
7070
deps = [
7171
":gapic_generator",
72+
"//generator/testdata:library_cc_gapic",
7273
"@gtest//:gtest_main",
7374
],
7475
)

generator/internal/client_cc_generator.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ std::vector<std::string> BuildClientCCIncludes(
3333
pb::ServiceDescriptor const* service) {
3434
return {
3535
LocalInclude(absl::StrCat(
36-
internal::ServiceNameToFilePath(service->name()), ".gapic.h")),
37-
LocalInclude(absl::StrCat(
38-
internal::ServiceNameToFilePath(service->name()), "_stub.gapic.h")),
36+
internal::ServiceNameToFilePath(service->full_name()), ".gapic.h")),
37+
LocalInclude(
38+
absl::StrCat(internal::ServiceNameToFilePath(service->full_name()),
39+
"_stub.gapic.h")),
3940
LocalInclude("gax/call_context.h"), LocalInclude("gax/status.h"),
4041
LocalInclude("gax/status_or.h"),
4142
};

generator/internal/stub_cc_generator.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ std::vector<std::string> BuildClientStubCCIncludes(
2929
pb::ServiceDescriptor const* service) {
3030
return {
3131
LocalInclude(
32-
absl::StrCat(CamelCaseToSnakeCase(service->name()), "_stub.gapic.h")),
32+
absl::StrCat(internal::ServiceNameToFilePath(service->full_name()),
33+
"_stub.gapic.h")),
3334
LocalInclude(absl::StrCat(
3435
absl::StripSuffix(service->file()->name(), ".proto"), ".grpc.pb.h")),
3536
LocalInclude("gax/call_context.h"), LocalInclude("gax/retry_loop.h"),

generator/testdata/google/example/library/v1/library_service.gapic.cc.baseline

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Generated by the GAPIC C++ plugin.
22
// If you make any local changes, they will be lost.
33
// source: generator/testdata/library.proto
4-
#include "library_service.gapic.h"
5-
#include "library_service_stub.gapic.h"
4+
#include "google/example/library/v1/library_service.gapic.h"
5+
#include "google/example/library/v1/library_service_stub.gapic.h"
66
#include "gax/call_context.h"
77
#include "gax/status.h"
88
#include "gax/status_or.h"

generator/testdata/google/example/library/v1/library_service_stub.gapic.cc.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// If you make any local changes, they will be lost.
33
// source: generator/testdata/library.proto
44

5-
#include "library_service_stub.gapic.h"
5+
#include "google/example/library/v1/library_service_stub.gapic.h"
66
#include "generator/testdata/library.grpc.pb.h"
77
#include "gax/call_context.h"
88
#include "gax/retry_loop.h"

rules_gapic/cpp/cc_gapic.bzl

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ def _cc_gapic_postprocessed_srcjar_impl(ctx):
2727
# TODO: Call formatter here
2828
pushd {output_dir_path}
2929
zip -q -r {output_dir_name}-h.srcjar . -i ./*.gapic.h
30+
find . -name "*.gapic.h" -delete
31+
zip -q -r {output_dir_name}.srcjar . -i ./*.cc -i ./*.h
3032
popd
3133
mv {output_dir_path}/{output_dir_name}-h.srcjar {output_main_h}
32-
cp {gapic_zip} {output_main}
34+
mv {output_dir_path}/{output_dir_name}.srcjar {output_main}
35+
rm -rf {output_dir_path}
3336
""".format(
3437
gapic_zip = gapic_zip.path,
3538
output_dir_name = output_dir_name,
@@ -55,32 +58,32 @@ _cc_gapic_postprocessed_srcjar = rule(
5558
},
5659
)
5760

58-
def cc_gapic_srcjar(name, src, package, visibility = None):
61+
def cc_gapic_srcjar(name, src, package, **kwargs):
5962
raw_srcjar_name = "%s_raw" % name
6063

6164
gapic_srcjar(
6265
name = raw_srcjar_name,
6366
src = src,
6467
package = package,
6568
output_suffix = ".zip",
66-
visibility = visibility,
6769
gapic_generator = Label("//generator:protoc-gen-cpp_gapic"),
70+
**kwargs
6871
)
6972

7073
_cc_gapic_postprocessed_srcjar(
7174
name = name,
7275
gapic_zip = ":%s" % raw_srcjar_name,
73-
visibility = visibility,
76+
**kwargs
7477
)
7578

76-
def cc_gapic_library(name, src, package, deps = [], visibility = None):
79+
def cc_gapic_library(name, src, package, deps = [], **kwargs):
7780
srcjar_name = "%s_srcjar" % name
7881

7982
cc_gapic_srcjar(
8083
name = srcjar_name,
8184
src = src,
8285
package = package,
83-
visibility = visibility,
86+
**kwargs
8487
)
8588

8689
actual_deps = deps + [
@@ -93,7 +96,8 @@ def cc_gapic_library(name, src, package, deps = [], visibility = None):
9396
unzipped_srcjar(
9497
name = main_dir,
9598
srcjar = main_file,
96-
extension = ".cc",
99+
extension = "",
100+
**kwargs
97101
)
98102

99103
main_h_file = ":%s-h.srcjar" % srcjar_name
@@ -102,12 +106,15 @@ def cc_gapic_library(name, src, package, deps = [], visibility = None):
102106
unzipped_srcjar(
103107
name = main_h_dir,
104108
srcjar = main_h_file,
105-
extension = ".h",
109+
extension = "",
110+
**kwargs
106111
)
107112

108113
native.cc_library(
109114
name = name,
110115
srcs = [":%s" % main_dir],
111116
deps = actual_deps,
112117
hdrs = [":%s" % main_h_dir],
118+
includes = [main_h_dir],
119+
**kwargs
113120
)

0 commit comments

Comments
 (0)