Skip to content

Commit

Permalink
Add @go_googleapis in go_rules_dependencies() (#1581)
Browse files Browse the repository at this point in the history
@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
jayconrod authored Jul 3, 2018
1 parent 3fcd473 commit 9ff93c2
Show file tree
Hide file tree
Showing 107 changed files with 3,229 additions and 0 deletions.
7 changes: 7 additions & 0 deletions go/private/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ def go_rules_dependencies():
# TODO(jayconrod): incorporate manual changes when regenerating build
# files. This repo contains aliases for //proto/wkt targets.
)
_maybe(
git_repository,

This comment has been minimized.

Copy link
@EdSchouten

EdSchouten Jul 26, 2018

Contributor

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?

name = "go_googleapis",
remote = "https://github.com/googleapis/googleapis",
commit = "6a3277c0656219174ff7c345f31fb20a90b30b97", # master as of 2018-07-01
overlay = manifest["go_googleapis"],
)

# Needed for examples
_maybe(
Expand Down
45 changes: 45 additions & 0 deletions tests/integration/googleapis/BUILD.bazel
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",
],
)
8 changes: 8 additions & 0 deletions tests/integration/googleapis/README.rst
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``.
49 changes: 49 additions & 0 deletions tests/integration/googleapis/color_service.go
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
}
45 changes: 45 additions & 0 deletions tests/integration/googleapis/color_service.proto
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);
}
63 changes: 63 additions & 0 deletions tests/integration/googleapis/color_service_test.go
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)
}
}
4 changes: 4 additions & 0 deletions third_party/go_googleapis/BUILD.in
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
1 change: 1 addition & 0 deletions third_party/go_googleapis/google/BUILD.bazel.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# gazelle:prefix google.golang.org/genproto/googleapis
159 changes: 159 additions & 0 deletions third_party/go_googleapis/google/api/BUILD.bazel.in
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",
],
)
Loading

0 comments on commit 9ff93c2

Please sign in to comment.