Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change dash to underscore in generated filenames #178

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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