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

proto_library: warning: directory does not exist #7157

Closed
jayconrod opened this issue Jan 17, 2019 · 42 comments
Closed

proto_library: warning: directory does not exist #7157

jayconrod opened this issue Jan 17, 2019 · 42 comments
Assignees
Labels
more data needed P2 We'll consider working on this in future. (Assignee optional) team-Rules-Server Issues for serverside rules included with Bazel

Comments

@jayconrod
Copy link
Contributor

Description of the problem / feature request:

Building proto_library targets for Well Known Types in @com_google_protobuf emits warnings like the one below. The build succeeds, but it would be nice if the warning can be fixed or removed.

$ bazel build @com_google_protobuf//:any_proto
...
INFO: From Generating Descriptor Set proto_library @com_google_protobuf//:any_proto:
external/com_google_protobuf: warning: directory does not exist.
...

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

# WORKSPACE
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
    name = "com_google_protobuf",
    remote = "https://github.com/protocolbuffers/protobuf",
    tag = "v3.6.1.3",
)

git_repository(
    name = "bazel_skylib",
    remote = "https://github.com/bazelbuild/bazel-skylib",
    tag = "0.6.0",
)
bazel build @com_google_protobuf//:any_proto

What operating system are you running Bazel on?

Linux amd64

What's the output of bazel info release?

release 0.21.0

This does not happen in 0.20.0, but it does happen in 0.22.0rc2.

@jayconrod
Copy link
Contributor Author

@lberki I wonder if this is related to recent source root changes?

@jin jin added team-Rules-Server Issues for serverside rules included with Bazel untriaged labels Jan 17, 2019
@lberki
Copy link
Contributor

lberki commented Jan 21, 2019

/cc @haberman

Probably, I suppose? We did reshuffle the way protoc is called a bit. I'm traveling this week and next, though, so I probably won't be able to look at it closely until I get back home.

@dbabkin , can you help out?

@lberki lberki added P2 We'll consider working on this in future. (Assignee optional) and removed untriaged labels Jan 21, 2019
@thaidn
Copy link

thaidn commented Mar 3, 2019

Friendly ping. This still happens in 0.22.0.

@dbabkin
Copy link
Contributor

dbabkin commented Mar 8, 2019

Hi,
There is no ETA when that will be fixed.
Priority of this task is low, as it is warning only.

@steeve
Copy link
Contributor

steeve commented Jun 6, 2019

Small ping, still happening in 0.25.3

@dapirian
Copy link

Ping again, this is extremely annoying and spammy.

@lberki
Copy link
Contributor

lberki commented Jul 2, 2019

Update: I have a change under review that will fix this issue. Let's see how the review goes. It's not complicated, so it shouldn't be problematic.

@lberki
Copy link
Contributor

lberki commented Jul 3, 2019

...and apologies for the delay. I know it was very annoying (in fact, the reason why I fixed it was because it annoyed me! :) )

@lberki
Copy link
Contributor

lberki commented Jul 3, 2019

Well, that was optimistic:

https://buildkite.com/bazel/bazel-at-head-plus-downstream/builds/1067#24a01f98-1ed2-4423-8d94-bf11cef557e4

The change will have to be rolled back. I'll take a look the next time I have some spare time.

@lberki lberki reopened this Jul 3, 2019
@lberki lberki reopened this Jul 3, 2019
@lberki
Copy link
Contributor

lberki commented Jul 3, 2019

Ugh. This is awful. Hear me out.

This warning messages happen when all the source files of a proto_library in an external repository are generated and therefore --proto_path=<root of external repository> is superfluous. However, the list of proto source roots comes from the same place that we use to determine the prefix we should cut off the exec path to obtain the proto import path.

Of course, we have to cut off different parts depending on whether the proto file is source or generated, but that we determine by... guesswork in guessProtoPathUnderRoot:

https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java#L659

That algorithm broke when we removed the directory from the set of proto paths. The reason why only Go broke is that this line trying to cater for legacy use cases saves us, but I don't want to rely on it:

https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java#L671

, but go_proto_library sensibly doesn't have its equivalent.

So that change was indeed wrong. Now, the question is, how to make it right -- eliminating the warning requires that we remove a repository root from the set of proto paths if there are only generated files, but if we remove it, the algorithm to generate -I clauses suddenly stops working.

Furthermore, it's not trivial to decouple --proto_path from -I because they are both derived from ProtoInfo, which is exposed to Starlark, so we can't just change it willy-nilly. In particular, it only has room for one direct proto source root, which is not enough: the principled fix is to make it so that ProtoInfo.proto_source_root is an execpath and not a root-relative path and if a proto_library has both generated and source .proto files, one would require both.

A saving grace is that ProtoInfo cannot currently be created from Starlark, so we may get away with adding a Java field that's not exposed to Starlark and leaving ProtoInfo.proto_source_root as a polite lie.

However, it's far from a trivial change :(

@hlopko
Copy link
Member

hlopko commented Jul 3, 2019

Shouldn't we remove .proto_source_root by #7153?

@lberki
Copy link
Contributor

lberki commented Jul 3, 2019

This is not about the attribute, but the eponymous field of ProtoInfo.

@hlopko
Copy link
Member

hlopko commented Jul 3, 2019

Yup, what I'm asking is if the field makes sense when the attribute is gone.

@lberki
Copy link
Contributor

lberki commented Jul 3, 2019

It does. That field tells what the effective proto source root is. That's a concept that makes sense even when the attribute will be gone.

@lberki
Copy link
Contributor

lberki commented Jul 3, 2019

So, I got a bit nerd sniped and I have another solution: simply create a virtual proto import directory when the proto_library rule has a generated .proto file just like we do when strip_import_prefix or import_prefix is set.

Granted, it's not that simple because we still need to make sure that our internal repository keeps chugging along, but I'd gladly fork the behavior of proto_library in this respect (they are different already, so no big change) if that's what I have to do to make proto_library saner for everyone else.

That's still not a tiny amount of work and it is still possible that some odd downstream project breaks, but this is certainly much simpler than the previous alternative. And it doesn't even require lying to Starlark!

siberex pushed a commit to siberex/bazel that referenced this issue Jul 4, 2019
…here are no .proto sources in it.

This prevents protoc from complaining about a nonexistent directory in sandboxed mode and is good hygiene in any case.

Fixes bazelbuild#7157.

RELNOTES: None.
PiperOrigin-RevId: 256208923
siberex pushed a commit to siberex/bazel that referenced this issue Jul 4, 2019
*** Reason for rollback ***

Breaks Bazel downstream: https://buildkite.com/bazel/bazel-at-head-plus-downstream/builds/1067#24a01f98-1ed2-4423-8d94-bf11cef557e4

*** Original change description ***

Do not add a --proto_path argument to the proto compiler invocation there are no .proto sources in it.

This prevents protoc from complaining about a nonexistent directory in sandboxed mode and is good hygiene in any case.

Fixes bazelbuild#7157.

RELNOTES: None.
PiperOrigin-RevId: 256338118
@lberki
Copy link
Contributor

lberki commented Jul 8, 2019

Update: I have another fix. Learning from the previous one, I have to run in through all sorts of presubmits to make sure that it doesn't break anything. It introduces a slight incompatibility which I hope no one relies on, but there is only one way to be sure...

If that still doesn't work, I have another option (not generating virtual import directories for rules with proto_source_root= set, only for those with generated sources), which might still fail, but with a much lower probability. The downstream presubmit will tell.

@lberki
Copy link
Contributor

lberki commented Jul 8, 2019

Update: collateral damage is minimal. Unfortunately, it includes rules_rust and Bazel itself.

I'll send out changes to both then try to submit this.

@sgammon
Copy link

sgammon commented Aug 29, 2019

@lberki no worries, thank you for the update

@crutcher
Copy link

crutcher commented Jul 9, 2020

Is this ... dead?

@joshburkart
Copy link

@lberki Can we reopen this? It's still occurring in the latest version of Bazel, right?

@MegaPanchamZ
Copy link

@joshburkart

Can confirm the error still exists in Bazel 3.x.x

@phlax
Copy link

phlax commented Mar 20, 2021

it would be great if this was fixed (and i guess the bug reopened)

we would like to make warnings into errors to prevent other proto generation issues, but i think these warnings make that not possible

@michael-lefkowitz-techlabs
Copy link

michael-lefkowitz-techlabs commented Jul 23, 2021

I'm still having this problem as well.

@comius
Copy link
Contributor

comius commented Jan 24, 2022

The reproduction on this bug is ancient. I've tried reproduction with Bazel 5.0.0 and bzlmod:

MODULE.bazel

bazel_dep(name = "protobuf", version = "3.19.2", repo_name = "com_google_protobuf")

Command line:

bazel build --experimental_enable_bzlmod @com_google_protobuf//:any_proto

and I get no warnings.

Can somebody please provide a reproducer on Bazel 5.0.0? Or at least add a message to the thread with Bazel versions and protobuf versions where this occurs.

@phlax
Copy link

phlax commented Jan 24, 2022

we are seeing this with bazel==4.2.1 and protobuf==3.19.3

@comius
Copy link
Contributor

comius commented Jan 24, 2022

I tried with bazel 4.2.1, protobuf 3.19.2 and 3.19.3; no success reproducing. Something else is missing that's causing this.

WORKSPACE

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
    name = "com_google_protobuf",
    remote = "https://github.com/protocolbuffers/protobuf",
    tag = "v3.19.3",
)

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

Command line:

bazel build  @com_google_protobuf//:any_proto

@alyssawilk
Copy link

We in this case is Envoy (https://github.com/envoyproxy/envoy). I've sent more detailed information internally for repro since the OSS instructions need some additions to build in-google, but our CI logs show it's still definitely a problem for our project and we're super happy to help you folks reproduce

@phlax
Copy link

phlax commented Jan 24, 2022

hmm - grepping (envoyproxy/envoy) repo seems to suggest that we dont load protobuf_deps i wonder if that is the problem

ill, add PR and try and check...

@comius
Copy link
Contributor

comius commented Jan 24, 2022

I see the warning here https://buildkite.com/bazel/envoy/builds/1811#0c20714c-e748-4c19-a6a5-844e9b4a0e70
I'll investigate further, thanks!

@phlax
Copy link

phlax commented Jan 24, 2022

loading the protobuf deps doesnt seem to have hurt, but doesnt get rid of the messages

@comius
Copy link
Contributor

comius commented Jan 25, 2022

The problem was created by proto_gen rule defined in https://github.com/protocolbuffers/protobuf project.

Correct issue is reported here: protocolbuffers/protobuf#6049
I created a PR fixing it: protocolbuffers/protobuf#9438

I'm closing this issue, because I didn't discover any warnings produced by the rules that are part of Bazel.

@comius comius closed this as completed Jan 25, 2022
@phlax
Copy link

phlax commented Jul 22, 2023

after being resolved for some time this has issue has returned (bazel: 6.1, protobuf: 23.1)

https://dev.azure.com/cncf/envoy/_build/results?buildId=143687&view=logs&j=8c169225-0ae8-53bd-947f-07cb81846cb5&t=4d0399a5-fd0d-5446-d022-32daa00183cc&l=296

tbh it seems more related to the protobuf version but the previous ticket in protobuf suggested it was a bazel issue

cc @alyssawilk @htuch

@phst
Copy link
Contributor

phst commented Jan 15, 2024

Yeah, this is happening for me as well with Bazel 7 and Protobuf 23.1. Maybe this issue could be reopened? Or should we file a new issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more data needed P2 We'll consider working on this in future. (Assignee optional) team-Rules-Server Issues for serverside rules included with Bazel
Projects
None yet
Development

No branches or pull requests