Skip to content

Commit 5129d36

Browse files
authored
chore(librarian): fix generation for google-cloud-compute (#14612)
This PR resolves the following stack trace when generating google-cloud-compute ``` Traceback (most recent call last): File "/app/./cli.py", line 532, in handle_generate _generate_api(api_path, library_id, source, output, version) File "/app/./cli.py", line 761, in _generate_api py_gapic_config = _read_bazel_build_py_rule(api_path, source) File "/app/./cli.py", line 556, in _read_bazel_build_py_rule result = parse_googleapis_content.parse_content(content) File "/app/parse_googleapis_content.py", line 133, in parse_content sl.eval(mod, ast, glb, sl.FileLoader(load)) starlark.StarlarkError: error: Variable `exports_files` not found --> BUILD.bazel:6:1 | 6 | exports_files(glob(include = ["*grpc_service_config.json"])) | ^^^^^^^^^^^^^ | The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/app/./cli.py", line 1406, in <module> args.func( File "/app/./cli.py", line 538, in handle_generate raise ValueError("Generation failed.") from e ValueError: Generation failed. ```
1 parent 88db83f commit 5129d36

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

.generator/parse_googleapis_content.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,15 @@
9595
"proto_library",
9696
"java_proto_library",
9797
"genrule",
98+
"gapic_yaml_from_disco",
99+
"grpc_service_config_from_disco",
100+
"proto_from_disco",
98101
)
99102

103+
_GLOB_CALLABLES = (
104+
"exports_files",
105+
"glob",
106+
)
100107

101108
def parse_content(content: str) -> dict:
102109
"""Parses content from BUILD.bazel and returns a dictionary
@@ -119,11 +126,20 @@ def bazel_target(**args):
119126
def noop_bazel_rule(**args):
120127
pass
121128

122-
for noop_callable in _NOOP_CALLABLES:
123-
mod.add_callable(noop_callable, noop_bazel_rule)
129+
def fake_glob(paths=[], **args):
130+
return []
131+
132+
mod.add_callable("package", noop_bazel_rule)
133+
134+
for glob_callable in _GLOB_CALLABLES:
135+
mod.add_callable(glob_callable, fake_glob)
124136

125137
def load(name):
126138
mod = sl.Module()
139+
140+
for noop_callable in _NOOP_CALLABLES:
141+
mod.add_callable(noop_callable, noop_bazel_rule)
142+
127143
for callable_name in _CALLABLE_MAP.get(name, []):
128144
mod.add_callable(callable_name, bazel_target)
129145
return mod.freeze()

.generator/test-resources/librarian/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
package(default_visibility = ["//visibility:public"])
16+
exports_files(glob(["*.yaml"]))
1617
load("@rules_proto//proto:defs.bzl", "proto_library")
1718
load(
1819
"@com_google_googleapis_imports//:imports.bzl",

0 commit comments

Comments
 (0)