Skip to content

.pb.go import error: local import "." in non-local package #67

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

Closed
ayrb13 opened this issue Aug 27, 2015 · 7 comments
Closed

.pb.go import error: local import "." in non-local package #67

ayrb13 opened this issue Aug 27, 2015 · 7 comments

Comments

@ayrb13
Copy link

ayrb13 commented Aug 27, 2015

I wrote some proto files that one import others.
like this:
package myproto;
import "a.proto";
import "b.proto";
import "c.proto";
import "d.proto";
import "e.proto";
these files are all in package myproto;

When I generated pb.go files and import "myproto"
go compiler told:
import cycle not allowed
package .
imports myproto
imports .
imports .
echo.go:5:2: local import "." in non-local package

Is it a bug of protoc-gen-go?

@dsymonds
Copy link
Contributor

If foo.proto imports bar.proto, they need to generate code in different Go packages, or else be run through protoc together. What commands did you run to get the generated .pb.go files?

@ayrb13
Copy link
Author

ayrb13 commented Aug 27, 2015

protoc --go_out=. a.proto
protoc --go_out=. b.proto
protoc --go_out=. c.proto
protoc --go_out=. d.proto
protoc --go_out=. e.proto

I did similar script when i generated cpp files?
How to "be run through protoc together"

thanks for your reply

@dsymonds
Copy link
Contributor

You haven't told protoc-gen-go how to map a.proto to a Go import path, which is why it ended up with a dot. Try protoc --go_out=. a.proto b.proto c.proto d.proto e.proto, or put them in different directories, or use the M parameter (carried in the --go_out flag) to specify what it should do.

@ayrb13
Copy link
Author

ayrb13 commented Aug 27, 2015

I did what you told me to do and It works now, thank you very much

abhishekrai added a commit to abhishekrai/protobuf that referenced this issue Nov 7, 2015
Normally, protoc-gen-go recommends certain conventions to avoid
cyclic imports between generated go files.  Some of these are
documented in:
golang#67

This change adds one more mechanism to avoid cycles: if protoc-gen-go
was invoked with import_path parameter set, then it will not generate
import statements for any packages with identical import_path.

This ends up being a simple way of avoiding cycles when all other
options are hard to implement.  For example, the codebase that I'm
working with has 100s of proto files shared between code written in
4 different languages including go.  It's difficult for us to pass
all proto files in a directory to protoc.  Other alternatives
documented in the above issue are even more complex for us to adopt.

In contrast, import_path is easy to set.
@icexin
Copy link

icexin commented Nov 26, 2015

@dsymonds How to use the M parameter? I have two proto files: a.proto with package a and b.proto with package b, a.proto imports b. proto. When compiled with protoc --go_out=. a.proto b.proto, protoc failed with inconsistent package names: a b. Thanks!

@dsymonds
Copy link
Contributor

If you've got two proto files that are going into the same package (implied by passing them on the command line together), they need to have the same package name.

@alecthomas
Copy link

Also see #39.

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

No branches or pull requests

4 participants