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

Variable import order caused by "option go_package" in conjunction with "import" #62

Open
ashleyvega opened this issue Mar 29, 2019 · 1 comment

Comments

@ashleyvega
Copy link

ashleyvega commented Mar 29, 2019

When one or both of the option go_package lines in the below 2 files are enabled, the import order changes randomly between:

	_ "." // or "github.com/someuser/api_a"
	_ "github.com/mwitkow/go-proto-validators"

and vice versa.

File: a.proto

syntax = "proto3";
package a;
// option go_package = "github.com/someuser/api_a";
message Thing { string id = 1; }

File: b.proto

syntax = "proto3";
import "a.proto";
package b;
// option go_package = "github.com/someuser/api_b";
import "github.com/mwitkow/go-proto-validators/validator.proto";
message SomethingContainingThing { a.Thing thing = 1 [(validator.field) = {msg_exists : true}]; }

Makefile

default: b.validator.pb.go b.pb.go

%.validator.pb.go: %.proto a.proto
	@protoc -I. -Ivendor -Ivendor/github.com/protocolbuffers/protobuf/src --govalidators_out=paths=source_relative:. "$<"

%.pb.go: %.proto a.proto
	@protoc -I. -Ivendor -Ivendor/github.com/protocolbuffers/protobuf/src --go_out=paths=source_relative:. "$<"

.PHONY: clean
clean:
	@rm -f *.pb.go

Script to highlight flake

F="b.validator.pb.go"
while true ; do
    rm -f "$F"
    make "$F"
    md5="$(md5sum "$F" | awk '{print $1}')"
    echo -e "$(date)\t$md5"
    mv "$F "$md5-$F"
done

(If F is changed to b.pb.go, no flakiness is observed in the output.)

In the vendor dir we have:

tree -d vendor
vendor/
└── github.com
    ├── google
    │   └── protobuf
    │       └── src
    │           └── google
    │               └── protobuf
    │                   ├── compiler
    │                   │   ├── cpp
    │                   │   └── ruby
    │                   └── util
    │                       └── internal
    │                           └── testdata
    └── mwitkow
        └── go-proto-validators
            ├── examples
            └── test

Versions:

  • mwitkow/go-proto-validators is at 1f38828 (28/Mar/2019)
  • protocolbuffers/protobuf is at f425b9f (12/Feb/2019, or v3.7.0+incompatible according to go.mod)
@zifter
Copy link

zifter commented Jul 23, 2020

Fix here gogo/protobuf#700

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

No branches or pull requests

2 participants