Skip to content

Commit efb2450

Browse files
committed
Use actions.run_shell instead of creating a shell script
A shell script is not runnable on Windows and failed with `%1 is not a valid Win32 application`.
1 parent 3353873 commit efb2450

File tree

4 files changed

+16
-54
lines changed

4 files changed

+16
-54
lines changed

haskell/BUILD.bazel

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ exports_files(
3232
"private/coverage_wrapper.sh.tpl",
3333
"private/ghci_repl_wrapper.sh",
3434
"private/hie_bios_wrapper.sh",
35-
"private/haddock_wrapper.sh.tpl",
3635
"private/cc_wrapper.py.tpl",
3736
"private/cc_wrapper_windows.sh.tpl",
3837
"private/pkgdb_to_bzl.py",

haskell/haddock.bzl

+16-27
Original file line numberDiff line numberDiff line change
@@ -135,26 +135,7 @@ def _haskell_doc_aspect_impl(target, ctx):
135135
[lib for li in target[CcInfo].linking_context.linker_inputs.to_list() for lib in li.libraries],
136136
)
137137

138-
# TODO(mboes): we should be able to instantiate this template only
139-
# once per toolchain instance, rather than here.
140-
# TODO(aherrmann): Convert to a standalone sh_binary.
141-
# Executable shell script files don't work on Windows.
142-
# This fails with `%1 is not a valid Win32 application.`.
143-
haddock_wrapper = ctx.actions.declare_file("haddock_wrapper-{}".format(hs.name))
144-
ctx.actions.expand_template(
145-
template = ctx.file._haddock_wrapper_tpl,
146-
output = haddock_wrapper,
147-
substitutions = {
148-
"%{ghc-pkg}": hs.tools.ghc_pkg.path, # not mentioned in bash XXX delete?
149-
"%{haddock}": shell.quote(hs.tools.haddock.path),
150-
# XXX Workaround
151-
# https://github.com/bazelbuild/bazel/issues/5980.
152-
"%{env}": render_env(hs.env),
153-
},
154-
is_executable = True,
155-
)
156-
157-
ctx.actions.run(
138+
ctx.actions.run_shell(
158139
inputs = depset(transitive = [
159140
target[HaskellInfo].package_databases,
160141
target[HaskellInfo].interface_dirs,
@@ -177,7 +158,21 @@ def _haskell_doc_aspect_impl(target, ctx):
177158
outputs = [haddock_file, html_dir],
178159
mnemonic = "HaskellHaddock",
179160
progress_message = "HaskellHaddock {}".format(ctx.label),
180-
executable = haddock_wrapper,
161+
command = """
162+
set -eo pipefail
163+
164+
{env}
165+
166+
# BSD and GNU mktemp are very different; attempt GNU first
167+
TEMP=$(mktemp -d 2>/dev/null || mktemp -d -t 'haddock_wrapper')
168+
trap cleanup 1 2 3 6
169+
cleanup() {{ rm -rf "$TEMP"; }}
170+
# XXX Override TMPDIR to prevent race conditions on certain platforms.
171+
# This is a workaround for
172+
# https://github.com/haskell/haddock/issues/894.
173+
TMPDIR=$TEMP {haddock} "$@"
174+
cleanup
175+
""".format(env = render_env(hs.env), haddock = shell.quote(hs.tools.haddock.path)),
181176
arguments = [
182177
args,
183178
compile_flags,
@@ -201,12 +196,6 @@ def _haskell_doc_aspect_impl(target, ctx):
201196

202197
haskell_doc_aspect = aspect(
203198
_haskell_doc_aspect_impl,
204-
attrs = {
205-
"_haddock_wrapper_tpl": attr.label(
206-
allow_single_file = True,
207-
default = Label("@rules_haskell//haskell:private/haddock_wrapper.sh.tpl"),
208-
),
209-
},
210199
attr_aspects = ["deps", "exports"],
211200
required_aspect_providers = [HaskellCcLibrariesInfo],
212201
toolchains = [

haskell/private/haddock_wrapper.sh.tpl

-19
This file was deleted.

tests/shellcheck/BUILD.bazel

-7
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ shellcheck(
2828
sh_flavor = "bash",
2929
)
3030

31-
shellcheck(
32-
name = "haddock_wrapper.sh",
33-
args = ["$(location @rules_haskell//haskell:private/haddock_wrapper.sh.tpl)"],
34-
data = ["@rules_haskell//haskell:private/haddock_wrapper.sh.tpl"],
35-
sh_flavor = "bash",
36-
)
37-
3831
shellcheck(
3932
name = "netlify-build",
4033
args = ["$(location @rules_haskell//:.netlify/build.sh)"],

0 commit comments

Comments
 (0)