Skip to content

Commit

Permalink
Fix execute_or_fail_loudly in ghc_bindist
Browse files Browse the repository at this point in the history
The call to `fail` itself failed with
```
	File "/var/lib/buildkite-agent/.cache/bazel/_bazel_buildkite-agent/8b8a09a5fc28e77c5514319513adb8f9/external/rules_haskell/haskell/ghc_bindist.bzl", line 197, in "{0} failed, aborting creation of GHC bindist".format
		" ".join(args)
sequence element must be a string (got 'path'). See bazelbuild/bazel#7802 for information about --incompatible_string_join_requires_strings.
```

This change switches to a shared implementation that fixes this issue.
  • Loading branch information
aherrmann committed Nov 25, 2019
1 parent eaea84d commit fd7f070
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions haskell/ghc_bindist.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "patch")
load("@rules_sh//sh:posix.bzl", "sh_posix_configure")
load(
"@rules_haskell//haskell:private/workspace_utils.bzl",
"execute_or_fail_loudly",
)

_GHC_DEFAULT_VERSION = "8.6.5"

Expand Down Expand Up @@ -182,20 +186,6 @@ GHC_BINDIST = \
},
}

def _execute_fail_loudly(ctx, args):
"""Execute a command and fail loudly if it fails.
ATTN: All commands have to be cross-compatible between BSD tools and GNU tools,
because we want to support macOS. Please cross-reference the macOS man-pages.
Args:
ctx: Repository rule context.
args: Command and its arguments.
"""
eresult = ctx.execute(args, quiet = False)
if eresult.return_code != 0:
fail("{0} failed, aborting creation of GHC bindist".format(" ".join(args)))

def _ghc_bindist_impl(ctx):
# Avoid rule restart by resolving these labels early. See
# https://github.com/bazelbuild/bazel/blob/master/tools/cpp/lib_cc_configure.bzl#L17.
Expand Down Expand Up @@ -226,15 +216,15 @@ def _ghc_bindist_impl(ctx):

# As the patches may touch the package DB we regenerate the cache.
if len(ctx.attr.patches) > 0:
_execute_fail_loudly(ctx, ["./bin/ghc-pkg", "recache"])
execute_or_fail_loudly(ctx, ["./bin/ghc-pkg", "recache"])

# On Windows the bindist already contains the built executables
if os != "windows":
# IMPORTANT: all these scripts have to be compatible with BSD
# tools! This means that sed -i always takes an argument.
_execute_fail_loudly(ctx, ["sed", "-e", "s/RelocatableBuild = NO/RelocatableBuild = YES/", "-i.bak", "mk/config.mk.in"])
_execute_fail_loudly(ctx, ["./configure", "--prefix", bindist_dir.realpath])
_execute_fail_loudly(ctx, ["make", "install"])
execute_or_fail_loudly(ctx, ["sed", "-e", "s/RelocatableBuild = NO/RelocatableBuild = YES/", "-i.bak", "mk/config.mk.in"])
execute_or_fail_loudly(ctx, ["./configure", "--prefix", bindist_dir.realpath])
execute_or_fail_loudly(ctx, ["make", "install"])
ctx.file("patch_bins", executable = True, content = r"""#!/usr/bin/env bash
grep --files-with-matches --null {bindist_dir} bin/* | xargs -0 -n1 \
sed -i.bak \
Expand All @@ -244,7 +234,7 @@ grep --files-with-matches --null {bindist_dir} bin/* | xargs -0 -n1 \
""".format(
bindist_dir = bindist_dir.realpath,
))
_execute_fail_loudly(ctx, ["./patch_bins"])
execute_or_fail_loudly(ctx, ["./patch_bins"])

# Generate BUILD file entries describing each prebuilt package.
# Cannot use //haskell:pkgdb_to_bzl because that's a generated
Expand Down Expand Up @@ -285,9 +275,9 @@ haskell_toolchain(
if os == "windows":
# These libraries cause linking errors on Windows when linking
# pthreads, due to libwinpthread-1.dll not being loaded.
_execute_fail_loudly(ctx, ["rm", "mingw/lib/gcc/x86_64-w64-mingw32/7.2.0/libstdc++.dll.a"])
_execute_fail_loudly(ctx, ["rm", "mingw/x86_64-w64-mingw32/lib/libpthread.dll.a"])
_execute_fail_loudly(ctx, ["rm", "mingw/x86_64-w64-mingw32/lib/libwinpthread.dll.a"])
execute_or_fail_loudly(ctx, ["rm", "mingw/lib/gcc/x86_64-w64-mingw32/7.2.0/libstdc++.dll.a"])
execute_or_fail_loudly(ctx, ["rm", "mingw/x86_64-w64-mingw32/lib/libpthread.dll.a"])
execute_or_fail_loudly(ctx, ["rm", "mingw/x86_64-w64-mingw32/lib/libwinpthread.dll.a"])

ctx.template(
"BUILD",
Expand Down

0 comments on commit fd7f070

Please sign in to comment.