1
1
const package_regex = r" package\s (\S *)[\s ]*;.*"
2
2
const service_regex = r" service\s (\S *)[\s ]*{.*"
3
3
4
- function write_header (io, package, client_module_name)
4
+ function write_header (io, generated_module, package, client_module_name)
5
5
print (io, """ module $(client_module_name)
6
6
using gRPCClient
7
7
8
- include("$(package ) .jl")
8
+ include("$(generated_module ) .jl")
9
9
using .$(package)
10
10
11
11
import Base: show
@@ -127,7 +127,7 @@ Generate a gRPC client from protobuf specification file.
127
127
- `outdir`: Directory to write generated code into, created if not present
128
128
already. Existing files if any will be overwtitten.
129
129
"""
130
- function generate (proto:: String ; outdir:: String = pwd ())
130
+ function generate (proto:: String ; outdir:: String = pwd (), includes :: Vector{String} = String[] )
131
131
if ! isfile (proto)
132
132
throw (ArgumentError (" No such file - $proto " ))
133
133
end
@@ -138,14 +138,18 @@ function generate(proto::String; outdir::String=pwd())
138
138
# determine the package name and service name
139
139
package, services = detect_services (proto)
140
140
protodir = dirname (proto)
141
- @info (" Detected" , package, services)
141
+ includeflag = ` -I=$protodir `
142
+ for inc in includes
143
+ includeflag = ` $includeflag -I=$inc `
144
+ end
145
+ @info (" Detected" , package, services, includes)
142
146
143
147
# generate protobuf services
144
148
mkpath (outdir)
145
149
bindir = Sys. BINDIR
146
150
pathenv = string (ENV [" PATH" ], Sys. iswindows () ? " ;" : " :" , bindir)
147
151
withenv (" PATH" => pathenv) do
148
- ProtoBuf. protoc (` -I= $protodir --julia_out=$outdir $proto ` )
152
+ ProtoBuf. protoc (` $includeflag --julia_out=$outdir $proto ` )
149
153
end
150
154
151
155
# include the generated code and detect service method names
@@ -154,9 +158,9 @@ function generate(proto::String; outdir::String=pwd())
154
158
Main. eval (:(include ($ generated_module_file)))
155
159
156
160
# generate the gRPC client code
157
- client_module_name = string (titlecase (package ; strict= false ), " Clients" )
161
+ client_module_name = string (titlecase (generated_module ; strict= false ), " Clients" )
158
162
open (joinpath (outdir, " $(client_module_name) .jl" ), " w" ) do grpcservice
159
- write_header (grpcservice, package, client_module_name)
163
+ write_header (grpcservice, generated_module, package, client_module_name)
160
164
for service in services
161
165
methods = get_generated_method_table (string (package, " ._" , service, " _methods" ))
162
166
write_service (grpcservice, package, service, methods)
0 commit comments