Skip to content

Commit

Permalink
chore: make repo bazel aware & add microgen macro (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz authored Oct 15, 2019
1 parent 386d4fa commit ee3350e
Show file tree
Hide file tree
Showing 20 changed files with 735 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ Session.vim

# Temporary
*~

# Bazel directories
bazel-*
4 changes: 4 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
load("@bazel_gazelle//:def.bzl", "gazelle")

# gazelle:prefix github.com/googleapis/gapic-generator-go
gazelle(name = "gazelle")
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,49 @@ The configuration supported by the plugin option includes:
* Defaults to empty, which is essentially the GA release level.
* Acceptable values are `alpha` and `beta`.

Bazel
-----

The generator can be executed via a Bazel BUILD file using the macro in this repo.

Add the following to your WORKSPACE to import this project.

```
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "com_googleapis_gapic_generator_go",
strip_prefix = "gapic-generator-master",
urls = ["https://github.com/googleapis/gapic-generator-go/archive/master.zip"],
)
load("@com_googleapis_gapic_generator_go//:repositories.bzl", "com_googleapis_gapic_generator_go_repositories")
com_googleapis_gapic_generator_go_repositories()
```

_Note: do not use `master`, use a commit hash or a release tag._

And invoke it in a BUILD file like so, using an example based on the [googleapis repo](https://github.com/googleapis/googleapis/tree/92bebf78345af8b2d3585220527115bda8bdedf8/google/cloud/language/v1).

```
load("@com_googleapis_gapic_generator_go//:rules_go_gapic/go_gapic.bzl", "go_gapic_library")
go_gapic_library(
name = "language_go_gapic",
srcs = [
# BUILD target for proto_library
"//google/cloud/language/v1:language_proto",
],
deps = [
# BUILD target for go_library_proto
"//google/cloud/language/v1:language_go_proto",
],
# go-gapic-package parameter value
importpath = "cloud.google.com/go/language/apiv1;language",
)
```

Docker Wrapper
--------------
The generator can also be executed via a Docker container. The image containes `protoc`, the microgenerator
Expand Down
47 changes: 47 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
workspace(name = "com_googleapis_gapic_generator_go")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "com_google_protobuf",
strip_prefix = "protobuf-3.9.1",
urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.9.1.zip"],
sha256 = "c90d9e13564c0af85fd2912545ee47b57deded6e5a97de80395b6d2d9be64854",
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

http_archive(
name = "io_bazel_rules_go",
urls = [
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/rules_go/releases/download/v0.20.0/rules_go-v0.20.0.tar.gz",
"https://github.com/bazelbuild/rules_go/releases/download/v0.20.0/rules_go-v0.20.0.tar.gz",
],
sha256 = "078f2a9569fa9ed846e60805fb5fb167d6f6c4ece48e6d409bf5fb2154eaf0d8",
)

load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")

go_rules_dependencies()

go_register_toolchains()

http_archive(
name = "bazel_gazelle",
urls = [
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/bazel-gazelle/releases/download/0.18.2/bazel-gazelle-0.18.2.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/0.18.2/bazel-gazelle-0.18.2.tar.gz",
],
sha256 = "7fc87f4170011201b1690326e8c16c5d802836e3a0d617d8f75c3af2b23180c4",
)

# gazelle:repo bazel_gazelle
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

gazelle_dependencies()

load("//:repositories.bzl", "com_googleapis_gapic_generator_go_repositories")

com_googleapis_gapic_generator_go_repositories()
20 changes: 20 additions & 0 deletions cmd/gen-go-sample/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
name = "go_default_library",
srcs = ["main.go"],
importpath = "github.com/googleapis/gapic-generator-go/cmd/gen-go-sample",
visibility = ["//visibility:private"],
deps = [
"//internal/errors:go_default_library",
"//internal/gensample:go_default_library",
"@com_github_golang_protobuf//proto:go_default_library",
"@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
],
)

go_binary(
name = "gen-go-sample",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)
20 changes: 20 additions & 0 deletions cmd/protoc-gen-go_cli/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

# gazelle:proto disable_global
go_library(
name = "go_default_library",
srcs = ["main.go"],
importpath = "github.com/googleapis/gapic-generator-go/cmd/protoc-gen-go_cli",
visibility = ["//visibility:private"],
deps = [
"//internal/gencli:go_default_library",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_golang_protobuf//protoc-gen-go/plugin:go_default_library",
],
)

go_binary(
name = "protoc-gen-go_cli",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)
21 changes: 21 additions & 0 deletions cmd/protoc-gen-go_gapic/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

# gazelle:proto disable_global
go_library(
name = "go_default_library",
srcs = ["main.go"],
importpath = "github.com/googleapis/gapic-generator-go/cmd/protoc-gen-go_gapic",
visibility = ["//visibility:private"],
deps = [
"//internal/gengapic:go_default_library",
"//internal/gensample:go_default_library",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_golang_protobuf//protoc-gen-go/plugin:go_default_library",
],
)

go_binary(
name = "protoc-gen-go_gapic",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)
8 changes: 8 additions & 0 deletions internal/errors/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["errors.go"],
importpath = "github.com/googleapis/gapic-generator-go/internal/errors",
visibility = ["//:__subpackages__"],
)
44 changes: 44 additions & 0 deletions internal/gencli/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = [
"cmd_file.go",
"completion_file.go",
"flag.go",
"gencli.go",
"root_file.go",
"service_file.go",
"util.go",
],
importpath = "github.com/googleapis/gapic-generator-go/internal/gencli",
visibility = ["//:__subpackages__"],
deps = [
"//internal/errors:go_default_library",
"//internal/pbinfo:go_default_library",
"//internal/printer:go_default_library",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_jhump_protoreflect//desc:go_default_library",
"@go_googleapis//google/api:annotations_go_proto",
"@io_bazel_rules_go//proto/wkt:compiler_plugin_go_proto",
"@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
],
)

go_test(
name = "go_default_test",
srcs = [
"cmd_file_test.go",
"completion_file_test.go",
"flag_test.go",
"root_file_test.go",
"service_file_test.go",
],
data = glob(["testdata/**"]),
embed = [":go_default_library"],
deps = [
"//internal/pbinfo:go_default_library",
"//internal/txtdiff:go_default_library",
"@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
],
)
62 changes: 62 additions & 0 deletions internal/gengapic/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = [
"client_init.go",
"doc_file.go",
"example.go",
"gengapic.go",
"imports.go",
"lro.go",
"markdown.go",
"paging.go",
"service_config.go",
"stream.go",
],
importpath = "github.com/googleapis/gapic-generator-go/internal/gengapic",
visibility = ["//:__subpackages__"],
deps = [
"//internal/errors:go_default_library",
"//internal/grpc_service_config:go_default_library",
"//internal/license:go_default_library",
"//internal/pbinfo:go_default_library",
"//internal/printer:go_default_library",
"@com_github_golang_commonmark_markdown//:go_default_library",
"@com_github_golang_protobuf//jsonpb:go_default_library_gen",
"@com_github_golang_protobuf//proto:go_default_library",
"@go_googleapis//google/api:annotations_go_proto",
"@go_googleapis//google/longrunning:longrunning_go_proto",
"@in_gopkg_yaml_v2//:go_default_library",
"@io_bazel_rules_go//proto/wkt:compiler_plugin_go_proto",
"@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
"@io_bazel_rules_go//proto/wkt:duration_go_proto",
],
)

go_test(
name = "go_default_test",
srcs = [
"client_init_test.go",
"doc_file_test.go",
"example_test.go",
"gengapic_test.go",
"markdown_test.go",
"paging_test.go",
],
data = glob(["testdata/**"]),
embed = [":go_default_library"],
deps = [
"//internal/grpc_service_config:go_default_library",
"//internal/pbinfo:go_default_library",
"//internal/txtdiff:go_default_library",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_google_go_cmp//cmp:go_default_library",
"@go_googleapis//google/api:annotations_go_proto",
"@go_googleapis//google/longrunning:longrunning_go_proto",
"@go_googleapis//google/rpc:code_go_proto",
"@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
"@io_bazel_rules_go//proto/wkt:duration_go_proto",
"@io_bazel_rules_go//proto/wkt:wrappers_go_proto",
],
)
56 changes: 56 additions & 0 deletions internal/gensample/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = [
"bytes.go",
"enum.go",
"gapic.go",
"genmanifest.go",
"gensample.go",
"inittree.go",
"out.go",
"paging.go",
"plugin.go",
"primval.go",
"resource.go",
"sampmain.go",
"typing.go",
],
importpath = "github.com/googleapis/gapic-generator-go/internal/gensample",
visibility = ["//:__subpackages__"],
deps = [
"//internal/errors:go_default_library",
"//internal/gensample/schema_v1p2:go_default_library",
"//internal/license:go_default_library",
"//internal/pbinfo:go_default_library",
"//internal/printer:go_default_library",
"@in_gopkg_yaml_v2//:go_default_library",
"@io_bazel_rules_go//proto/wkt:compiler_plugin_go_proto",
"@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
],
)

go_test(
name = "go_default_test",
srcs = [
"enum_test.go",
"genmanifest_test.go",
"gensample_sampleconfig_test.go",
"gensample_test.go",
"inittree_test.go",
"resource_test.go",
],
data = glob(["testdata/**"]),
embed = [":go_default_library"],
deps = [
"//internal/errors:go_default_library",
"//internal/gensample/schema_v1p2:go_default_library",
"//internal/pbinfo:go_default_library",
"//internal/txtdiff:go_default_library",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_google_go_cmp//cmp:go_default_library",
"@in_gopkg_yaml_v2//:go_default_library",
"@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
],
)
8 changes: 8 additions & 0 deletions internal/gensample/schema_v1p2/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["schema.go"],
importpath = "github.com/googleapis/gapic-generator-go/internal/gensample/schema_v1p2",
visibility = ["//:__subpackages__"],
)
29 changes: 29 additions & 0 deletions internal/grpc_service_config/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

proto_library(
name = "grpc_service_config_proto",
srcs = ["grpc_service_config.proto"],
visibility = ["//:__subpackages__"],
deps = [
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:wrappers_proto",
"@go_googleapis//google/rpc:code_proto",
],
)

go_proto_library(
name = "grpc_service_config_go_proto",
compilers = ["@io_bazel_rules_go//proto:go_grpc"],
importpath = "github.com/googleapis/gapic-generator-go/internal/grpc_service_config",
proto = ":grpc_service_config_proto",
visibility = ["//:__subpackages__"],
deps = ["@go_googleapis//google/rpc:code_go_proto"],
)

go_library(
name = "go_default_library",
embed = [":grpc_service_config_go_proto"],
importpath = "github.com/googleapis/gapic-generator-go/internal/grpc_service_config",
visibility = ["//visibility:public"],
)
8 changes: 8 additions & 0 deletions internal/license/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["license.go"],
importpath = "github.com/googleapis/gapic-generator-go/internal/license",
visibility = ["//:__subpackages__"],
)
Loading

0 comments on commit ee3350e

Please sign in to comment.