diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 0000000000..21f0bf88f2 --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,20 @@ +load("@gapic_generator_python_pip_deps//:requirements.bzl", "requirement") + +py_binary( + name = "gapic_plugin", + srcs = glob(["gapic/**/*.py"]), + data = glob(["gapic/**/*.j2"]), + main = "gapic/cli/generate.py", + visibility = ["//visibility:public"], + deps = [ + "@com_google_protobuf//:protobuf_python", + requirement("click"), + requirement("google-api-core"), + requirement("googleapis-common-protos"), + requirement("grpcio"), + requirement("jinja2"), + requirement("pypandoc"), + requirement("PyYAML"), + ], + python_version = "PY3", +) \ No newline at end of file diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 0000000000..57a357e7b9 --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,35 @@ +workspace(name = "gapic_generator_python") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +# +# Import rules_python +# +http_archive( + name = "rules_python", + strip_prefix = "rules_python-748aa53d7701e71101dfd15d800e100f6ff8e5d1", + url = "https://github.com/bazelbuild/rules_python/archive/748aa53d7701e71101dfd15d800e100f6ff8e5d1.zip", +) + +load("@rules_python//python:repositories.bzl", "py_repositories") + +py_repositories() + +load("@rules_python//python:pip.bzl", "pip_repositories") + +pip_repositories() + +# +# Import gapic-generator-python specific dependencies +# +load("//:repositories.bzl", "gapic_generator_python") + +gapic_generator_python() + +load("@gapic_generator_python_pip_deps//:requirements.bzl", "pip_install") + +pip_install() + +load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") + +protobuf_deps() diff --git a/repositories.bzl b/repositories.bzl new file mode 100644 index 0000000000..ed39838d4f --- /dev/null +++ b/repositories.bzl @@ -0,0 +1,41 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@rules_python//python:pip.bzl", "pip_import") + +def gapic_generator_python(): + _maybe( + pip_import, + name = "gapic_generator_python_pip_deps", + python_interpreter = "python3", + requirements = "@gapic_generator_python//:requirements.txt", + ) + + _protobuf_version = "3.11.2" + _protobuf_version_in_link = "v%s" % _protobuf_version + _maybe( + http_archive, + name = "com_google_protobuf", + urls = ["https://github.com/protocolbuffers/protobuf/archive/%s.zip" % _protobuf_version_in_link], + strip_prefix = "protobuf-%s" % _protobuf_version, + ) + + _maybe( + http_archive, + name = "bazel_skylib", + strip_prefix = "bazel-skylib-2169ae1c374aab4a09aa90e65efe1a3aad4e279b", + urls = ["https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz"], + ) + + _maybe( + http_archive, + name = "com_google_api_codegen", + strip_prefix = "gapic-generator-b32c73219d617f90de70bfa6ff0ea0b0dd638dfe", + urls = ["https://github.com/googleapis/gapic-generator/archive/b32c73219d617f90de70bfa6ff0ea0b0dd638dfe.zip"], + ) + +def _maybe(repo_rule, name, strip_repo_prefix = "", **kwargs): + if not name.startswith(strip_repo_prefix): + return + repo_name = name[len(strip_repo_prefix):] + if repo_name in native.existing_rules(): + return + repo_rule(name = repo_name, **kwargs) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000..9cdcdd7574 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +click >= 6.7 +google-api-core >= 1.14.3 +googleapis-common-protos >= 1.6.0 +grpcio >= 1.24.3 +jinja2 >= 2.10 +protobuf >= 3.7.1 +pypandoc >= 1.4 +PyYAML >= 5.1.1 diff --git a/rules_python_gapic/BUILD.bazel b/rules_python_gapic/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/rules_python_gapic/py_gapic.bzl b/rules_python_gapic/py_gapic.bzl new file mode 100644 index 0000000000..50d792b82b --- /dev/null +++ b/rules_python_gapic/py_gapic.bzl @@ -0,0 +1,31 @@ +# Copyright 2020 Google LLC +# +# 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 +# +# https://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. + +load("@com_google_api_codegen//rules_gapic:gapic.bzl", "proto_custom_library") + +def py_gapic_library(name, srcs, **kwargs): + # srcjar_target_name = "%s_srcjar" % name + srcjar_target_name = name + srcjar_output_suffix = ".srcjar" + + proto_custom_library( + name = srcjar_target_name, + deps = srcs, + plugin = Label("@gapic_generator_python//:gapic_plugin"), + plugin_args = [], + plugin_file_args = {}, + output_type = "python_gapic", + output_suffix = srcjar_output_suffix, + **kwargs + )