Skip to content

Commit 299b32e

Browse files
committed
for testing purposes
1 parent eceea95 commit 299b32e

6 files changed

Lines changed: 137 additions & 87 deletions

File tree

.github/workflows/gapic-generator-tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ permissions:
33

44
name: Gapic Generator Specialized Tests
55

6+
# trigger job
67
on:
78
pull_request:
89
push:
@@ -219,7 +220,8 @@ jobs:
219220
# Only runs if the Gatekeeper passed
220221
if: ${{ needs.python_config.result == 'success' }}
221222
runs-on: ubuntu-latest
222-
container: gcr.io/gapic-images/googleapis # zizmor: ignore[unpinned-images]
223+
container:
224+
image: gcr.io/gapic-images/googleapis # zizmor: ignore[unpinned-images]
223225
steps:
224226
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
225227
with:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# See https://github.com/bazelbuild/bazelisk
2-
USE_BAZEL_VERSION=6.5.0
2+
USE_BAZEL_VERSION=7.7.1

packages/gapic-generator/.bazelrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
# New protobuf requires C++17
22
build --repo_env=BAZEL_CXXOPTS="-std=c++17"
3+
4+
# Workaround for rules_python precompilation bug with directory outputs:
5+
# Newer rules_python (v0.40.0+) attempts to precompile (.py -> .pyc) sources.
6+
# GAPIC code generator rules (e.g., //tests/integration:asset_py_gapic) output a
7+
# directory structure of generated code instead of discrete individual files.
8+
# This triggers: "Error in add: Cannot add directories to Args#add since they may expand to multiple values".
9+
# Disabling precompilation bypasses the bug without affecting runtime behavior.
10+
build --@rules_python//python/config_settings:precompile=force_disabled
11+
12+
common --noenable_bzlmod

packages/gapic-generator/WORKSPACE

Lines changed: 85 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,124 +2,144 @@ workspace(name = "gapic_generator_python")
22

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

5-
_bazel_skylib_version = "1.4.0"
5+
# =========================================================================
6+
# 1. LOAD MODERN DEPENDENCIES FIRST (CRITICAL: FIRST-LOAD WINS)
7+
# =========================================================================
8+
# Load Protobuf 35.1
9+
http_archive(
10+
name = "com_google_protobuf",
11+
strip_prefix = "protobuf-35.1",
12+
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v35.1/protobuf-35.1.zip"],
13+
)
614

7-
_bazel_skylib_sha256 = "f24ab666394232f834f74d19e2ff142b0af17466ea0c69a3f4c276ee75f6efce"
15+
# Load standard, unpatched rules_gapic v1.0.0
16+
http_archive(
17+
name = "rules_gapic",
18+
strip_prefix = "rules_gapic-1.0.0",
19+
urls = [
20+
"https://github.com/googleapis/rules_gapic/archive/v1.0.0.tar.gz"
21+
],
22+
patch_cmds = [
23+
# Safely buffer files in memory first to prevent truncation, then insert the load statement [11]
24+
"python3 -c \"import glob; [open(f, 'w').write('load(\\\"@rules_proto//proto:defs.bzl\\\", \\\"ProtoInfo\\\")\\n' + c) for f, c in [(f, open(f).read()) for f in glob.glob('**/*.bzl', recursive=True)] if 'ProtoInfo' in c and '@rules_proto//proto:defs.bzl' not in c]\""
25+
],
26+
)
827

28+
http_archive(
29+
name = "rules_cc",
30+
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.1.5/rules_cc-0.1.5.tar.gz"],
31+
strip_prefix = "rules_cc-0.1.5",
32+
)
33+
34+
_bazel_skylib_version = "1.9.0"
935
http_archive(
1036
name = "bazel_skylib",
11-
sha256 = _bazel_skylib_sha256,
1237
url = "https://github.com/bazelbuild/bazel-skylib/releases/download/{0}/bazel-skylib-{0}.tar.gz".format(_bazel_skylib_version),
1338
)
1439

40+
http_archive(
41+
name = "com_google_absl",
42+
strip_prefix = "abseil-cpp-20240722.1",
43+
urls = [
44+
"https://github.com/abseil/abseil-cpp/releases/download/20240722.1/abseil-cpp-20240722.1.tar.gz",
45+
],
46+
)
47+
1548
_io_bazel_rules_go_version = "0.33.0"
1649
http_archive(
1750
name = "io_bazel_rules_go",
18-
sha256 = "685052b498b6ddfe562ca7a97736741d87916fe536623afb7da2824c0211c369",
1951
urls = [
2052
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v{0}/rules_go-v{0}.zip".format(_io_bazel_rules_go_version),
2153
"https://github.com/bazelbuild/rules_go/releases/download/v{0}/rules_go-v{0}.zip".format(_io_bazel_rules_go_version),
2254
],
2355
)
2456

25-
_rules_python_version = "0.26.0"
26-
27-
_rules_python_sha256 = "9d04041ac92a0985e344235f5d946f71ac543f1b1565f2cdbc9a2aaee8adf55b"
28-
57+
# =========================================================================
58+
# UPGRADED: rules_python v1.1.0 (No sha256) [11]
59+
# =========================================================================
60+
_rules_python_version = "1.1.0"
2961
http_archive(
3062
name = "rules_python",
31-
sha256 = _rules_python_sha256,
3263
strip_prefix = "rules_python-{}".format(_rules_python_version),
33-
url = "https://github.com/bazelbuild/rules_python/archive/{}.tar.gz".format(_rules_python_version),
64+
url = "https://github.com/bazelbuild/rules_python/releases/download/{0}/rules_python-{0}.tar.gz".format(_rules_python_version),
3465
)
3566

3667
load("@rules_python//python:repositories.bzl", "py_repositories")
37-
3868
py_repositories()
3969

4070
load("@rules_python//python:pip.bzl", "pip_parse")
41-
42-
4371
pip_parse(
4472
name = "gapic_generator_python_pip_deps",
45-
requirements_lock = "//:requirements.txt",
73+
requirements_lock = "//:requirements.txt",
4674
)
47-
load("@gapic_generator_python_pip_deps//:requirements.bzl", "install_deps")
4875

76+
load("@gapic_generator_python_pip_deps//:requirements.bzl", "install_deps")
4977
install_deps()
50-
#
51-
# Import gapic-generator-python specific dependencies
52-
#
53-
load(
54-
"//:repositories.bzl",
55-
"gapic_generator_python",
56-
"gapic_generator_register_toolchains",
57-
)
58-
59-
gapic_generator_python()
60-
61-
gapic_generator_register_toolchains()
62-
63-
_grpc_version = "1.71.0"
64-
65-
_grpc_sha256 = "9313c3f8f4dd3341597f152d506a50caf571fe40f886e24ea9078891990df285"
6678

79+
# =========================================================================
80+
# 2. LOAD THE UNPATCHED UPSTREAM gRPC REPOSITORY
81+
# =========================================================================
82+
_grpc_version = "816506e5c0434a42414af6955cc9eef0c562ff3a"
6783
http_archive(
6884
name = "com_github_grpc_grpc",
69-
sha256 = _grpc_sha256,
70-
strip_prefix = "grpc-%s" % _grpc_version,
71-
urls = ["https://github.com/grpc/grpc/archive/v%s.zip" % _grpc_version],
85+
strip_prefix = "grpc-816506e5c0434a42414af6955cc9eef0c562ff3a",
86+
urls = ["https://github.com/grpc/grpc/archive/816506e5c0434a42414af6955cc9eef0c562ff3a.zip"],
7287
)
73-
# instantiated in grpc_deps().
74-
75-
_protobuf_version = "30.2"
7688

77-
_protobuf_sha256 = "07a43d88fe5a38e434c7f94129cad56a4c43a51f99336074d0799c2f7d4e44c5"
78-
79-
http_archive(
80-
name = "com_google_protobuf",
81-
sha256 = _protobuf_sha256,
82-
strip_prefix = "protobuf-%s" % _protobuf_version,
83-
urls = ["https://github.com/protocolbuffers/protobuf/archive/v%s.tar.gz" % _protobuf_version],
84-
)
8589
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
86-
8790
grpc_deps()
8891

89-
http_archive(
90-
name = "rules_cc",
91-
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.1.1/rules_cc-0.1.1.tar.gz"],
92-
sha256 = "712d77868b3152dd618c4d64faaddefcc5965f90f5de6e6dd1d5ddcd0be82d42",
93-
strip_prefix = "rules_cc-0.1.1",
92+
# =========================================================================
93+
# 3. LOAD GAPIC-GENERATOR DEPENDENCIES
94+
# =========================================================================
95+
load(
96+
"//:repositories.bzl",
97+
"gapic_generator_python",
98+
"gapic_generator_register_toolchains",
9499
)
100+
gapic_generator_python()
101+
gapic_generator_register_toolchains()
95102

96-
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps", "PROTOBUF_MAVEN_ARTIFACTS")
97-
# This is actually already done within grpc_deps but calling this for Bazel convention.
98-
protobuf_deps()
99-
100-
# Add rules_java to resolve the following error
101-
# `The repository '@compatibility_proxy' could not be resolved: Repository '@compatibility_proxy' is not defined`
103+
# Add rules_java to resolve compatibility proxy errors
102104
load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")
103-
104105
rules_java_dependencies()
105106

106-
# gRPC enforces a specific version of Go toolchain which conflicts with our build.
107-
# All the relevant parts of grpc_extra_deps() are imported in this WORKSPACE file
108-
# explicitly, that is why we do not call grpc_extra_deps() here and call
109-
# apple_rules_dependencies and apple_support_dependencies macros explicitly.
107+
# =========================================================================
108+
# 4. LOAD TRANSITIVE PROTO DEPENDENCIES & REGISTER TOOLCHAINS
109+
# =========================================================================
110+
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
111+
protobuf_deps()
110112

111-
load("@build_bazel_rules_apple//apple:repositories.bzl", "apple_rules_dependencies")
113+
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")
114+
rules_proto_dependencies()
115+
116+
load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains")
117+
rules_proto_toolchains()
112118

119+
# =========================================================================
120+
# 5. LOAD SUPPORTING PLATFORMS
121+
# =========================================================================
122+
load("@build_bazel_rules_apple//apple:repositories.bzl", "apple_rules_dependencies")
113123
apple_rules_dependencies()
114124

115125
load("@build_bazel_apple_support//lib:repositories.bzl", "apple_support_dependencies")
116-
117126
apple_support_dependencies()
118127

119128
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
120-
121129
switched_rules_by_language(
122130
name = "com_google_googleapis_imports",
123131
gapic = True,
124132
grpc = True,
125133
)
134+
load("@rules_python//python:repositories.bzl", "python_register_multi_toolchains")
135+
136+
python_register_multi_toolchains(
137+
name = "python",
138+
ignore_root_user_error = True,
139+
python_versions = [
140+
"3.10",
141+
"3.11",
142+
"3.12",
143+
"3.13",
144+
],
145+
)

packages/gapic-generator/repositories.bzl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ def gapic_generator_python():
1616
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz"],
1717
)
1818

19-
_grpc_version = "1.47.0"
20-
_grpc_sha256 = "edf25f4db6c841853b7a29d61b0980b516dc31a1b6cdc399bcf24c1446a4a249"
19+
_grpc_version = "1.82.0"
2120
_maybe(
2221
http_archive,
2322
name = "com_github_grpc_grpc",
24-
sha256 = _grpc_sha256,
2523
strip_prefix = "grpc-{}".format(_grpc_version),
2624
url = "https://github.com/grpc/grpc/archive/v{}.zip".format(_grpc_version),
2725
)

packages/gapic-generator/rules_python_gapic/py_gapic.bzl

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,41 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
load("@rules_gapic//:gapic.bzl", "proto_custom_library", "unzipped_srcjar")
15+
load("@rules_gapic//:gapic.bzl", "proto_custom_library", "unzipped_srcjar", "CustomProtoInfo")
1616
load("@rules_python//python:defs.bzl", "py_library")
1717
load("@gapic_generator_python_pip_deps//:requirements.bzl", "requirement")
1818

19+
# Load the modern Starlark ProtoInfo under an alias [11]
20+
load("@rules_proto//proto:defs.bzl", StarlarkProtoInfo = "ProtoInfo")
21+
22+
def _gapic_compat_proto_library_impl(ctx):
23+
dep = ctx.attr.dep
24+
starlark_proto = dep[StarlarkProtoInfo]
25+
return [
26+
# Construct CustomProtoInfo natively in Starlark, bypassing the native C++ constructor! [11]
27+
CustomProtoInfo(
28+
direct_sources = starlark_proto.direct_sources,
29+
check_deps_sources = starlark_proto.check_deps_sources,
30+
# Map legacy transitive_imports to the modern transitive_sources attribute [7]
31+
transitive_imports = starlark_proto.transitive_sources,
32+
transitive_descriptor_sets = starlark_proto.transitive_descriptor_sets,
33+
)
34+
]
35+
36+
gapic_compat_proto_library = rule(
37+
implementation = _gapic_compat_proto_library_impl,
38+
attrs = {
39+
"dep": attr.label(mandatory = True, providers = [StarlarkProtoInfo]),
40+
}
41+
)
42+
1943
def _gapic_test_file_impl(ctx):
2044
generated_test_file = ctx.actions.declare_file(ctx.label.name)
21-
2245
ctx.actions.expand_template(
2346
template = ctx.attr.template.files.to_list()[0],
2447
output = generated_test_file,
2548
substitutions = {},
2649
)
27-
2850
return [DefaultInfo(files = depset(direct = [generated_test_file]))]
2951

3052
gapic_test_file = rule(
@@ -46,30 +68,36 @@ def py_gapic_library(
4668
rest_numeric_enums = False,
4769
deps = [],
4870
**kwargs):
71+
72+
# 1. Dynamically wrap the input srcs with our legacy native provider converter [11]
73+
compat_srcs = []
74+
for i, src in enumerate(srcs):
75+
compat_name = "%s_compat_src_%d" % (name, i)
76+
gapic_compat_proto_library(
77+
name = compat_name,
78+
dep = src,
79+
)
80+
compat_srcs.append(":%s" % compat_name)
81+
4982
srcjar_target_name = "%s_srcjar" % name
5083
srcjar_output_suffix = ".srcjar"
51-
5284
plugin_args = plugin_args or []
5385
opt_args = opt_args or []
54-
5586
if metadata:
5687
plugin_args.append("metadata")
57-
5888
file_args = {}
5989
if grpc_service_config:
6090
file_args[grpc_service_config] = "retry-config"
6191
if service_yaml:
6292
file_args[service_yaml] = "service-yaml"
63-
6493
if transport:
6594
opt_args = opt_args + ["transport=%s" % transport]
66-
6795
if rest_numeric_enums:
6896
opt_args = opt_args + ["rest-numeric-enums"]
6997

7098
proto_custom_library(
7199
name = srcjar_target_name,
72-
deps = srcs,
100+
deps = compat_srcs, # <--- Changed this from 'srcs' to 'compat_srcs'! [11]
73101
plugin = Label("@gapic_generator_python//:gapic_plugin"),
74102
plugin_args = plugin_args,
75103
plugin_file_args = file_args,
@@ -78,15 +106,12 @@ def py_gapic_library(
78106
output_suffix = srcjar_output_suffix,
79107
**kwargs
80108
)
81-
82109
main_file = "%s" % srcjar_target_name + srcjar_output_suffix
83110
main_dir = "%s.py" % srcjar_target_name
84-
85111
unzipped_srcjar(
86112
name = main_dir,
87113
srcjar = ":%s" % main_file,
88114
)
89-
90115
actual_deps = deps + [
91116
"@com_github_grpc_grpc//src/python/grpcio/grpc:grpcio",
92117
requirement("protobuf"),
@@ -96,22 +121,17 @@ def py_gapic_library(
96121
requirement("pytest-asyncio"),
97122
requirement("aiohttp")
98123
]
99-
100124
py_library(
101125
name = name,
102126
srcs = [":%s" % main_dir],
103127
deps = actual_deps,
104128
)
105-
106129
test_file_target_name = "%s_test.py" % name
107-
108130
gapic_test_file(
109131
name = test_file_target_name,
110132
template = Label("//rules_python_gapic:test.py"),
111133
)
112-
113134
test_runner_file_target_name = "%s_pytest.py" % name
114-
115135
gapic_test_file(
116136
name = test_runner_file_target_name,
117137
template = Label("//rules_python_gapic:pytest.py"),

0 commit comments

Comments
 (0)