Skip to content

Commit

Permalink
Try py_binary instead of sh_binary
Browse files Browse the repository at this point in the history
  • Loading branch information
facundominguez committed Mar 18, 2021
1 parent 12d2fd6 commit 8f8854c
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions haskell/private/runghc.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@rules_python//python:defs.bzl", "py_binary")

# Note [Running Setup.hs when cross-compiling]
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -21,22 +22,15 @@ def _runghc_wrapper_impl(ctx):
ctx.actions.write(
output = runghc_wrapper_file,
content = """\
#!/usr/bin/env bash
#!/usr/bin/env python3
# --- begin runfiles.bash initialization v2 ---
# Copy-pasted from the Bazel Bash runfiles library v2.
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${{RUNFILES_DIR:-/dev/null}}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${{RUNFILES_MANIFEST_FILE:-/dev/null}}" | cut -f2- -d' ')" 2>/dev/null || \
source "$0.runfiles/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{{ echo>&2 "ERROR: cannot find $f"; exit 1; }}; f=; set -e
# --- end runfiles.bash initialization v2 ---
import subprocess
import sys
from rules_python.python.runfiles import runfiles
echo $0.runfiles_manifest 1>&2
find "$(dirname "$0")" -name "runghc*manifest*" 1>&2
$(rlocation "{runghc}") "$@"
r = runfiles.Create()
subprocess.run([r.Rlocation("{runghc}")] + sys.argv[1:], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
""".format(runghc = runghc_runfile_path),
is_executable = True,
)
Expand All @@ -55,14 +49,16 @@ _runghc_wrapper = rule(
doc = """Produces the runghc wrapper script.""",
)

def runghc(name, visibility):
_runghc_wrapper(name = name + ".sh")
native.sh_binary(
def runghc(name, **kwargs):
_runghc_wrapper(name = name + ".py")
py_binary(
name = name,
srcs = [name + ".sh"],
data = [name + ".sh"],
srcs = [name + ".py"],
data = [name + ".py"],
srcs_version = "PY3",
python_version = "PY3",
deps = [
"@bazel_tools//tools/bash/runfiles",
"@rules_python//python/runfiles",
],
visibility = visibility,
**kwargs,
)

0 comments on commit 8f8854c

Please sign in to comment.