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

fix: convert forward slashes to backslashes for protoc plugins on Windows. #668

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions ts/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ bzl_library(
"//ts/private:ts_proto_library",
"@aspect_bazel_lib//lib:copy_to_directory",
"@aspect_bazel_lib//lib:directory_path",
"@aspect_bazel_lib//lib:platform_utils",
"@aspect_bazel_lib//lib:write_source_files",
"@aspect_rules_js//js:defs",
"@aspect_rules_js//js:libs",
Expand Down
14 changes: 11 additions & 3 deletions ts/private/ts_proto_library.bzl
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
"Private implementation details for ts_proto_library"

load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "COPY_FILE_TO_BIN_TOOLCHAINS")
load("@aspect_bazel_lib//lib:platform_utils.bzl", "platform_utils")
load("@rules_proto//proto:defs.bzl", "ProtoInfo", "proto_common")
load("@rules_proto//proto:proto_common.bzl", proto_toolchains = "toolchains")

_PROTO_TOOLCHAIN_TYPE = "@rules_proto//proto:toolchain_type"

def _windows_path_normalize(path):
"""Changes forward slashs to backslashs for Windows paths."""
host_is_windows = platform_utils.host_platform_is_windows()
if host_is_windows:
return path.replace("/", "\\")
return path

# buildifier: disable=function-docstring-header
def _protoc_action(ctx, proto_info, outputs):
"""Create an action like
Expand All @@ -29,19 +37,19 @@ def _protoc_action(ctx, proto_info, outputs):
fail("protoc_gen_options.target must be 'js+dts'")

args = ctx.actions.args()
args.add_joined(["--plugin", "protoc-gen-es", ctx.executable.protoc_gen_es.path], join_with = "=")
args.add_joined(["--plugin", "protoc-gen-es", _windows_path_normalize(ctx.executable.protoc_gen_es.path)], join_with = "=")
for (key, value) in options.items():
args.add_joined(["--es_opt", key, value], join_with = "=")
args.add_joined(["--es_out", ctx.bin_dir.path], join_with = "=")

if ctx.attr.gen_connect_es:
args.add_joined(["--plugin", "protoc-gen-connect-es", ctx.executable.protoc_gen_connect_es.path], join_with = "=")
args.add_joined(["--plugin", "protoc-gen-connect-es", _windows_path_normalize(ctx.executable.protoc_gen_connect_es.path)], join_with = "=")
for (key, value) in options.items():
args.add_joined(["--connect-es_opt", key, value], join_with = "=")
args.add_joined(["--connect-es_out", ctx.bin_dir.path], join_with = "=")

if ctx.attr.gen_connect_query:
args.add_joined(["--plugin", "protoc-gen-connect-query", ctx.executable.protoc_gen_connect_query.path], join_with = "=")
args.add_joined(["--plugin", "protoc-gen-connect-query", _windows_path_normalize(ctx.executable.protoc_gen_connect_query.path)], join_with = "=")
for (key, value) in options.items():
args.add_joined(["--connect-query_opt", key, value], join_with = "=")
args.add_joined(["--connect-query_out", ctx.bin_dir.path], join_with = "=")
Expand Down