Skip to content

Commit 8d4aecd

Browse files
committed
code generator only needing one protos path
1 parent 9880957 commit 8d4aecd

File tree

3 files changed

+22
-49
lines changed

3 files changed

+22
-49
lines changed

lib/actors/config/persistent_term_config.ex

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ if Code.ensure_loaded?(:persistent_term) do
3333
{:grpc_http_transcoding_enabled, "true"},
3434
# default values are evaluated at runtime.
3535
{:grpc_compiled_modules_path, :runtime},
36-
{:grpc_actors_protos_path, :runtime},
3736
{:grpc_include_protos_path, :runtime},
3837
{:internal_nats_hosts, "nats://127.0.0.1:4222"},
3938
{:internal_nats_tls, "false"},
@@ -271,15 +270,6 @@ if Code.ensure_loaded?(:persistent_term) do
271270
value
272271
end
273272

274-
defp load_env({:grpc_actors_protos_path, :runtime}) do
275-
default_value = "#{File.cwd!()}/priv/protos/actors"
276-
277-
value = env("PROXY_GRPC_ACTORS_PROTOS_PATH", default_value)
278-
:persistent_term.put({__MODULE__, :grpc_actors_protos_path}, value)
279-
280-
value
281-
end
282-
283273
defp load_env({:grpc_include_protos_path, :runtime}) do
284274
default_value = "#{File.cwd!()}/priv/protos"
285275

lib/sidecar/grpc/code_generator.ex

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ defmodule Sidecar.GRPC.CodeGenerator do
3737
def compile_protos(opts \\ []) do
3838
Logger.debug("Compiling ActorHost Protocol Buffers...")
3939

40-
actors_path = Keyword.get(opts, :protos_path, Config.get(:grpc_actors_protos_path))
4140
include_path = Keyword.get(opts, :protos_path, Config.get(:grpc_include_protos_path))
4241
output_path = Keyword.get(opts, :output_path, Config.get(:grpc_compiled_modules_path))
4342

@@ -52,13 +51,8 @@ defmodule Sidecar.GRPC.CodeGenerator do
5251
{ProtobufGenerate.Plugins.GRPC, Sidecar.GRPC.Generators.HandlerGenerator}
5352
end
5453

55-
user_defined_proto_files_list = list_files_with_full_path_by_extensions(actors_path, ".proto")
5654
include_files_path = list_files_with_full_path_by_extensions(include_path, ".proto")
5755

58-
Logger.info(
59-
"Found #{length(user_defined_proto_files_list)} ActorHost Protocol Buffers to compile... (#{inspect(user_defined_proto_files_list)})"
60-
)
61-
6256
invoker_helper =
6357
if Code.ensure_loaded?(SpawnSdk) do
6458
["--plugin=Sidecar.GRPC.Generators.ActorInvoker"]
@@ -68,7 +62,7 @@ defmodule Sidecar.GRPC.CodeGenerator do
6862

6963
spawn_protos_dir = Application.app_dir(:spawn, "priv/protos")
7064

71-
if length(user_defined_proto_files_list) > 0 do
65+
if Enum.count(include_files_path) > 0 do
7266
protoc_options =
7367
[
7468
"--include-path=#{include_path}",
@@ -80,19 +74,8 @@ defmodule Sidecar.GRPC.CodeGenerator do
8074
"--plugin=#{handler_generator_plugin}",
8175
"--plugin=Sidecar.GRPC.Generators.GeneratorAccumulator"
8276
] ++
83-
invoker_helper ++
84-
user_defined_proto_files_list
85-
86-
include_files_options =
87-
[
88-
"--include-path=#{include_path}",
89-
"--include-path=#{spawn_protos_dir}",
90-
"--generate-descriptors=true",
91-
"--one-file-per-module",
92-
"--output-path=#{output_path}"
93-
] ++ include_files_path
77+
invoker_helper ++ include_files_path
9478

95-
_ = Generate.run(include_files_options)
9679
_ = Generate.run(protoc_options)
9780

9881
:ok

lib/sidecar/grpc/generators/handler_transcoding_generator.ex

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,29 @@ defmodule Sidecar.GRPC.Generators.HandlerTranscodingGenerator do
1414
@impl true
1515
def template do
1616
"""
17+
<%= if @render do %>
1718
defmodule <%= @module %>.ActorDispatcher do
18-
<%= if @render do %>
19-
use GRPC.Server, service: <%= @service_name %>.Service, http_transcode: true
20-
21-
alias Sidecar.GRPC.Dispatcher
22-
23-
<%= for {method_name, input, output, _options} <- @methods do %>
24-
@spec <%= Macro.underscore(method_name) %>(<%= input %>.t(), GRPC.Server.Stream.t()) :: <%= output %>.t()
25-
def <%= Macro.underscore(method_name) %>(message, stream) do
26-
request = %{
27-
system: <%= inspect(@actor_system) %>,
28-
actor_name: <%= inspect(@actor_name) %>,
29-
action_name: <%= inspect(method_name) %>,
30-
input: message,
31-
stream: stream,
32-
descriptor: <%= @service_name %>.Service.descriptor()
33-
}
34-
35-
Dispatcher.dispatch(request)
36-
end
37-
<% end %>
19+
use GRPC.Server, service: <%= @service_name %>.Service, http_transcode: true
20+
21+
alias Sidecar.GRPC.Dispatcher
22+
23+
<%= for {method_name, input, output, _options} <- @methods do %>
24+
@spec <%= Macro.underscore(method_name) %>(<%= input %>.t(), GRPC.Server.Stream.t()) :: <%= output %>.t()
25+
def <%= Macro.underscore(method_name) %>(message, stream) do
26+
request = %{
27+
system: <%= inspect(@actor_system) %>,
28+
actor_name: <%= inspect(@actor_name) %>,
29+
action_name: <%= inspect(method_name) %>,
30+
input: message,
31+
stream: stream,
32+
descriptor: <%= @service_name %>.Service.descriptor()
33+
}
34+
35+
Dispatcher.dispatch(request)
36+
end
3837
<% end %>
3938
end
39+
<% end %>
4040
"""
4141
end
4242

0 commit comments

Comments
 (0)