0

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...

jdb
  • 51
  • 4
  • There aren't many reasons left for adding the library directive. Why do you want to add it? – Günter Zöchbauer Sep 23 '18 at 14:37
  • My project structure has an API for web, mobile and desktop, all relying on a core/shared library. In all four libraries I have classes with the same names, but different namespaces (e.g. .../web/app.dart, .../mobile/app.dart etc.). the library directive is simply used to differentiate between them. – jdb Sep 24 '18 at 10:20
  • NOTE: I'm not interested in adding the library directive to ALL generated models, just one or two of my so-called 'group' models where I have to hacka away at a result using ugly imports in the proto files and post-processing of the .dart files. As I said: I have a working workflow, but if I can add the library directive, that workflow will be simplified a lot... – jdb Sep 24 '18 at 10:24

1 Answers1

0

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.

jdb
  • 51
  • 4