Skip to content

Commit 7ad84f7

Browse files
committed
Adapt tests for "Cabal//:cabal" optional dependency
This dependency is not needed since ghc 9.6
1 parent 2c21462 commit 7ad84f7

File tree

7 files changed

+20
-13
lines changed

7 files changed

+20
-13
lines changed

WORKSPACE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ load("//haskell:private/ghc_ci.bzl", "ghc_version")
44

55
ghc_version(name = "rules_haskell_ghc_version")
66

7+
load("@rules_haskell//haskell:private/versions.bzl", "is_at_least")
78
load("//haskell:repositories.bzl", "rules_haskell_dependencies")
89

910
rules_haskell_dependencies()
@@ -179,7 +180,7 @@ stack_snapshot(
179180
"proto-lens-runtime",
180181
"lens-family",
181182
],
182-
setup_deps = {} if GHC_VERSION and GHC_VERSION.startswith("9.6.") else {
183+
setup_deps = {} if GHC_VERSION and is_at_least("9.6", GHC_VERSION) else {
183184
# See https://github.com/tweag/rules_haskell/issues/1871
184185
"HUnit": ["@Cabal//:Cabal"],
185186
"bifunctors": ["@Cabal//:Cabal"],

extensions/rules_haskell_dependencies.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
66
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
77
load("@rules_haskell//tools:os_info.bzl", "os_info")
88
load("@rules_haskell_ghc_version//:ghc_version.bzl", "GHC_VERSION")
9+
load("@rules_haskell//haskell:private/versions.bzl", "is_at_least")
910

1011
def _empty_repo_impl(rctx):
1112
fail(rctx.attr.error_msg)
@@ -38,7 +39,8 @@ def repositories(*, bzlmod): # @unused
3839

3940
# TODO: Remove when tests are run with a ghc version containing Cabal >= 3.10
4041
# See https://github.com/tweag/rules_haskell/issues/1871
41-
if GHC_VERSION and GHC_VERSION.startswith("9.6."):
42+
43+
if GHC_VERSION and is_at_least("9.6", GHC_VERSION):
4244
_empty_repo(
4345
name = "Cabal",
4446
error_msg = "When using GHC >= 9.6, do not depend on @Cabal, as https://github.com/tweag/rules_haskell/issues/1871 is fixed.",

haskell/private/versions.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _parse_bazel_version(bazel_version):
5151
"""
5252
return [int(_parse_version_chunk(x)) for x in bazel_version.split(".")]
5353

54-
def _is_at_least(threshold, version):
54+
def is_at_least(threshold, version):
5555
"""Check that a version is higher or equals to a threshold.
5656
Args:
5757
threshold: the minimum version string
@@ -64,7 +64,7 @@ def _is_at_least(threshold, version):
6464
# Needed for check_bazel_version below.
6565
return _parse_bazel_version(version) >= _parse_bazel_version(threshold)
6666

67-
def _is_at_most(threshold, version):
67+
def is_at_most(threshold, version):
6868
"""Check that a version is lower or equals to a threshold.
6969
Args:
7070
threshold: the maximum version string
@@ -103,7 +103,7 @@ def check_bazel_version(minimum_bazel_version, maximum_bazel_version = None, baz
103103
else:
104104
bazel_version = native.bazel_version
105105

106-
if not _is_at_least(
106+
if not is_at_least(
107107
threshold = minimum_bazel_version,
108108
version = bazel_version,
109109
):
@@ -113,7 +113,7 @@ def check_bazel_version(minimum_bazel_version, maximum_bazel_version = None, baz
113113
))
114114

115115
if maximum_bazel_version:
116-
if not _is_at_most(
116+
if not is_at_most(
117117
threshold = maximum_bazel_version,
118118
version = bazel_version,
119119
):

rules_haskell_tests/WORKSPACE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local_repository(
66
)
77

88
load("@rules_haskell//haskell:private/ghc_ci.bzl", "ghc_version")
9+
load("@rules_haskell//haskell:private/versions.bzl", "is_at_least")
910

1011
ghc_version(name = "rules_haskell_ghc_version")
1112

@@ -297,7 +298,7 @@ stack_snapshot(
297298
"typed-process": ["@Cabal//:Cabal"],
298299
"unliftio-core": ["@Cabal//:Cabal"],
299300
}.items()
300-
if [d for d in deps if d != "@Cabal//:Cabal"] or not GHC_VERSION or not GHC_VERSION.startswith("9.6.")
301+
if [d for d in deps if d != "@Cabal//:Cabal"] or not GHC_VERSION or not is_at_least("9.6", GHC_VERSION)
301302
},
302303
stack_snapshot_json = "//:stackage_snapshot{}.json".format(
303304
"_" + str(GHC_VERSION) if GHC_VERSION else "",

rules_haskell_tests/non_module_deps_2.bzl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
""" External repositories for the CI that need to be shared between WORKSPACE and MODULE.bazel files """
22

33
load("@rules_haskell//haskell:cabal.bzl", "stack_snapshot")
4+
load("@rules_haskell//haskell:private/versions.bzl", "is_at_least")
45
load("@os_info//:os_info.bzl", "is_linux", "is_windows")
56
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
67
load("@toolchains_libraries//:toolchain_libraries.bzl", "toolchain_libraries")
@@ -88,7 +89,7 @@ def repositories(*, bzlmod): # @unused
8889
"unliftio-core": ["@ghcide//:Cabal"],
8990
"yaml": ["@ghcide//:Cabal"],
9091
}.items()
91-
if [d for d in deps if d != "@Cabal//:Cabal"] or not GHC_VERSION or not GHC_VERSION.startswith("9.6.")
92+
if [d for d in deps if d != "@Cabal//:Cabal"] or not GHC_VERSION or not is_at_least("9.6", GHC_VERSION)
9293
},
9394
stack_snapshot_json = ("//:ghcide-snapshot{}.json".format(
9495
"_" + str(GHC_VERSION) if GHC_VERSION else "",
@@ -119,15 +120,15 @@ haskell_cabal_binary(
119120
verbose = False,
120121
visibility = ["//visibility:public"],
121122
)
122-
""".format(setup_deps = "" if GHC_VERSION and GHC_VERSION.startswith("9.6.") else """setup_deps = ["@Cabal//:Cabal"],"""),
123+
""".format(setup_deps = "" if GHC_VERSION and is_at_least("9.6", GHC_VERSION) else """setup_deps = ["@Cabal//:Cabal"],"""),
123124
sha256 = "9bd2f1a27e8f1b2ffdb5b2fbd3ed82b6f0e85191459a1b24ffcbef4e68a81bec",
124125
strip_prefix = "alex-3.2.7.1",
125126
urls = ["http://hackage.haskell.org/package/alex-3.2.7.1/alex-3.2.7.1.tar.gz"],
126127
)
127128

128129
# TODO: Remove when tests are run with a ghc version containing Cabal >= 3.10
129130
# See https://github.com/tweag/rules_haskell/issues/1871
130-
if GHC_VERSION and GHC_VERSION.startswith("9.6."):
131+
if GHC_VERSION and is_at_least("9.6", GHC_VERSION):
131132
_empty_repo(
132133
name = "Cabal",
133134
error_msg = "When using GHC >= 9.6, do not depend on @Cabal, as https://github.com/tweag/rules_haskell/issues/1871 is fixed.",
@@ -200,7 +201,7 @@ haskell_cabal_library(
200201
"hspec-expectations": ["@Cabal//:Cabal"],
201202
"quickcheck-io": ["@Cabal//:Cabal"],
202203
}.items()
203-
if [d for d in deps if d != "@Cabal//:Cabal"] or not GHC_VERSION or not GHC_VERSION.startswith("9.6.")
204+
if [d for d in deps if d != "@Cabal//:Cabal"] or not GHC_VERSION or not is_at_least("9.6", GHC_VERSION)
204205
},
205206
stack_snapshot_json = ("//:stackage-pinning-test_snapshot{}.json".format(
206207
"_" + str(GHC_VERSION) if GHC_VERSION else "",

rules_haskell_tests/tests/haskell_cabal_datafiles/compare_other_cabal_functions/without_generate_paths_module/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ load(
77
"haskell_binary",
88
"haskell_toolchain_library",
99
)
10+
load("@rules_haskell//haskell:private/versions.bzl", "is_at_least")
1011
load("@rules_haskell_ghc_version//:ghc_version.bzl", "GHC_VERSION")
1112

1213
package(default_testonly = 1)
@@ -21,7 +22,7 @@ haskell_cabal_library(
2122
"lib.cabal",
2223
],
2324
generate_paths_module = False,
24-
setup_deps = [] if GHC_VERSION and GHC_VERSION.startswith("9.6.") else ["@Cabal//:Cabal"],
25+
setup_deps = [] if GHC_VERSION and is_at_least("9.6", GHC_VERSION) else ["@Cabal//:Cabal"],
2526
tags = ["skip_profiling"],
2627
version = "0.1.0.0",
2728
visibility = ["//visibility:public"],

tools/repositories.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
load("@rules_haskell//haskell:cabal.bzl", "stack_snapshot")
44
load("@rules_haskell_ghc_version//:ghc_version.bzl", "GHC_VERSION")
5+
load("@rules_haskell//haskell:private/versions.bzl", "is_at_least")
56

67
def rules_haskell_worker_dependencies(**stack_kwargs):
78
"""
@@ -29,7 +30,7 @@ def rules_haskell_worker_dependencies(**stack_kwargs):
2930
"text",
3031
"vector",
3132
],
32-
setup_deps = {} if GHC_VERSION and GHC_VERSION.startswith("9.6.") else {
33+
setup_deps = {} if GHC_VERSION and is_at_least("9.6", GHC_VERSION) else {
3334
"bifunctors": ["@Cabal//:Cabal"],
3435
"proto-lens-runtime": ["@Cabal//:Cabal"],
3536
"transformers-compat": ["@Cabal//:Cabal"],

0 commit comments

Comments
 (0)