Filed https://github.com/grpc/grpc/issues/11672

On Fri, Jun 30, 2017 at 9:20 AM, Nicolas Noble <[email protected]>
wrote:

> This may sound like a bug indeed. Could you file one on github ?
>
> On Fri, Jun 30, 2017 at 12:10 AM, Yukang Yang <[email protected]> wrote:
>
>> I finally know why my own example doesn't work. This is a BUG in
>> grpc/bazel/generate_cc.bzl
>> <https://github.com/grpc/grpc/blob/master/bazel/generate_cc.bzl>.
>>
>> line 13: label_len = len(ctx.label.package) + 1
>>
>> should actually be
>>
>> label_len = len(ctx.label.package)
>> if label_len != 0:
>>   label_len = label_len + 1
>>
>> grpc's example works even with the bug because BUILD file is in a
>> subdirectory and its package is "example". When package is not empty
>> string, it makes sense to add 1 because proto path is examples/protos/
>> helloworld.proto. Plus 1 can remove the / after "examples".
>>
>> However, this is not the case when package is an empty string. In my own
>> example, BUILD file is in topmost directory and package is an empty string.
>> there is no leading / before output path. for example, my proto path is
>> proto/helloworld.proto. there is no need to plus 1 in this case.
>>
>> I am using grpc_proto_library because of https://github.com/grpc/grpc/i
>> ssues/11176. I am guessing it is the recommended way to use bazel with
>> c++ grpc and it probably should not be limited to grpc's own use case.
>>
>>
>> On Wed, Jun 28, 2017 at 5:24 PM, Yukang Yang <[email protected]> wrote:
>>
>>> Thanks, Nicolas! I tried too many to make it work and as a result, my
>>> repository was full of junk. I just deleted entire repository and cloned it
>>> again. I can successfully build GRPC's example with bazel now.
>>>
>>> But my own example (https://bitbucket.org/xyyk/grpc-example/overview)
>>> still fails with the same error. Still looking into it.
>>>
>>>
>>>
>>> On Wed, Jun 28, 2017 at 3:03 PM, Nicolas Noble <[email protected]>
>>> wrote:
>>>
>>>> That last error is a known problem with protobuf; you've run make, and
>>>> that leaves files around that confuses Bazel. Please clean the protobuf
>>>> subdirectory using git clean -f -d -x for example.
>>>>
>>>> On Wed, Jun 28, 2017 at 9:37 AM, Yukang Yang <[email protected]> wrote:
>>>>
>>>>> Hi Nicolas,
>>>>>
>>>>> Thanks for reply!
>>>>>
>>>>> 1. Problem in GRPC's example (https://github.com/grpc/grpc/
>>>>> blob/master/examples/BUILD):
>>>>>
>>>>> I just git pull. Now I am at the same commit as you. But It still
>>>>> doesn't build, although this time it is a different error message. I am 
>>>>> not
>>>>> sure if I am the only person who can get this error. Here is what I did:
>>>>>
>>>>> $ cd GRPC_REPOSITORY
>>>>> $ git show --oneline
>>>>> c4f85b78f3 (HEAD -> master, origin/master, origin/HEAD) Merge pull
>>>>> request #11474 from makdharma/cares_fix
>>>>> // same commit as yours
>>>>>
>>>>> $ ~/bazel version
>>>>> Build label: 0.5.2- (@non-git)
>>>>> // brew hasn't updated bazel and 0.5.1 has a bug. I built bazel from
>>>>> 0.5.2 distribution package
>>>>>
>>>>> $ ~/bazel build examples/...
>>>>> external/com_google_protobuf/BUILD.bazel:367:1: in cc_binary rule
>>>>> @com_google_protobuf//:protoc: cycle in dependency graph:
>>>>>     //examples:_auth_sample_codegen
>>>>>     //external:protocol_compiler (host)
>>>>> .-> @com_google_protobuf//:protoc (host)
>>>>> |   @com_google_protobuf//:protoc_lib (host)
>>>>> |   @com_google_protobuf//:protobuf (host)
>>>>> |   
>>>>> @com_google_protobuf//:src/google/protobuf/util/internal/testdata/timestamp_duration.pb.h
>>>>> (host)
>>>>> |   @com_google_protobuf//:cc_test_protos_genproto (host)
>>>>> `-- @com_google_protobuf//:protoc (host)
>>>>> This cycle occurred because of a configuration option.
>>>>> ERROR: Analysis of target '//examples:_auth_sample_codegen' failed;
>>>>> build aborted.
>>>>> // I checked protobuf BUILD file and I don't know how is
>>>>> @com_google_protobuf//:protobuf depends on a target of
>>>>> timestamp_duration.pb.h.
>>>>>
>>>>> 2. Problem in my own example (https://bitbucket.org/xyyk/gr
>>>>> pc-example/overview):
>>>>>
>>>>> I realized that more stuff is needed in WORKSPACE of my own example.
>>>>> Now I have went through all errors of "BUILD file not found", added 
>>>>> missing
>>>>> external dependency and bind in my WORKSPACE, and fixed all of them. I no
>>>>> longer get any error about package or BUILD. But this time it seems bazel
>>>>> cannot output cc files successfully.
>>>>>
>>>>> $ cd MY_OWN_EXAMPLE
>>>>> $ ~/bazel build :helloworld
>>>>>
>>>>> ERROR: /Users/yukang/git-projects/grpc-example/BUILD:31:1: output
>>>>> 'rotos/helloworld.pb.h' was not created.
>>>>> ERROR: /Users/yukang/git-projects/grpc-example/BUILD:31:1: output
>>>>> 'rotos/helloworld.pb.cc' was not created.
>>>>> ERROR: /Users/yukang/git-projects/grpc-example/BUILD:31:1: not all
>>>>> outputs were created or valid.
>>>>> ERROR: /Users/yukang/git-projects/grpc-example/BUILD:31:1: output
>>>>> 'rotos/helloworld.grpc.pb.h' was not created.
>>>>> ERROR: /Users/yukang/git-projects/grpc-example/BUILD:31:1: output
>>>>> 'rotos/helloworld.grpc.pb.cc' was not created.
>>>>> Target //:helloworld failed to build
>>>>>
>>>>> It shows output as 'rotos/.....', while the output should actually be
>>>>> 'protos/.....' (the first letter 'p' is missing). This looks like a bazel
>>>>> issue. I also tried to build with -s
>>>>>
>>>>> $ ~/bazel clean
>>>>> $ ~/bazel build :helloworld -s
>>>>>
>>>>> Last output before the error is often this one:
>>>>> >>>>> # //:_helloworld_codegen [action 'Generating
>>>>> rotos/helloworld.pb.h']
>>>>> (cd 
>>>>> /private/var/tmp/_bazel_yukang/daf269fd3c8ea3827a82b98ac2b45027/execroot/__main__
>>>>> && \
>>>>>   exec env - \
>>>>>   bazel-out/host/bin/external/com_google_protobuf/protoc
>>>>> '--cpp_out=:bazel-out/darwin_x86_64-fastbuild/genfiles'
>>>>> '-Iprotos/helloworld.proto=protos/helloworld.proto'
>>>>> protos/helloworld.proto)
>>>>>
>>>>> If I run the command as is, i.e. first cd into __main__, and then use
>>>>> exec env - bazel-out....., my terminal crashes immediately. I don't know
>>>>> where I can find any error log about the crash.
>>>>>
>>>>> The interesting thing is if I modify this command by a little. I still
>>>>> cd into __main__,  remove 'exec env - ' and run only 
>>>>> 'bazel-out/..../protoc
>>>>> ....'. It works. and I can see the output cc files in my bazel-out. This
>>>>> looks like a bazel issue.
>>>>>
>>>>>
>>>>> On Tuesday, June 27, 2017 at 5:13:36 PM UTC-7, Nicolas Noble wrote:
>>>>>>
>>>>>> So, first, you can't just grab a portion of the tree and expect it to
>>>>>> work elsewhere. What's important is that it's able to find the WORKSPACE
>>>>>> file properly. So your second test with the copy wouldn't work without a
>>>>>> proper WORKSPACE file. Plus some of the examples are referring to files
>>>>>> down the tree, such as, well, the grpc library itself.
>>>>>>
>>>>>> Then, the error itself you're seeing seems is an old one that was
>>>>>> fixed a while ago, so I'm not sure you're really at head here.
>>>>>>
>>>>>> :~/sources/grpc (master)$ git show --oneline
>>>>>> c4f85b7 Merge pull request #11474 from makdharma/cares_fix
>>>>>>
>>>>>> :~/sources/grpc (master)$ bazel build examples/...
>>>>>> INFO: Found 18 targets...
>>>>>> INFO: Elapsed time: 102.154s, Critical Path: 9.91s
>>>>>> :~/sources/grpc (master)$ ./bazel-bin/examples/greeter_server &
>>>>>> [1] 11025
>>>>>> I0628 02:05:58.983490133   11025 server_builder.cc:254]
>>>>>>  Synchronous server. Num CQs: 4, Min pollers: 1, Max Pollers: 2, CQ 
>>>>>> timeout
>>>>>> (msec): 10000
>>>>>> Server listening on 0.0.0.0:50051
>>>>>> :~/sources/grpc (master)$ ./bazel-bin/examples/greeter_client
>>>>>> Greeter received: Hello world
>>>>>>
>>>>>>
>>>>>> On Mon, Jun 26, 2017 at 10:15 AM, Yukang Yang <[email protected]>
>>>>>> wrote:
>>>>>>
>>>>>>> Hi GRPC experts,
>>>>>>>
>>>>>>> I found the proto in GRPC example doesn't build with bazel. I used
>>>>>>> GRPC from head. bazel is got from brew install bazel.
>>>>>>>
>>>>>>> Here is what I did:
>>>>>>>
>>>>>>> git clone https://github.com/grpc/grpc.git
>>>>>>> cd grpc
>>>>>>> git pull && git submodule init && git submodule update && git
>>>>>>> submodule status
>>>>>>> cd examples
>>>>>>> bazel build :helloworld
>>>>>>>
>>>>>>> I got:
>>>>>>>
>>>>>>> ERROR: /Users/yukang/git-projects/grpc/WORKSPACE:16:1: no such
>>>>>>> package '@com_google_protobuf//': In new_local_repository rule
>>>>>>> //external:com_go
>>>>>>> ogle_protobuf the 'build_file' attribute does not specify an
>>>>>>> existing file 
>>>>>>> (/Users/yukang/git-projects/grpc/third_party/protobuf/BUILD
>>>>>>> does not
>>>>>>>  exist) and referenced by '//external:protobuf'.
>>>>>>> ERROR: Analysis of target '//examples:helloworld' failed; build
>>>>>>> aborted.
>>>>>>>
>>>>>>> I have verified that 
>>>>>>> /Users/yukang/git-projects/grpc/third_party/protobuf/BUILD
>>>>>>> exists.
>>>>>>>
>>>>>>> I also copied example out of GRPC repository and tried to set up an
>>>>>>> external dependency on grpc repository.
>>>>>>>
>>>>>>> Here is what I did:
>>>>>>>
>>>>>>> https://bitbucket.org/xyyk/grpc-example/overview
>>>>>>>
>>>>>>> git clone [email protected]:xyyk/grpc-example.git
>>>>>>> cd grpc-example
>>>>>>> bazel build :helloworld
>>>>>>>
>>>>>>> I got:
>>>>>>>
>>>>>>> ERROR: error loading package '': Extension file not found. Unable to
>>>>>>> load package for '@grpc//bazel:grpc_build_system.bzl': BUILD file
>>>>>>> not found on package path.
>>>>>>>
>>>>>>> I also saw the post at http://www.grpc.io/blog/bazel_rules_protobuf.
>>>>>>> But their example at https://github.com/pubref/grpc_greetertimer
>>>>>>> doesn't build either.
>>>>>>>
>>>>>>> Does someone know what is wrong here?
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Yukang
>>>>>>>
>>>>>>> --
>>>>>>> You received this message because you are subscribed to the Google
>>>>>>> Groups "grpc.io" group.
>>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>>> send an email to [email protected].
>>>>>>> To post to this group, send email to [email protected].
>>>>>>> Visit this group at https://groups.google.com/group/grpc-io.
>>>>>>> To view this discussion on the web visit
>>>>>>> https://groups.google.com/d/msgid/grpc-io/b7f43ecb-0ebf-47d4
>>>>>>> -a0aa-20157f210881%40googlegroups.com
>>>>>>> <https://groups.google.com/d/msgid/grpc-io/b7f43ecb-0ebf-47d4-a0aa-20157f210881%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>>> .
>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>
>>>>>>
>>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "grpc.io" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>> To post to this group, send email to [email protected].
>>>>> Visit this group at https://groups.google.com/group/grpc-io.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/grpc-io/c2399379-61f5-4ed4
>>>>> -a65f-446248a3c8b6%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/grpc-io/c2399379-61f5-4ed4-a65f-446248a3c8b6%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>> --
>>>> You received this message because you are subscribed to a topic in the
>>>> Google Groups "grpc.io" group.
>>>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>>>> pic/grpc-io/mbGvH013Bhc/unsubscribe.
>>>> To unsubscribe from this group and all its topics, send an email to
>>>> [email protected].
>>>> To post to this group, send email to [email protected].
>>>> Visit this group at https://groups.google.com/group/grpc-io.
>>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>>> gid/grpc-io/CAEvr0PFHLXkeW0duAW%3DsVvAeV%3DqY7YM5Xtj6SbyX_JW
>>>> yf2NkUw%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/grpc-io/CAEvr0PFHLXkeW0duAW%3DsVvAeV%3DqY7YM5Xtj6SbyX_JWyf2NkUw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "grpc.io" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/grpc-io/mbGvH013Bhc/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/grpc-io.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/grpc-io/CAEvr0PGuzAzUBL%2BiPMo%2BgtZ-K0k%2BYzMLi2tMr9%
> 2BCCb-%2BYR50ow%40mail.gmail.com
> <https://groups.google.com/d/msgid/grpc-io/CAEvr0PGuzAzUBL%2BiPMo%2BgtZ-K0k%2BYzMLi2tMr9%2BCCb-%2BYR50ow%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/CAC9uF3SZ80LNSDouj_5VSVDJi%3DD1N-wi7adWxjrh3j2KzqiJuA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to