-
-
Notifications
You must be signed in to change notification settings - Fork 678
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add @go_googleapis in go_rules_dependencies() (#1581)
@go_googleapis contains proto_library and go_proto_library rules for github.com/googleapis/googleapis. It's best to have a standard place for these to avoid conflicts, especially widely used generic protos like google/rpc/status.proto. Related #1548
- Loading branch information
Showing
107 changed files
with
3,229 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") | ||
|
||
proto_library( | ||
name = "color_service_proto", | ||
srcs = ["color_service.proto"], | ||
deps = [ | ||
"@go_googleapis//google/rpc:status_proto", | ||
"@go_googleapis//google/type:color_proto", | ||
], | ||
) | ||
|
||
go_proto_library( | ||
name = "color_service_go_proto", | ||
compilers = ["@io_bazel_rules_go//proto:go_grpc"], | ||
importpath = "github.com/bazelbuild/rules_go/tests/integration/googleapis/color_service_proto", | ||
proto = ":color_service_proto", | ||
deps = [ | ||
"@go_googleapis//google/rpc:status_go_proto", | ||
"@go_googleapis//google/type:color_go_proto", | ||
], | ||
) | ||
|
||
go_library( | ||
name = "color_service", | ||
importpath = "github.com/bazelbuild/rules_go/tests/integration/googleapis/color_service", | ||
srcs = ["color_service.go"], | ||
deps = [ | ||
":color_service_go_proto", | ||
"@go_googleapis//google/rpc:code_go_proto", | ||
"@go_googleapis//google/rpc:status_go_proto", | ||
"@go_googleapis//google/type:color_go_proto", | ||
], | ||
) | ||
|
||
go_test( | ||
name = "color_service_test", | ||
srcs = ["color_service_test.go"], | ||
deps = [ | ||
":color_service", | ||
":color_service_go_proto", | ||
"@go_googleapis//google/type:color_go_proto", | ||
"@org_golang_google_grpc//:go_default_library", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Functionality related to @go_googleapis | ||
======================================= | ||
|
||
color_service_test | ||
------------------ | ||
|
||
Verifies that a simple gRPC client and server can be built and run. .proto | ||
files are compiled at build time and depend on libraries in ``@go_googleapis``. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2018 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package color_service | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
cspb "github.com/bazelbuild/rules_go/tests/integration/googleapis/color_service_proto" | ||
"google.golang.org/genproto/googleapis/rpc/code" | ||
"google.golang.org/genproto/googleapis/rpc/status" | ||
"google.golang.org/genproto/googleapis/type/color" | ||
) | ||
|
||
type colorServer struct { | ||
colors sync.Map | ||
} | ||
|
||
func New() cspb.ColorServiceServer { | ||
return &colorServer{} | ||
} | ||
|
||
func (s *colorServer) SetColor(ctx context.Context, r *cspb.SetColorRequest) (*cspb.SetColorResponse, error) { | ||
_, loaded := s.colors.LoadOrStore(r.Name, r.Color) | ||
if loaded { | ||
return &cspb.SetColorResponse{Status: &status.Status{Code: int32(code.Code_ALREADY_EXISTS)}}, nil | ||
} | ||
return &cspb.SetColorResponse{}, nil | ||
} | ||
|
||
func (s *colorServer) GetColor(ctx context.Context, r *cspb.GetColorRequest) (*cspb.GetColorResponse, error) { | ||
value, ok := s.colors.Load(r.Name) | ||
if !ok { | ||
return &cspb.GetColorResponse{Status: &status.Status{Code: int32(code.Code_NOT_FOUND)}}, nil | ||
} | ||
return &cspb.GetColorResponse{Color: value.(*color.Color)}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2018 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
syntax = "proto3"; | ||
|
||
import "google/rpc/status.proto"; | ||
import "google/type/color.proto"; | ||
|
||
package rules_go.tests.integration.color_service; | ||
|
||
option go_package = "github.com/bazelbuild/rules_go/tests/integration/googleapis/color_service_proto"; | ||
|
||
message SetColorRequest { | ||
string name = 1; | ||
google.type.Color color = 2; | ||
} | ||
|
||
message SetColorResponse { | ||
google.rpc.Status status = 1; | ||
} | ||
|
||
message GetColorRequest { | ||
string name = 1; | ||
} | ||
|
||
message GetColorResponse { | ||
google.rpc.Status status = 1; | ||
google.type.Color color = 2; | ||
} | ||
|
||
service ColorService { | ||
rpc SetColor(SetColorRequest) returns (SetColorResponse); | ||
rpc GetColor(GetColorRequest) returns (GetColorResponse); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2018 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package color_service_test | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/bazelbuild/rules_go/tests/integration/googleapis/color_service" | ||
cspb "github.com/bazelbuild/rules_go/tests/integration/googleapis/color_service_proto" | ||
"google.golang.org/genproto/googleapis/type/color" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
func TestColorService(t *testing.T) { | ||
lis, err := net.Listen("tcp", "127.0.0.1:") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
grpcServer := grpc.NewServer() | ||
cspb.RegisterColorServiceServer(grpcServer, color_service.New()) | ||
go grpcServer.Serve(lis) | ||
defer grpcServer.Stop() | ||
|
||
conn, err := grpc.Dial(lis.Addr().String(), grpc.WithInsecure()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer conn.Close() | ||
client := cspb.NewColorServiceClient(conn) | ||
|
||
_, err = client.SetColor(context.Background(), &cspb.SetColorRequest{ | ||
Name: "red", | ||
Color: &color.Color{Red: 1.0}, | ||
}) | ||
if err != nil { | ||
t.Errorf("SetColor: %v", err) | ||
} | ||
resp, err := client.GetColor(context.Background(), &cspb.GetColorRequest{ | ||
Name: "red", | ||
}) | ||
if err != nil { | ||
t.Errorf("GetColor: %v", err) | ||
} | ||
want := &color.Color{Red: 1.0} | ||
if !reflect.DeepEqual(resp.Color, want) { | ||
t.Errorf("got %#v; want %#v", resp.Color, want) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# gazelle:proto package | ||
# gazelle:proto_group go_package | ||
# gazelle:exclude gapic | ||
# gazelle:exclude third_party |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# gazelle:prefix google.golang.org/genproto/googleapis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") | ||
|
||
proto_library( | ||
name = "annotations_proto", | ||
srcs = [ | ||
"annotations.proto", | ||
"http.proto", | ||
], | ||
visibility = ["//visibility:public"], | ||
deps = ["@com_google_protobuf//:descriptor_proto"], | ||
) | ||
|
||
proto_library( | ||
name = "configchange_proto", | ||
srcs = ["config_change.proto"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
proto_library( | ||
name = "distribution_proto", | ||
srcs = ["distribution.proto"], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
":annotations_proto", | ||
"@com_google_protobuf//:any_proto", | ||
"@com_google_protobuf//:timestamp_proto", | ||
], | ||
) | ||
|
||
proto_library( | ||
name = "httpbody_proto", | ||
srcs = ["httpbody.proto"], | ||
visibility = ["//visibility:public"], | ||
deps = ["@com_google_protobuf//:any_proto"], | ||
) | ||
|
||
proto_library( | ||
name = "label_proto", | ||
srcs = ["label.proto"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
proto_library( | ||
name = "metric_proto", | ||
srcs = ["metric.proto"], | ||
visibility = ["//visibility:public"], | ||
deps = [":label_proto"], | ||
) | ||
|
||
proto_library( | ||
name = "monitoredres_proto", | ||
srcs = ["monitored_resource.proto"], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
":label_proto", | ||
"@com_google_protobuf//:struct_proto", | ||
], | ||
) | ||
|
||
proto_library( | ||
name = "serviceconfig_proto", | ||
srcs = [ | ||
"auth.proto", | ||
"backend.proto", | ||
"billing.proto", | ||
"consumer.proto", | ||
"context.proto", | ||
"control.proto", | ||
"documentation.proto", | ||
"endpoint.proto", | ||
"log.proto", | ||
"logging.proto", | ||
"monitoring.proto", | ||
"quota.proto", | ||
"service.proto", | ||
"source_info.proto", | ||
"system_parameter.proto", | ||
"usage.proto", | ||
], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
":annotations_proto", | ||
":label_proto", | ||
":metric_proto", | ||
":monitoredres_proto", | ||
"//google/api/experimental:api_proto", | ||
"@com_google_protobuf//:any_proto", | ||
"@com_google_protobuf//:api_proto", | ||
"@com_google_protobuf//:type_proto", | ||
"@com_google_protobuf//:wrappers_proto", | ||
], | ||
) | ||
|
||
go_proto_library( | ||
name = "annotations_go_proto", | ||
importpath = "google.golang.org/genproto/googleapis/api/annotations", | ||
proto = ":annotations_proto", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
go_proto_library( | ||
name = "configchange_go_proto", | ||
importpath = "google.golang.org/genproto/googleapis/api/configchange", | ||
proto = ":configchange_proto", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
go_proto_library( | ||
name = "distribution_go_proto", | ||
importpath = "google.golang.org/genproto/googleapis/api/distribution", | ||
proto = ":distribution_proto", | ||
visibility = ["//visibility:public"], | ||
deps = [":annotations_go_proto"], | ||
) | ||
|
||
go_proto_library( | ||
name = "httpbody_go_proto", | ||
importpath = "google.golang.org/genproto/googleapis/api/httpbody", | ||
proto = ":httpbody_proto", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
go_proto_library( | ||
name = "label_go_proto", | ||
importpath = "google.golang.org/genproto/googleapis/api/label", | ||
proto = ":label_proto", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
go_proto_library( | ||
name = "metric_go_proto", | ||
importpath = "google.golang.org/genproto/googleapis/api/metric", | ||
proto = ":metric_proto", | ||
visibility = ["//visibility:public"], | ||
deps = [":label_go_proto"], | ||
) | ||
|
||
go_proto_library( | ||
name = "monitoredres_go_proto", | ||
importpath = "google.golang.org/genproto/googleapis/api/monitoredres", | ||
proto = ":monitoredres_proto", | ||
visibility = ["//visibility:public"], | ||
deps = [":label_go_proto"], | ||
) | ||
|
||
go_proto_library( | ||
name = "serviceconfig_go_proto", | ||
compilers = ["@io_bazel_rules_go//proto:go_grpc"], | ||
importpath = "google.golang.org/genproto/googleapis/api/serviceconfig", | ||
proto = ":serviceconfig_proto", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
":annotations_go_proto", | ||
":label_go_proto", | ||
":metric_go_proto", | ||
":monitoredres_go_proto", | ||
"//google/api/experimental:api_go_proto", | ||
], | ||
) |
Oops, something went wrong.
This repository seems to take an excruciating amount of time to clone over somewhat slower links. Would it make sense to use
http_archive
here instead?