Skip to content

Commit b210ba1

Browse files
committed
use depset for transitive reexports in HaskellLibraryInfo
1 parent d63bfde commit b210ba1

File tree

5 files changed

+82
-18
lines changed

5 files changed

+82
-18
lines changed

haskell/cabal.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ def _haskell_cabal_library_impl(ctx):
611611
user_compile_flags = [],
612612
user_repl_flags = [],
613613
)
614-
lib_info = HaskellLibraryInfo(package_id = package_id, version = None, exports = [])
614+
lib_info = HaskellLibraryInfo(package_id = package_id, version = None, exports = depset([package_id]))
615615
if with_haddock:
616616
doc_info = generate_unified_haddock_info(
617617
this_package_id = package_id,

haskell/private/haskell_impl.bzl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -652,14 +652,16 @@ def haskell_library_impl(ctx):
652652
)
653653

654654
exports = [
655-
reexp[HaskellLibraryInfo]
655+
reexp[HaskellLibraryInfo].exports
656656
for reexp in ctx.attr.exports
657-
if HaskellCoverageInfo in reexp
658657
]
659658
lib_info = HaskellLibraryInfo(
660659
package_id = pkg_id.to_string(my_pkg_id),
661660
version = version,
662-
exports = exports,
661+
exports = depset(
662+
[pkg_id.to_string(my_pkg_id)],
663+
transitive = exports,
664+
),
663665
)
664666

665667
dep_coverage_data = []
@@ -888,7 +890,7 @@ def haskell_import_impl(ctx):
888890
lib_info = HaskellLibraryInfo(
889891
package_id = id,
890892
version = ctx.attr.version,
891-
exports = [],
893+
exports = depset([id]),
892894
)
893895
default_info = DefaultInfo(
894896
files = depset(target_files),

haskell/providers.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ HaskellLibraryInfo = provider(
3131
fields = {
3232
"package_id": "Workspace unique package identifier.",
3333
"version": "Package version.",
34-
"exports": "List of other `HaskellLibraryInfo` that this package reexports",
34+
"exports": "List of `package_id`s that this package exports, that is to say, reexports and this package's own `package_id`",
3535
},
3636
)
3737

3838
def all_package_ids(lib_info):
39-
return [lib_info.package_id] + [sublib_info.package_id for sublib_info in lib_info.exports]
39+
return lib_info.exports.to_list()
4040

4141
# XXX: Does this belong here?
4242
def all_dependencies_package_ids(deps):

rules_haskell_tests/tests/RunTests.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ main = hspec $ around_ printStatsHook $ do
117117
it "loads module with module dependency" $
118118
assertSuccess (Process.proc "./.ghcide" ["tests/binary-with-lib/Main.hs"])
119119

120+
describe "transitive re-exports" $ do
121+
it "work" $
122+
assertSuccess (bazel ["build", "//tests/package-reexport-transitive"])
123+
it "work for long chains" $
124+
assertSuccess (bazel ["build", "//tests/package-reexport-transitive:long"])
125+
it "do not work for interrupted chains" $
126+
assertFailure (bazel ["build", "//tests/package-reexport-transitive:interrupted"])
127+
120128
describe "failures" $ do
121129
-- Make sure not to include haskell_repl (@repl) or alias (-repl) targets
122130
-- in the query. Those would not fail under bazel test.
@@ -130,9 +138,6 @@ main = hspec $ around_ printStatsHook $ do
130138
it "haskell_doc fails with plugins #1549" $
131139
-- https://github.com/tweag/rules_haskell/issues/1549
132140
assertFailure (bazel ["build", "//tests/haddock-with-plugin"])
133-
it "transitive re-exports do not work #1145" $
134-
-- https://github.com/tweag/rules_haskell/issues/1145
135-
assertFailure (bazel ["build", "//tests/package-reexport-transitive"])
136141
it "doctest failure with foreign import #1559" $
137142
-- https://github.com/tweag/rules_haskell/issues/1559
138143
assertFailure (bazel ["build", "//tests/haskell_doctest_ffi_1559:doctest-a"])

rules_haskell_tests/tests/package-reexport-transitive/BUILD.bazel

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,38 @@ haskell_library(
1414

1515
haskell_library(
1616
name = "intermediate",
17-
exports = [
18-
":root",
19-
],
20-
deps = [
21-
":root",
22-
],
17+
exports = [":root"],
18+
deps = [":root"],
19+
)
20+
21+
haskell_library(
22+
name = "intermediate1",
23+
exports = [":intermediate"],
24+
deps = [":intermediate"],
25+
)
26+
27+
haskell_library(
28+
name = "intermediate2",
29+
exports = [":intermediate1"],
30+
deps = [":intermediate1"],
31+
)
32+
33+
haskell_library(
34+
name = "intermediate3",
35+
exports = [":intermediate2"],
36+
deps = [":intermediate2"],
37+
)
38+
39+
haskell_library(
40+
name = "intermediate4",
41+
exports = [],
42+
deps = [":intermediate2"],
43+
)
44+
45+
haskell_library(
46+
name = "intermediate5",
47+
exports = [":intermediate4"],
48+
deps = [":intermediate4"],
2349
)
2450

2551
haskell_library(
@@ -30,8 +56,6 @@ haskell_library(
3056
],
3157
)
3258

33-
# Failure test for https://github.com/tweag/rules_haskell/issues/1145
34-
# TODO Turn into regression test once that issue is resolved.
3559
haskell_test(
3660
name = "final",
3761
srcs = ["Main.hs"],
@@ -47,3 +71,36 @@ test_suite(
4771
tags = ["manual"],
4872
tests = [":final"],
4973
)
74+
75+
haskell_test(
76+
name = "final-long",
77+
srcs = ["Main.hs"],
78+
tags = ["manual"],
79+
deps = [
80+
":intermediate3",
81+
"//tests/hackage:base",
82+
],
83+
)
84+
85+
test_suite(
86+
name = "long",
87+
tags = ["manual"],
88+
tests = [":final-long"],
89+
)
90+
91+
haskell_test(
92+
name = "final-interrupted",
93+
srcs = ["Main.hs"],
94+
tags = ["manual"],
95+
deps = [
96+
":intermediate5",
97+
"//tests/hackage:base",
98+
],
99+
)
100+
101+
test_suite(
102+
name = "interrupted",
103+
tags = ["manual"],
104+
tests = [":final-interrupted"],
105+
)
106+

0 commit comments

Comments
 (0)