Skip to content

Commit

Permalink
Change dash to underscore in generated filenames (#178)
Browse files Browse the repository at this point in the history
The generated rust code for my-file.proto is in my_file.rs.
Declared outputs for _proto and _grpc rules should reflect this.
  • Loading branch information
mjduijn authored and mfarrugi committed Jan 4, 2019
1 parent b74f9e5 commit ac74cc1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions proto/proto.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ load(
"//proto:toolchain.bzl",
"GRPC_COMPILE_DEPS",
"PROTO_COMPILE_DEPS",
_file_stem = "file_stem",
_generate_proto = "rust_generate_proto",
_generated_file_stem = "generated_file_stem",
)
load("//rust:private/rustc.bzl", "CrateInfo", "rustc_compile_action")
load("//rust:private/utils.bzl", "find_toolchain")
Expand Down Expand Up @@ -106,11 +106,11 @@ def _gen_lib(ctx, grpc, srcs, lib):
content.append("extern crate grpc;")
content.append("extern crate tls_api;")
for f in srcs.to_list():
content.append("pub mod %s;" % _file_stem(f))
content.append("pub use %s::*;" % _file_stem(f))
content.append("pub mod %s;" % _generated_file_stem(f))
content.append("pub use %s::*;" % _generated_file_stem(f))
if grpc:
content.append("pub mod %s_grpc;" % _file_stem(f))
content.append("pub use %s_grpc::*;" % _file_stem(f))
content.append("pub mod %s_grpc;" % _generated_file_stem(f))
content.append("pub use %s_grpc::*;" % _generated_file_stem(f))
ctx.actions.write(lib, "\n".join(content))

def _expand_provider(lst, provider):
Expand Down
5 changes: 3 additions & 2 deletions proto/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

"""Toolchain for compiling rust stubs from protobug and gRPC."""

def file_stem(f):
def generated_file_stem(f):
basename = f.rsplit("/", 2)[-1]
basename = basename.replace("-", "_")
return basename.rsplit(".", 2)[0]

def rust_generate_proto(
Expand Down Expand Up @@ -49,7 +50,7 @@ def rust_generate_proto(

if not protos:
fail("Protobuf compilation requested without inputs!")
paths = ["%s/%s" % (output_dir, file_stem(i)) for i in protos.to_list()]
paths = ["%s/%s" % (output_dir, generated_file_stem(i)) for i in protos.to_list()]
outs = [ctx.actions.declare_file(path + ".rs") for path in paths]
output_directory = outs[0].dirname

Expand Down

0 comments on commit ac74cc1

Please sign in to comment.