ygot icon indicating copy to clipboard operation
ygot copied to clipboard

imports should be started with src?

Open adibrastegarnia opened this issue 6 years ago • 5 comments

Hello,

It looks like when we generate protobuf models, ygot adds two imports as follows to the protobuf messages:

import "github.com/openconfig/ygot/proto/ywrapper/ywrapper.proto";
import "github.com/openconfig/ygot/proto/yext/yext.proto";

According to the Golang documents, the expected structure of a go program is $GOPATH/src/. That means when we use go get to retrieve dependencies, it creates src directory and then it adds github repos under src directory. I think the above imports should be started with src. What do you think? Am I missing something?

Thanks

adibrastegarnia avatar Mar 31 '19 23:03 adibrastegarnia

Proto and Go import paths don't have a relationship to one another. You can use the -I flag to protoc such that the import path is specified according to whatever root you expect. For consistency, we chose to make the default assumption for Go users that the path was in $GOPATH/src (where all Go imports are specified relative to).

If you want these import paths to be written out differently, then you can use the -yext_path and -ywrapper_path flags to proto_generator which let you explicitly specify this.

robshakir avatar Apr 01 '19 14:04 robshakir

Thanks for your response. I didn't know there are flags that we can use to specify yext and ywrapper paths. I will try.

adibrastegarnia avatar Apr 01 '19 14:04 adibrastegarnia

@robshakir I tried but it doesn't work. I have a script here if you would like to take a look:

https://github.com/adibrastegarnia/ygot-scripts/blob/master/src/command.sh

I would like the imports to be started with src otherwise protobuf doesn't find the file. I tried something like this: -ywrapper_path="../src/github.com/openconfig/ygot/proto/ywrapper"

The error is : No such file or directory

adibrastegarnia avatar Apr 01 '19 21:04 adibrastegarnia

What command is producing the error? What is the protoc command that you are using?

robshakir avatar Apr 01 '19 22:04 robshakir

I am using bazel to generate proto libraries. Actually, I solved the problem using a different method. I moved WORKSPACE and BUILD file to src directory and I don't need to change imports anymore but I think it is not a bad idea to take a look if you have time in case someone wants to have WORKSPACE and BUILD file outside of src directory.

On Mon, Apr 1, 2019 at 6:52 PM Rob Shakir [email protected] wrote:

What command is producing the error? What is the protoc command that you are using?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/openconfig/ygot/issues/279#issuecomment-478775544, or mute the thread https://github.com/notifications/unsubscribe-auth/AJ4q3A6z1j3WbrFXariQxHfcjpmxAGGmks5vco2jgaJpZM4cUnVN .

adibrastegarnia avatar Apr 01 '19 23:04 adibrastegarnia