Skip to content

Commit

Permalink
Merge pull request #1303 from tweag/cabal-exe-name
Browse files Browse the repository at this point in the history
haskell_cabal_binary allow target name and executable to differ
  • Loading branch information
mergify[bot] authored Jun 2, 2020
2 parents 5e401dd + 64449e6 commit 1809a3b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions haskell/cabal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ def _haskell_cabal_binary_impl(ctx):
)
posix = ctx.toolchains["@rules_sh//sh/posix:toolchain_type"]

exe_name = ctx.attr.exe_name if ctx.attr.exe_name else hs.label.name
user_compile_flags = _expand_make_variables("compiler_flags", ctx, ctx.attr.compiler_flags)
cabal = _find_cabal(hs, ctx.files.srcs)
setup = _find_setup(hs, cabal, ctx.files.srcs)
Expand All @@ -560,7 +561,7 @@ def _haskell_cabal_binary_impl(ctx):
)
binary = hs.actions.declare_file(
"_install/bin/{name}{ext}".format(
name = hs.label.name,
name = exe_name,
ext = ".exe" if hs.toolchain.is_windows else "",
),
sibling = cabal,
Expand All @@ -577,7 +578,7 @@ def _haskell_cabal_binary_impl(ctx):
dep_info,
cc_info,
direct_cc_info,
component = "exe:{}".format(hs.label.name),
component = "exe:{}".format(exe_name),
package_id = hs.label.name,
tool_inputs = tool_inputs,
tool_input_manifests = tool_input_manifests,
Expand Down Expand Up @@ -636,6 +637,9 @@ haskell_cabal_binary = rule(
_haskell_cabal_binary_impl,
executable = True,
attrs = {
"exe_name": attr.string(
doc = "Cabal executable component name. Defaults to the value of the name attribute.",
),
"srcs": attr.label_list(allow_files = True),
"deps": attr.label_list(
aspects = [haskell_cc_libraries_aspect],
Expand Down
3 changes: 2 additions & 1 deletion tests/haskell_cabal_package/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ haskell_cabal_library(
)

haskell_cabal_binary(
name = "haskell_cabal_package",
name = "exe",
srcs = glob(["**"]),
exe_name = "haskell_cabal_package",
deps = [
":base",
":lib",
Expand Down

0 comments on commit 1809a3b

Please sign in to comment.