Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicated label "@com_google_protobuf//:protobuf_python" in the deps of a py_proto_library #9688

Closed
epertoso opened this issue Mar 28, 2022 · 3 comments
Assignees

Comments

@epertoso
Copy link

What version of protobuf and what language are you using?
Version: v3.20.0
Language: Python

What operating system (Linux, Windows, ...) and version?
GNU/Linux (Debian Buster, dockerized)

What runtime / compiler are you using (e.g., python version or gcc version)
Python 3.10.3

What did you do?
Steps to reproduce the behavior:

  1. Build the test_py target in the minimal example given below ($ bazel build :test_py)

What did you expect to see
A successful build.

What did you see instead?

ERROR: /home/epertoso/test/BUILD:3:17: Label '@com_google_protobuf//:protobuf_python' is duplicated in the 'deps' attribute of rule 'test_py'
ERROR: error loading package '': Package '' contains errors
INFO: Elapsed time: 0.038s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

Anything else we should know about your project / environment
We depend on gRPC, which in turns depend on protoc-gen-validate. We saw the error after updating protobuf to v3.20, the failing target is validate_py.

The error was introduced by this PR: #9187, as the test

if default_runtime and not default_runtime in py_libs + deps:
fails because py_libs and deps contain strings, and not Labels.

Minimal example

WORKSPACE

workspace(name = "test")

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

http_archive(
    name = "com_google_protobuf",
    sha256 = "b07772d38ab07e55eca4d50f4b53da2d998bb221575c60a4f81100242d4b4889",
    strip_prefix = "protobuf-3.20.0",
    urls = ["https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.20.0.tar.gz"],
)

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

protobuf_deps()

BUILD

load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")

py_proto_library(
    name = "test_py",
    srcs = ["test.proto"],
    deps = ["@com_google_protobuf//:protobuf_python"],
)

test.proto

syntax = "proto2";
package test;

message Foo { optional int32 bar = 1; }
@acozzette
Copy link
Member

@epertoso Thank you for the detailed bug report. The test case was easy to reproduce.

@Wyverald @meteorcloudy Do you have any ideas on how to fix this? It seems to me like we just need to deduplicate a Label against a list of strings, but it's not entirely obvious to me how to do that. The two possibilities that come to mind are:

  1. Convert the Label to a string and just operate on strings. This looks like it should work, but the fact that Label doesn't have a method for stringifying itself makes me think this isn't an intended path.
  2. Convert the strings to Labels. I don't think this will work since then all py_proto_library deps would be anchored to the protobuf workspace.

CodingCanuck added a commit to reboot-dev/pyprotoc-plugin that referenced this issue Apr 2, 2022
protocolbuffers/protobuf#9688 caused build
errors when trying to integrate the latest `pyprotoc-plugin` changes
into https://github.com/3rdparty/eventuals.

Fixes build errors of the form:
```
ERROR: /home/vscode/.cache/dazel/tests/external/com_envoyproxy_protoc_gen_validate/validate/BUILD:28:17: Label '@com_google_protobuf//:protobuf_python' is duplicated in the 'deps' attribute of rule 'validate_py'
ERROR: /home/vscode/.cache/dazel/tests/external/envoy_api/envoy/extensions/filters/network/http_connection_manager/v3/BUILD:7:18: Target '@com_envoyproxy_protoc_gen_validate//validate:validate_proto' contains an error and its package is in error and referenced by '@envoy_api//envoy/extensions/filters/network/http_connection_manager/v3:pkg'
INFO: Repository com_github_curl_curl instantiated at:
  /workspaces/respect/submodules/eventuals/WORKSPACE.bazel:26:5: in <toplevel>
  /workspaces/respect/submodules/eventuals/bazel/deps.bzl:24:14: in deps
  /home/vscode/.cache/dazel/tests/external/com_github_3rdparty_bazel_rules_curl/bazel/deps.bzl:30:10: in deps
  /home/vscode/.cache/dazel/tests/external/bazel_tools/tools/build_defs/repo/utils.bzl:233:18: in maybe
Repository rule http_archive defined at:
  /home/vscode/.cache/dazel/tests/external/bazel_tools/tools/build_defs/repo/http.bzl:364:31: in <toplevel>
ERROR: Analysis of target '//test:death-client' failed; build aborted:
```
aviator-app bot pushed a commit to reboot-dev/pyprotoc-plugin that referenced this issue Apr 2, 2022
protocolbuffers/protobuf#9688 caused build
errors when trying to integrate the latest `pyprotoc-plugin` changes
into https://github.com/3rdparty/eventuals.

Fixes build errors of the form:
```
ERROR: /home/vscode/.cache/dazel/tests/external/com_envoyproxy_protoc_gen_validate/validate/BUILD:28:17: Label '@com_google_protobuf//:protobuf_python' is duplicated in the 'deps' attribute of rule 'validate_py'
ERROR: /home/vscode/.cache/dazel/tests/external/envoy_api/envoy/extensions/filters/network/http_connection_manager/v3/BUILD:7:18: Target '@com_envoyproxy_protoc_gen_validate//validate:validate_proto' contains an error and its package is in error and referenced by '@envoy_api//envoy/extensions/filters/network/http_connection_manager/v3:pkg'
INFO: Repository com_github_curl_curl instantiated at:
  /workspaces/respect/submodules/eventuals/WORKSPACE.bazel:26:5: in <toplevel>
  /workspaces/respect/submodules/eventuals/bazel/deps.bzl:24:14: in deps
  /home/vscode/.cache/dazel/tests/external/com_github_3rdparty_bazel_rules_curl/bazel/deps.bzl:30:10: in deps
  /home/vscode/.cache/dazel/tests/external/bazel_tools/tools/build_defs/repo/utils.bzl:233:18: in maybe
Repository rule http_archive defined at:
  /home/vscode/.cache/dazel/tests/external/bazel_tools/tools/build_defs/repo/http.bzl:364:31: in <toplevel>
ERROR: Analysis of target '//test:death-client' failed; build aborted:
```
@Wyverald
Copy link
Contributor

Wyverald commented Apr 4, 2022

This is a very tricky problem and indeed one I did not foresee. We can't do 1 since the strings passed in are not "absolute" labels, and unfortunately str(some_label_object) isn't always "absolute" either (cue years of tech debt). We can't do 2 as you said, but we should do some variant of it: we'd need some way to convert strings to labels but using the current package's context, essentially restoring a deprecated API that was removed (Label(..., relative_to_caller_repository=True)).

minor-fixes added a commit to minor-fixes/enkit that referenced this issue May 10, 2022
This change fixes a few minor issues to unblock builds in internal:

* Patch labels must be qualified by the repository name or they get
  resolved relative to the calling workspace
* `com_google_protobuf` must be overridden and updated to 3.20.1 to get
  around protocolbuffers/protobuf#9688

Tested: Built internal using `--override_repository` pointing to enkit;
`//systest/...` builds. It's possible that other builds still fail; TBD
after this is merged.

Jira: INFRA-1038
minor-fixes added a commit to enfabrica/enkit that referenced this issue May 10, 2022
This change fixes a few minor issues to unblock builds in internal:

* Patch labels must be qualified by the repository name or they get
  resolved relative to the calling workspace
* `com_google_protobuf` must be overridden and updated to 3.20.1 to get
  around protocolbuffers/protobuf#9688

Tested: Built internal using `--override_repository` pointing to enkit;
`//systest/...` builds. It's possible that other builds still fail; TBD
after this is merged.

Jira: INFRA-1038
@alexeagle
Copy link
Contributor

restoring a deprecated API that was removed

bazelbuild/bazel@b859571 claims to be exactly that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants