Skip to content

Commit

Permalink
Added hearts
Browse files Browse the repository at this point in the history
  • Loading branch information
anders617 committed Nov 11, 2019
1 parent e62c68c commit 7bf355f
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 22 deletions.
16 changes: 16 additions & 0 deletions proto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ proto_library(
visibility = ["//visibility:public"],
)

proto_library(
name = "hearts_proto",
srcs = ["hearts.proto"],
visibility = ["//visibility:public"],
)

proto_library(
name = "mdining_proto",
srcs = ["mdining.proto"],
Expand All @@ -62,6 +68,7 @@ proto_library(
":menu_proto",
":food_proto",
":foodstat_proto",
":hearts_proto",
"@com_googleapis_googleapis//google/api:annotations_proto",
],
)
Expand Down Expand Up @@ -123,6 +130,7 @@ go_proto_library(
":menu_proto",
":food_proto",
":foodstat_proto",
":hearts_proto",
],
visibility = ["//visibility:public"],
deps = [
Expand All @@ -146,6 +154,7 @@ node_grpc_web_proto_library(
name = "mdining_grpcweb_proto",
deps = [
":mdining_proto",
":mdining_node_proto",
],
mode = "grpcweb",
)
Expand Down Expand Up @@ -230,6 +239,12 @@ cc_proto_library(
deps = [":foodstat_proto"],
)

cc_proto_library(
name = "hearts_cc_proto",
visibility = ["//visibility:public"],
deps = [":hearts_proto"],
)

cc_library(
name = "mdining_cc_library",
visibility = ["//visibility:public"],
Expand All @@ -241,5 +256,6 @@ cc_library(
":menu_cc_proto",
":food_cc_proto",
":foodstat_cc_proto",
":hearts_cc_proto",
]
)
8 changes: 8 additions & 0 deletions proto/hearts.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
syntax = "proto3";

package mdining;

message HeartCount {
string key = 1;
int64 count = 2;
}
24 changes: 24 additions & 0 deletions proto/mdining.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "proto/filterableentries.proto";
import "proto/menu.proto";
import "proto/food.proto";
import "proto/foodstat.proto";
import "proto/hearts.proto";

service MDining {
rpc GetDiningHalls(DiningHallsRequest) returns (DiningHallsReply) {
Expand Down Expand Up @@ -53,6 +54,21 @@ service MDining {
get: "/v1/stats"
};
}

rpc StreamHearts(HeartsRequest) returns (stream HeartsReply) {
}

rpc GetHearts(HeartsRequest) returns (HeartsReply) {
option (google.api.http) = {
get: "/v1/hearts"
};
}

rpc AddHeart(HeartsRequest) returns (HeartsReply) {
option (google.api.http) = {
post: "/v1/hearts"
};
}
}

message FoodStatsRequest {}
Expand Down Expand Up @@ -96,3 +112,11 @@ message FoodRequest {
message FoodReply {
repeated Food foods = 1;
}

message HeartsRequest {
repeated string keys = 1;
}

message HeartsReply {
repeated HeartCount counts = 1;
}
59 changes: 37 additions & 22 deletions rules/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def _generate_node_grpc_web_srcs(
mode,
sources,
transitive_sources):
all_sources = [src for src in sources] + [src for src in transitive_sources.to_list()]
all_sources = [src for src in sources] + [src for src in transitive_sources]
print(all_sources)
proto_include_paths = [
"-I%s" % p
for p in _proto_include_paths(
Expand All @@ -73,7 +74,12 @@ def _generate_node_grpc_web_srcs(
proto_include_paths += ["-I{}".format(src_prefix if src_prefix[-1] != '/' else src_prefix[:-1])]

files = []
count = 0
for src, path in zip(sources, paths):
if is_grpc and count > 0:
# Only compile first proto for grpc
break
count += 1
extension = ".grpc.pb.js" if is_grpc else "_pb.js"
name = "{}{}".format(
".".join(src.path.split("/")[-1].split(".")[:-1]),
Expand Down Expand Up @@ -140,6 +146,9 @@ def _node_proto_library_impl(ctx):
# if dep.label.package != ctx.label.package:
# continue
print(dep.label.package)
if ProtoInfo not in dep:
print(dep)
continue
# paths.append(ctx.label.package + "/" + dep.label.package)
direct_sources.append(dep[ProtoInfo].direct_sources)
transitive_sources.append(dep[ProtoInfo].transitive_imports.to_list())
Expand All @@ -149,25 +158,30 @@ def _node_proto_library_impl(ctx):
# print(deps)
print(direct_sources)
srcs = []
if not ctx.attr._is_grpc:
for src_list in direct_sources:
for src in src_list:
if src not in srcs:
srcs.append(src)
proto_path = _proto_path(src)
proto_path = proto_path[:proto_path.rfind("/")]
# Special logic for descriptor protobuf
paths.append(ctx.label.package + "/" + proto_path.replace("_virtual_imports/descriptor_proto/", ""))
print(ctx.label.package, proto_path.replace("_virtual_imports/descriptor_proto/", ""))
if not ctx.attr._is_grpc:
for src_list in transitive_sources:
for src in src_list:
if src not in srcs:
srcs.append(src)
proto_path = _proto_path(src)
proto_path = proto_path[:proto_path.rfind("/")]
print(ctx.label.package, proto_path.replace("_virtual_imports/descriptor_proto/", ""))
paths.append(ctx.label.package + "/" + proto_path.replace("_virtual_imports/descriptor_proto/", ""))
# if ctx.attr._is_grpc:
# srcs = direct_sources
# if not ctx.attr._is_grpc:
for src_list in direct_sources:
for src in src_list:
if src not in srcs:
srcs.append(src)
proto_path = _proto_path(src)
proto_path = proto_path[:proto_path.rfind("/")]
# Special logic for descriptor protobuf
paths.append(ctx.label.package + "/" + proto_path.replace("_virtual_imports/descriptor_proto/", ""))
print(ctx.label.package, proto_path.replace("_virtual_imports/descriptor_proto/", ""))
all_transitive_sources = []
# if not ctx.attr/._is_grpc:
for src_list in transitive_sources:
for src in src_list:
if src not in srcs:
# if not ctx.attr._is_grpc:
srcs.append(src)
proto_path = _proto_path(src)
proto_path = proto_path[:proto_path.rfind("/")]
print(ctx.label.package, proto_path.replace("_virtual_imports/descriptor_proto/", ""))
paths.append(ctx.label.package + "/" + proto_path.replace("_virtual_imports/descriptor_proto/", ""))
all_transitive_sources.append(src)
print(srcs)
srcs = _generate_node_grpc_web_srcs(
ctx.attr._is_grpc,
Expand All @@ -179,7 +193,7 @@ def _node_proto_library_impl(ctx):
import_style = ctx.attr.import_style,
mode = ctx.attr.mode,
sources = srcs,
transitive_sources = dep[ProtoInfo].transitive_imports,
transitive_sources = all_transitive_sources,
)

deps = [
Expand Down Expand Up @@ -254,7 +268,8 @@ node_grpc_web_proto_library = rule(
attrs = dict({
"deps": attr.label_list(
mandatory = True,
providers = [ProtoInfo],
providers = [],
# providers = [ProtoInfo],
),
"import_style": attr.string(
default = "commonjs",
Expand Down

0 comments on commit 7bf355f

Please sign in to comment.