I was trying to use a separate .options file in Android, but it did not take effect after compile. However, if I define the options in the .proto file itself, it did take effect.
>> my .proto file:
message ConnectionStatus {
required int32 status = 1;
required string profile = 2;
}
>> my .options file:
ConnectionStatus.profile max_size:32
I also tried specifying the .options file in Android.mk file with:
LOCAL_PROTOC_FLAGS += -f $(LOCAL_PATH)/protobuffer/CneMsg.options
But it says "UNKNOWN flag: -f":
>>
(out/host/linux-x86/bin/aprotoc --proto_path=. --proto_path=src/protobuffer/ -f src/protobuffer/CneMsg.options -Iexternal/nanopb-c/generator/proto/ --nanopb_out=proto --plugin=external/nanopb-c/generator/protoc-gen-nanopb src/protobuffer/CneMsg.proto)"
Unknown flag: -f
ninja: build stopped: subcommand failed.
make: *** [ninja_wrapper] Error 1
The protoc version is :
/host/linux-x86/bin/aprotoc --version
libprotoc 2.6.1
Is it because this version is too old that it doesn't support a separate .options file? or am I missing any steps here?
Thanks a lot.
Boxiang
Thanks so much for your reply. I have some follow up questions.
On Monday, March 14, 2016 at 10:37:45 PM UTC-7, Petteri Aimonen wrote:
> Hi,
>
> > I was trying to use a separate .options file in Android, but it did
> > not take effect after compile. However, if I define the options in the
> > .proto file itself, it did take effect.
>
> Yeah, the problem is probably caused by --proto-path. Google's protoc
> does not pass that information to plugins yet.
> https://github.com/nanopb/nanopb/issues/116
> https://github.com/google/protobuf/pull/811
>
Which one is the "execution directory" in https://github.com/nanopb/nanopb/issues/116 ? If I put my .options file in the "execution directory" as a temporary workaround, then it should be able to find the .options file, correct?
> > I also tried specifying the .options file in Android.mk file with:
> > LOCAL_PROTOC_FLAGS += -f $(LOCAL_PATH)/protobuffer/CneMsg.options
> > But it says "UNKNOWN flag: -f":
>
> Yeah, the protoc's syntax for passing arguments to plugins is a bit
> confusing. You would have to modify the Makefile somehow so that you
> get:
>
> > "--nanopb_out=-f $(LOCAL_PATH)/protobuf/CneMsg.options:proto"
>
What is the part after ":" ? Is it the output directory where .pb.c and .pb.h will be generated?
I modified my makefile, now I have:
(out/host/linux-x86/bin/aprotoc --proto_path=. --proto_path=vendor/src/protobuffer/ -Iexternal/nanopb-c/generator/proto/ --nanopb_out=-f vendor/src/protobuffer/CneMsg.options:out/proto/src/protobuffer/ --nanopb_out=out/proto --plugin=external/nanopb-c/generator/protoc-gen-nanopb vendor/src/protobuffer/CneMsg.proto)"
however, it's giving me "No such file or directory" error:
vendor/src/protobuffer/CneMsg.options:out/proto/src/protobuffer/: No such file or directory
I double checked that the .options file does exist under vendor/src/protobuffer/
Which file/directory is it complaining?
> in the protoc command.
>
> > Is it because this version is too old that it doesn't support a
> > separate .options file? or am I missing any steps here?
>
> You would have to check the version of protoc-gen-nanopb, which is the
> actual nanopb plugin. Separate options file is supported since
> nanopb-0.2.1 (2013-04-14), so I think Android would have that already.
>
My protoc-gen-nanopb version is:
nanopb_version = "nanopb-0.2.8-dev"
> --
> Petteri
Thanks a lot,
Boxiang
>
> Two problems:
> 1) You should put the "--nanopb_out=-f ..." in quotes as it contains
> spaces.
> 2) You probably want to remove the other --nanopb_out there.
>
1) resolved the issue. The entire string should be put inside " ". It can now find the .options file!
2) is fine if it has another --nanopb_out there. In fact, there can be multiple --nanopb_out flags.
I'd like to also add that in order to match the options fields with the fields in .proto file, it must be prefixed by package name if there is one. To use the one in your documentation as an example:
# myproto.proto
package MyPackage <-- if a package name is specified
message MyMessage {
required string name = 1;
repeated int32 ids = 4;
}
# myproto.options
MyPackage.MyMessage.name max_size:40 <-- must be prefixed by package name
MyPackage.MyMessage.ids max_count:5
Thanks so much for the help!
Boxiang