From 7bf355f0a157724d115e0c87173af26285019f24 Mon Sep 17 00:00:00 2001 From: anders617 Date: Mon, 11 Nov 2019 18:45:37 -0500 Subject: [PATCH] Added hearts --- proto/BUILD | 16 ++++++++++++ proto/hearts.proto | 8 ++++++ proto/mdining.proto | 24 ++++++++++++++++++ rules/defs.bzl | 59 ++++++++++++++++++++++++++++----------------- 4 files changed, 85 insertions(+), 22 deletions(-) create mode 100644 proto/hearts.proto diff --git a/proto/BUILD b/proto/BUILD index f1719f1..f42b21c 100644 --- a/proto/BUILD +++ b/proto/BUILD @@ -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"], @@ -62,6 +68,7 @@ proto_library( ":menu_proto", ":food_proto", ":foodstat_proto", + ":hearts_proto", "@com_googleapis_googleapis//google/api:annotations_proto", ], ) @@ -123,6 +130,7 @@ go_proto_library( ":menu_proto", ":food_proto", ":foodstat_proto", + ":hearts_proto", ], visibility = ["//visibility:public"], deps = [ @@ -146,6 +154,7 @@ node_grpc_web_proto_library( name = "mdining_grpcweb_proto", deps = [ ":mdining_proto", + ":mdining_node_proto", ], mode = "grpcweb", ) @@ -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"], @@ -241,5 +256,6 @@ cc_library( ":menu_cc_proto", ":food_cc_proto", ":foodstat_cc_proto", + ":hearts_cc_proto", ] ) diff --git a/proto/hearts.proto b/proto/hearts.proto new file mode 100644 index 0000000..e360337 --- /dev/null +++ b/proto/hearts.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + +package mdining; + +message HeartCount { + string key = 1; + int64 count = 2; +} diff --git a/proto/mdining.proto b/proto/mdining.proto index 7e2c32e..1914ec5 100644 --- a/proto/mdining.proto +++ b/proto/mdining.proto @@ -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) { @@ -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 {} @@ -96,3 +112,11 @@ message FoodRequest { message FoodReply { repeated Food foods = 1; } + +message HeartsRequest { + repeated string keys = 1; +} + +message HeartsReply { + repeated HeartCount counts = 1; +} diff --git a/rules/defs.bzl b/rules/defs.bzl index dd8dea9..7034cbd 100644 --- a/rules/defs.bzl +++ b/rules/defs.bzl @@ -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( @@ -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]), @@ -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()) @@ -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, @@ -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 = [ @@ -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",