Skip to content

Commit

Permalink
Split messages and services macros
Browse files Browse the repository at this point in the history
  • Loading branch information
jcanizales committed Jul 2, 2015
1 parent 164f633 commit d943527
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions grpc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,49 @@ def _file_with_extension(src, ext):
basename = elements[-1].partition('.')[0]
return "".join(elements[:-1] + [basename, ext])

def objc_grpc_library(name, srcs, visibility=None):
def _protoc_invocation(srcs, flags):
protoc_command = "protoc -I . "
srcs_params = ""
for src in srcs:
srcs_params += " $(location %s)" % (src)
return protoc_command + flags + srcs_params

def objc_proto_library(name, srcs, visibility=None):
src = _file_to_upper_camel(srcs[0])

# Messages
protoc_messages_flags = "--objc_out=$(GENDIR)"
protoc_flags = "--objc_out=$(GENDIR)"
message_header = _file_with_extension(src, ".pbobjc.h")
message_implementation = _file_with_extension(src, ".pbobjc.m")
native.genrule(
name = name + "_mesages_codegen",
name = name + "_codegen",
srcs = srcs,
outs = [message_header, message_implementation],
cmd = protoc_command + protoc_messages_flags + srcs_params,
cmd = _protoc_invocation(srcs, protoc_flags),
)
native.objc_library(
name = name + "_messages",
name = name,
hdrs = [message_header],
includes = ["."],
non_arc_srcs = [message_implementation],
deps = [
"//external:protobuf_objc",
],
visibility = visibility,
)

# Services
protoc_services_flags = "--grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(location //external:grpc_protoc_plugin_objc)"
def objc_grpc_library(name, srcs, visibility=None):
objc_proto_library(name + "_messages", srcs, visibility)

src = _file_to_upper_camel(srcs[0])

protoc_flags = "--grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(location //external:grpc_protoc_plugin_objc)"
service_header = _file_with_extension(src, ".pbrpc.h")
service_implementation = _file_with_extension(src, ".pbrpc.m")
native.genrule(
name = name + "_codegen",
srcs = srcs + ["//external:grpc_protoc_plugin_objc"],
outs = [service_header, service_implementation],
cmd = protoc_command + protoc_services_flags + srcs_params,
cmd = _protoc_invocation(srcs, protoc_flags),
)
native.objc_library(
name = name,
Expand Down

0 comments on commit d943527

Please sign in to comment.