uber / prototool

Your Swiss Army Knife for Protocol Buffers
MIT License
5.05k stars 345 forks source link

prototool giving passing but protoc failing to generate stubs #539

Closed tasdikrahman closed 4 years ago

tasdikrahman commented 4 years ago

Greetings,

We are having a directory structure for the proto files for our service, something like this

$ tree -L 2 ./proto
./proto
├── feature
│   └── feature.proto
├── service.proto
└── v2
    └── service.proto

The contents being

v2/service.proto

syntax = "proto3";
package myapplication.rpc.v2;
option go_package = "v2";

import "proto/feature/feature.proto";

message Foo {
  string name = 1;
  ...
  repeated myapplication.rpc.feature.Feature features = 8;
}

service.proto

syntax = "proto3";
package myapplication.rpc;
option go_package = "myapplication";

import "proto/feature/feature.proto";

message Foo {
  ...
  repeated myapplication.rpc.feature.Feature features = 16;
}

feature/feature.proto

syntax = "proto3";
package myapplication.rpc.feature;
option go_package = "myapplication/feature";

enum Feature {
    FEATURE_INVALID = 0;

    FEATURE_MYENUMFIELD = 1;
}

Now when I do prototool lint --debug on the root directory (./myapplication dir), I will not get any error, but when I try generating the stubs out of the proto files

I get an error saying

proto/feature/feature.proto: File not found.
v2/service.proto: Import "proto/feature/feature.proto" was not found or had errors.
v2/service.proto:20:12: "myapplication.rpc.feature.Feature" is not defined

the commands I am using to generate the stubs

.PHONY: gen-proto
gen-proto: GO111MODULE = off
# gen-proto: lint-proto
gen-proto:
    cd $(SRC_DIR)/proto && retool do protoc --proto_path=. --go_out=$(SRC_DIR)/pkg/rpc/ --twirp_out=$(SRC_DIR)/pkg/rpc/ --ruby_out=$(SRC_DIR)/client-rb/lib/myapplication/rpc/ --twirp_ruby_out=$(SRC_DIR)/client-rb/lib/myapplication/rpc/ feature/feature.proto
    cd $(SRC_DIR)/proto && retool do protoc --proto_path=. --go_out=$(SRC_DIR)/pkg/rpc/ --twirp_out=$(SRC_DIR)/pkg/rpc/ --ruby_out=$(SRC_DIR)/client-rb/lib/myapplication/rpc/ --twirp_ruby_out=$(SRC_DIR)/client-rb/lib/myapplication/rpc/ service.proto
    cd $(SRC_DIR)/proto && retool do protoc --proto_path=. --go_out=$(SRC_DIR)/pkg/rpc/ --twirp_out=$(SRC_DIR)/pkg/rpc/ --ruby_out=$(SRC_DIR)/client-rb/lib/myapplication/rpc/ --twirp_ruby_out=$(SRC_DIR)/client-rb/lib/myapplication/rpc/ v2/service.proto

One thing to notice here is that, when I change the import to not prefix proto in import, like below

v2/service.proto

syntax = "proto3";
package myapplication.rpc.v2;
option go_package = "v2";

import "feature/feature.proto";

service.proto

syntax = "proto3";
package myapplication.rpc;
option go_package = "myapplication";

import "feature/feature.proto";

message Foo {
  ...
  repeated myapplication.rpc.feature.Feature features = 16;
}

the changes of removing proto prefix and make gen-proto doesn't fail, and the stubs get generated successfully, but $ prototool lint is failing.

Would be great if someone could point where we are going wrong.

smaye81 commented 4 years ago

Try this:

protoc --proto_path=$(SRC_DIR)/proto --go_out=$(SRC_DIR)/pkg/rpc/ --twirp_out=$(SRC_DIR)/pkg/rpc/ --ruby_out=$(SRC_DIR)/client-rb/lib/myapplication/rpc/ --twirp_ruby_out=$(SRC_DIR)/client-rb/lib/myapplication/rpc/ $(SRC_DIR)/proto/feature/feature.proto

Set your proto_path to be the path where your protos are so protoc knows where to find your files rather than cd'ing into the directory.