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

cc_proto_library does not filter blacklisted protos inside the protobuf repo #10590

Closed
Yannic opened this issue Jan 15, 2020 · 8 comments
Closed
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-CPP Issues for C++ rules type: bug

Comments

@Yannic
Copy link
Contributor

Yannic commented Jan 15, 2020

For Bazel //:src/google/protobuf/any.proto and @com_google_protobuf//:src/google/protobuf/any.proto are different files, which causes blacklisting of .proto sources to fail inside the protobuf repo.

protocolbuffers/protobuf#7075 (comment)

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

git clone --branch proto_blacklist_test https://github.com/Yannic/protobuf.git
cd protobuf
bazel test @com_google_protobuf//:cc_proto_blacklist_test //:cc_proto_blacklist_test
# @com_google_protobuf//:cc_proto_blacklist_test passes
# //:cc_proto_blacklist_test fails
bazel test --proto_toolchain_for_cc=//:cc_toolchain @com_google_protobuf//:cc_proto_blacklist_test //:cc_proto_blacklist_test
# //:cc_proto_blacklist_test passes
# @com_google_protobuf//:cc_proto_blacklist_test fails

What operating system are you running Bazel on?

N/A

What's the output of bazel info release?

Tested with several versions between 0.22.0 and 2.0.0

Any other information, logs, or outputs that you want to share?

This is mostly an issue for the protobuf repo or for users defining their own proto_lang_toolchain, which shouldn't be too many.

I see two possible fixes:

  • a: Teach Bazel that //:src/google/protobuf/any.proto and @com_google_protobuf//:src/google/protobuf/any.proto are equivalent.
  • b: Filter .proto files based on their import path.

b Is blocked on making ProtoInfo mandatory for proto_lang_toolchain#blacklisted_protos (cc @cushon). I have no idea how hard a would be. Is it related to --incompatible_remap_main_repo (cc @aehlig)?

@jin jin added team-Rules-CPP Issues for C++ rules untriaged labels Jan 23, 2020
@oquenchil oquenchil added P2 We'll consider working on this in future. (Assignee optional) type: bug and removed untriaged labels Feb 18, 2020
dlj-NaN added a commit to dlj-NaN/protobuf that referenced this issue Oct 1, 2020
The Python C++ extension targets are not used unless
`--@:use_fast_cpp_protos=true`, and may not even be able to build
if the Python headers are missing (note that
`//util/python:python_headers`, bound to `@python_headers//` in
`//:WORKSPACE`, is not currently sufficient). This change adds the
`"manual"` tag to these targets, so that they do not cause
`bazel test ...` to fail when Python headers are missing. Without
the manual tag, the targets are always selected, even if
`--@:use_fast_cpp_protos=false`.

The `:cc_proto_blacklist_test` target is metastable, depending on
whether the `--proto_toolchain_for_cc=` flag names a target with
or without the `@com_google_protobuf//` prefix. We use the correct
prefix for Bazel's default in `kokoro/linux/bazel/build.sh`, but
the `bazel test :cc_proto_blacklist_test` (with or without `//`)
fails consistently. Hopefully, this will be fixed when
bazelbuild/bazel#10590 is addressed.
dlj-NaN added a commit to protocolbuffers/protobuf that referenced this issue Oct 1, 2020
The Python C++ extension targets are not used unless
`--@:use_fast_cpp_protos=true`, and may not even be able to build
if the Python headers are missing (note that
`//util/python:python_headers`, bound to `@python_headers//` in
`//:WORKSPACE`, is not currently sufficient). This change adds the
`"manual"` tag to these targets, so that they do not cause
`bazel test ...` to fail when Python headers are missing. Without
the manual tag, the targets are always selected, even if
`--@:use_fast_cpp_protos=false`.

The `:cc_proto_blacklist_test` target is metastable, depending on
whether the `--proto_toolchain_for_cc=` flag names a target with
or without the `@com_google_protobuf//` prefix. We use the correct
prefix for Bazel's default in `kokoro/linux/bazel/build.sh`, but
the `bazel test :cc_proto_blacklist_test` (with or without `//`)
fails consistently. Hopefully, this will be fixed when
bazelbuild/bazel#10590 is addressed.
@oquenchil
Copy link
Contributor

It looks like those PRs should have fixed this. Closing.

@Yannic
Copy link
Contributor Author

Yannic commented Nov 19, 2020

No they have not, it still doesn't work.

@oquenchil oquenchil reopened this Nov 19, 2020
@oquenchil oquenchil added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed P2 We'll consider working on this in future. (Assignee optional) labels Nov 19, 2020
@Wyverald
Copy link
Member

Wyverald commented Dec 8, 2021

I don't completely understand what the original bug is about. So I cloned the protocolbuffers/protobuf repo, and tried to run the tests in the top comment with last_green bazel:

bazel test @com_google_protobuf//:cc_proto_blacklist_test //:cc_proto_blacklist_test
# //:cc_proto_blacklist_test fails
bazel test --proto_toolchain_for_cc=//:cc_toolchain @com_google_protobuf//:cc_proto_blacklist_test //:cc_proto_blacklist_test
# //:cc_proto_blacklist_test passes

It seems like Bazel now considers @com_google_protobuf//:cc_proto_blacklist_test and //:cc_proto_blacklist_test to be the same target (which seems correct to me). However, the test is failing without manually setting --proto_toolchain_for_cc=//:cc_toolchain. Any more insight here?

@Yannic
Copy link
Contributor Author

Yannic commented Dec 8, 2021

The .proto file skip list works by checking whether the Artifact of any srcs files is equal to the artifact of any skip-listed file. In other words, it checks whether they have the same PathFragment [1].

In the case of the protobuf repo, the excluded .protos are (e.g.) external/com_google_protobuf/src/google/protobuf/any.proto, which is not the same as what we compare them to (src/google/protobuf/any.proto).

The real fix for this issue is to skip-list based on proto import path and not on artifact path, which would also allow us to get rid of the horrible difference between "proto source" and "original proto source". Everything in Bazel is ready for this, can't tell if Blaze is ready for that switch.

[1] https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/rules/proto/ProtoSourceFileExcludeList.java;l=121;drc=89e2f875842eaf8abc5e831e0741d41a8cd83823

@Wyverald
Copy link
Member

Wyverald commented Dec 8, 2021

Thanks for the context, Yannic!

In the case of the protobuf repo, the excluded .protos are (e.g.) external/com_google_protobuf/src/google/protobuf/any.proto,

I was a bit confused how this happens, so I went and did a bit of digging. Apparently, we implicitly insert a local_repository(name="$WORKSPACE_NAME", path=".") clause into the WORKSPACE file (code). This effectively means that there are two distinct packages @com_google_protobuf//:__pkg__ and @//:__pkg_, and both are loaded through the same BUILD file.

I believe this is terribly wrong and the actual source of this bug (probably what you referred to as "a" in the original comment). What makes this weirder is that the package @com_google_protobuf//:__pkg__ is not normally accessible. If you wrote in a BUILD file some_rule(name="X",dep="@com_google_protobuf//:some_target"), that "dep" will go through repo mapping and get resolved to @//:some_target. It's only through corner cases where repo mapping is skipped, such as the built-in default flag value for --proto_toolchain_for_cc, that the @com_google_protobuf//:__pkg__ package can be named at all. (Before 630be02, target patterns on the command line also skipped repo mapping, which is why the old trick worked.)

This can probably be fixed with the "delayed label" thing that @meteorcloudy and I chatted about, which basically tries to make labels in flag defaults also go through repo mapping. Alas, that's unlikely to land in the near future.

In the meantime, @Yannic, your idea to "compare proto import path instead of artifact path" could also mitigate this specific case, though I have no idea how ready Blaze is.

meteorcloudy added a commit to bazelbuild/continuous-integration that referenced this issue Dec 14, 2021
Add `--proto_toolchain_for_cc=//:cc_toolchain` to work around bazelbuild/bazel#10590 (comment)
meteorcloudy added a commit to bazelbuild/continuous-integration that referenced this issue Dec 14, 2021
Add `--proto_toolchain_for_cc=//:cc_toolchain` to work around bazelbuild/bazel#10590 (comment)
@github-actions
Copy link

github-actions bot commented Jun 2, 2023

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Jun 2, 2023
@github-actions
Copy link

This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please reach out to the triage team (@bazelbuild/triage). Thanks!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 17, 2023
fmeum pushed a commit to fmeum/continuous-integration that referenced this issue Dec 10, 2023
Add `--proto_toolchain_for_cc=//:cc_toolchain` to work around bazelbuild/bazel#10590 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-CPP Issues for C++ rules type: bug
Projects
None yet
Development

No branches or pull requests

5 participants