-
Notifications
You must be signed in to change notification settings - Fork 7
/
.hie-bios
executable file
·57 lines (52 loc) · 2.59 KB
/
.hie-bios
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env bash
set -euo pipefail
# When using a .hie-bios script with ghcide/hie-bios, the script will be passed
# an environment variable, `HIE_BIOS_OUTPUT`, which contains a filename. This
# script's job is to write to that file a list of command-line arguments that
# when given to (notionally) GHCi will allow ghcide/hie-bios to load that file
# as Haskell code and provide IDE information, etc. When using Bazel to provide
# this information, you can do the following:
#
# * Any `haskell_repl` target (whether defined explicitly by you or implicitly
# e.g. as the `@repl` result of a `haskell_binary` rule) exports an output
# group, `hie_bios`. If you're not familiar with Bazel output groups, you
# might think of them as "optional extras" that you can ask to be built
# alongside default/implicit targets.
#
# * The `hie_bios` output group builds a file that will generate the
# command-line arguments needed to boot up that REPL (i.e. exactly what this
# script needs). Thus this script's job becomes building and `cat`-ing that
# file to the location indicated by the `HIE_BIOS_OUTPUT` environment
# variable.
#
# As it stands, this script also implements some other functionality:
#
# * If the environment variable isn't set, it prints its output to standard
# output (useful for testing/debugging this script or hie-bios/ghcide).
#
# * Due to some bugs/limitations in rules_haskell, it patches the output
# generated by Bazel so that it works with static
# runtimes/fully-statically-linked binary support. This code should disappear
# once these issues are resolved upstream.
# We pick the `impl-ifc-repl` target as that which we'll use to generate
# command-line flags. You can pick others/be smarter here/play with multi-cradle
# support potentially (not done in this repository at present).
bazel build //example-service:impl-ifc-repl --output_groups=hie_bios
# PATCH: The flags generated by rules_haskell use relative paths that will only
# work from the Bazel execroot. This script runs in the workspace root, not the
# execroot, so we patch the appropriate relative paths to address this. We can
# find the execroot by resolving the `bazel-out` symlink for now (as
# rules_haskell does in its GHCi support, which handles this correctly already).
EXECROOT=$(dirname $(readlink ./bazel-out))
hie_bios() {
cat bazel-bin/example-service/impl-ifc-repl@hie-bios \
| sed -e "s#-L#-L$EXECROOT/#g"
}
if [[ -z "${HIE_BIOS_OUTPUT-}" ]]
then
# Output to standard output if the `HIE_BIOS_OUTPUT` environment variable
# isn't set to aid in testing/debugging.
hie_bios
else
hie_bios >"$HIE_BIOS_OUTPUT"
fi