Skip to content

Commit dc8fe7c

Browse files
zhangskzcopybara-github
authored andcommitted
Loosen py_proto_library check for paths with hyphens to exclude import prefixes (i.e. external/module-name) .
These do not actually make it into the name used in python imports, so this should allow modules with hyphens in their name (i.e. `bazel build @com_google_protobuf-examples//:addressbook_py_pb2). PiperOrigin-RevId: 732189971
1 parent 864001d commit dc8fe7c

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

.github/workflows/test_bazel.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,16 @@ jobs:
5151
shell: bash
5252
run: echo "${{ matrix.bazelversion }}" > .bazelversion
5353

54-
- name: Run tests
54+
- name: Run tests
55+
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
56+
uses: protocolbuffers/protobuf-ci/bazel@v4
57+
with:
58+
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
59+
bazel-cache: examples-from-protobuf
60+
version: ${{ matrix.bazelversion }}
61+
bash: bazel test @com_google_protobuf-examples//... $BAZEL_FLAGS --enable_bzlmod=${{ matrix.bzlmod }} --enable_workspace=${{ !matrix.bzlmod }} ${{ matrix.toolchain_resolution }}
62+
63+
- name: Run tests (examples)
5564
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
5665
uses: protocolbuffers/protobuf-ci/bazel@v4
5766
with:

MODULE.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,9 @@ use_repo(cc_configure, "local_config_cc")
134134

135135
# rules_proto are needed for @com_google_protobuf_v25.0 used in //compatibility/... tests
136136
bazel_dep(name = "rules_proto", version = "4.0.0", dev_dependency = True)
137+
138+
bazel_dep(name = "com_google_protobuf-examples", version = "0.0.0")
139+
local_path_override(
140+
module_name = "com_google_protobuf-examples",
141+
path = "examples/",
142+
)

bazel/py_proto_library.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ def _py_proto_aspect_impl(target, ctx):
4444

4545
# Check Proto file names
4646
for proto in target[ProtoInfo].direct_sources:
47-
if proto.is_source and "-" in proto.dirname:
48-
fail("Cannot generate Python code for a .proto whose path contains '-' ({}).".format(
47+
import_path = proto_common.get_import_path(proto)
48+
if proto.is_source and "-" in import_path:
49+
fail("Cannot generate Python code for a .proto whose python import path contains '-' ({}).".format(
4950
proto.path,
5051
))
5152

examples/MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Bazel module dependencies"""
22

33
module(
4-
name = "com_google_protobuf_examples",
4+
name = "com_google_protobuf-examples",
55
version = "0.0.0",
66
compatibility_level = 1,
77
)

examples/WORKSPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
workspace(name = "com_google_protobuf_examples")
1+
workspace(name = "com_google_protobuf-examples")
22

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

0 commit comments

Comments
 (0)