Add option for including extra files from .pb.h
diff --git a/examples/network_server/fileproto.options b/examples/network_server/fileproto.options
index 952f36d..211160a 100644
--- a/examples/network_server/fileproto.options
+++ b/examples/network_server/fileproto.options
@@ -9,6 +9,8 @@
# On the other hand, using the callback interface, it is not necessary
# to set a limit on the number of files in the response.
-ListFilesResponse.file type:FT_CALLBACK, callback_datatype:"void*"
+* include:"sys/types.h"
+* include:"dirent.h"
+ListFilesResponse.file type:FT_CALLBACK, callback_datatype:"DIR*"
ListFilesRequest.path max_size:128
FileInfo.name max_size:128
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py
index 57c670e..d86c7d2 100755
--- a/generator/nanopb_generator.py
+++ b/generator/nanopb_generator.py
@@ -1441,6 +1441,10 @@
yield options.libformat
yield '\n'
+ for incfile in self.file_options.include:
+ yield options.genformat % incfile
+ yield '\n'
+
for incfile in includes:
noext = os.path.splitext(incfile)[0]
yield options.genformat % (noext + options.extension + options.header_extension)
@@ -1449,6 +1453,8 @@
if Globals.protoc_insertion_points:
yield '/* @@protoc_insertion_point(includes) */\n'
+ yield '\n'
+
yield '#if PB_PROTO_HEADER_VERSION != 40\n'
yield '#error Regenerate this file with the current version of nanopb generator.\n'
yield '#endif\n'
@@ -1741,10 +1747,10 @@
metavar="OUTPUTDIR", default=None,
help="Output directory of .pb.h and .pb.c files")
optparser.add_option("-Q", "--generated-include-format", dest="genformat",
- metavar="FORMAT", default='#include "%s"\n',
+ metavar="FORMAT", default='#include "%s"',
help="Set format string to use for including other .pb.h files. [default: %default]")
optparser.add_option("-L", "--library-include-format", dest="libformat",
- metavar="FORMAT", default='#include <%s>\n',
+ metavar="FORMAT", default='#include <%s>',
help="Set format string to use for including the nanopb pb.h header. [default: %default]")
optparser.add_option("--strip-path", dest="strip_path", action="store_true", default=False,
help="Strip directory path from #included .pb.h file name")
diff --git a/generator/proto/nanopb.proto b/generator/proto/nanopb.proto
index 5368c52..7138b88 100644
--- a/generator/proto/nanopb.proto
+++ b/generator/proto/nanopb.proto
@@ -128,6 +128,9 @@
// Set default value for has_ fields.
optional bool default_has = 23 [default = false];
+
+ // Extra files to include in generated `.pb.h`
+ repeated string include = 24;
}
// Extensions to protoc 'Descriptor' type in order to define options