@@ -135,26 +135,7 @@ def _haskell_doc_aspect_impl(target, ctx):
135
135
[lib for li in target [CcInfo ].linking_context .linker_inputs .to_list () for lib in li .libraries ],
136
136
)
137
137
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 (
158
139
inputs = depset (transitive = [
159
140
target [HaskellInfo ].package_databases ,
160
141
target [HaskellInfo ].interface_dirs ,
@@ -177,7 +158,21 @@ def _haskell_doc_aspect_impl(target, ctx):
177
158
outputs = [haddock_file , html_dir ],
178
159
mnemonic = "HaskellHaddock" ,
179
160
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 )),
181
176
arguments = [
182
177
args ,
183
178
compile_flags ,
@@ -201,12 +196,6 @@ def _haskell_doc_aspect_impl(target, ctx):
201
196
202
197
haskell_doc_aspect = aspect (
203
198
_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
- },
210
199
attr_aspects = ["deps" , "exports" ],
211
200
required_aspect_providers = [HaskellCcLibrariesInfo ],
212
201
toolchains = [
0 commit comments