Search code examples
dartprotocol-buffersprotoc

Add 'library' directive to dart code generated using protoc


Can someone tell me how to get protoc to generate dart files with a leading library directive?

I'm using the dart-protoc-plugin (v0.10.2) to generate my dart, c++, c#, js and java models from proto files. I was under the impression there was no way to get protoc to add a 'library' directive to the generated dart files, until I noticed the directive appearing in another project (see date.pb.dart).

If I take the same file (date.proto) I cannot get protoc to generate a dart file containing a 'library' directive.

In short: I want to take a .proto file with the following content

syntax = "proto3";

package another.proj.nspace;

message MyObj {
  ...
}

and produce a .dart file with a leading 'library' directive similar to the following snippet

///
//  Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library another.proj.nspace;
...

NOTE: I don't care about the actual value of the directive since I can restructure my code to get the desired result. I just need a way for protoc to add the library directive...

The basic command I'm using to generate the dart files is

protoc --proto_path=./ --dart_out="./" ./another/proj/nspace/date.proto

Unfortunately the dart-protoc-plugin's README isn't very helpful and I had to go through the source to find out which options are available; and currently it seems like the only dart-specific option is related to grpc.

I've tried options from the other languages (e.g. 'library', and 'basepath') without any success.

It would simplify my workflow quite a bit if this is possible, but I'm starting to get the impression that the library directive in date.pb.dart is added after the code was generated...


Solution

  • After asking around a little bit, it seems that the library directive was removed from the protoc plugin at some stage (see pull request), thus it is no longer supported.