Skip to content

Commit

Permalink
Use sh_binary rule instead of py_binary
Browse files Browse the repository at this point in the history
  • Loading branch information
avdv committed Aug 22, 2023
1 parent fa79a8e commit 05d0acd
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions tests/protoc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def _protoc_wrapper_impl(ctx):
ctx.actions.write(
output = protoc_wrapper_file,
content = """\
import os, subprocess, sys
#!/usr/bin/env bash
path = os.environ.get("PATH", "")
path = os.pathsep.join([path, os.path.realpath(os.path.dirname({compiler_exe}))])
os.environ["PATH"] = path
subprocess.check_call([{protoc}] + sys.argv[1:])
set -eo pipefail
PATH=$PATH:$(cd "$(dirname ${compiler_exe})" && pwd )
exec {protoc} "$@"
""".format(protoc = repr(ctx.executable._protoc.path), compiler_exe = repr(compiler)),
is_executable = True,
)
Expand All @@ -32,16 +32,14 @@ _protoc_wrapper = rule(
executable = True,
implementation = _protoc_wrapper_impl,
attrs = {
"_protoc": attr.label(executable = True, cfg="exec", default = "@com_google_protobuf//:protoc"),
"_protoc": attr.label(executable = True, cfg = "exec", default = "@com_google_protobuf//:protoc"),
},
toolchains = ["@rules_cc//cc:toolchain_type"],
)

def protoc_wrapper(name):
_protoc_wrapper(name = name + ".py")
py_binary(
_protoc_wrapper(name = name + ".sh")
native.sh_binary(
name = name,
srcs = [name + ".py"],
srcs_version = "PY3",
python_version = "PY3",
srcs = [name + ".sh"],
)

0 comments on commit 05d0acd

Please sign in to comment.