Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use depset for reexports in HaskellLibraryInfo #2125

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion haskell/cabal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ def _haskell_cabal_library_impl(ctx):
user_compile_flags = [],
user_repl_flags = [],
)
lib_info = HaskellLibraryInfo(package_id = package_id, version = None, exports = [])
lib_info = HaskellLibraryInfo(package_id = package_id, version = None, exports = depset([package_id]))
if with_haddock:
doc_info = generate_unified_haddock_info(
this_package_id = package_id,
Expand Down
10 changes: 6 additions & 4 deletions haskell/private/haskell_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -652,14 +652,16 @@ def haskell_library_impl(ctx):
)

exports = [
reexp[HaskellLibraryInfo]
reexp[HaskellLibraryInfo].exports
for reexp in ctx.attr.exports
if HaskellCoverageInfo in reexp
]
lib_info = HaskellLibraryInfo(
package_id = pkg_id.to_string(my_pkg_id),
version = version,
exports = exports,
exports = depset(
[pkg_id.to_string(my_pkg_id)],
transitive = exports,
),
)

dep_coverage_data = []
Expand Down Expand Up @@ -888,7 +890,7 @@ def haskell_import_impl(ctx):
lib_info = HaskellLibraryInfo(
package_id = id,
version = ctx.attr.version,
exports = [],
exports = depset([id]),
)
default_info = DefaultInfo(
files = depset(target_files),
Expand Down
4 changes: 2 additions & 2 deletions haskell/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ HaskellLibraryInfo = provider(
fields = {
"package_id": "Workspace unique package identifier.",
"version": "Package version.",
"exports": "List of other `HaskellLibraryInfo` that this package reexports",
"exports": "List of `package_id`s that this package exports, that is to say, reexports and this package's own `package_id`",
},
)

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

# XXX: Does this belong here?
def all_dependencies_package_ids(deps):
Expand Down
11 changes: 8 additions & 3 deletions rules_haskell_tests/tests/RunTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ main = hspec $ around_ printStatsHook $ do
it "loads module with module dependency" $
assertSuccess (Process.proc "./.ghcide" ["tests/binary-with-lib/Main.hs"])

describe "transitive re-exports" $ do
it "work" $
assertSuccess (bazel ["build", "//tests/package-reexport-transitive"])
it "work for long chains" $
assertSuccess (bazel ["build", "//tests/package-reexport-transitive:long"])
it "do not work for interrupted chains" $
assertFailure (bazel ["build", "//tests/package-reexport-transitive:interrupted"])

describe "failures" $ do
-- Make sure not to include haskell_repl (@repl) or alias (-repl) targets
-- in the query. Those would not fail under bazel test.
Expand All @@ -130,9 +138,6 @@ main = hspec $ around_ printStatsHook $ do
it "haskell_doc fails with plugins #1549" $
-- https://github.com/tweag/rules_haskell/issues/1549
assertFailure (bazel ["build", "//tests/haddock-with-plugin"])
it "transitive re-exports do not work #1145" $
-- https://github.com/tweag/rules_haskell/issues/1145
assertFailure (bazel ["build", "//tests/package-reexport-transitive"])
it "doctest failure with foreign import #1559" $
-- https://github.com/tweag/rules_haskell/issues/1559
assertFailure (bazel ["build", "//tests/haskell_doctest_ffi_1559:doctest-a"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,38 @@ haskell_library(

haskell_library(
name = "intermediate",
exports = [
":root",
],
deps = [
":root",
],
exports = [":root"],
deps = [":root"],
)

haskell_library(
name = "intermediate1",
exports = [":intermediate"],
deps = [":intermediate"],
)

haskell_library(
name = "intermediate2",
exports = [":intermediate1"],
deps = [":intermediate1"],
)

haskell_library(
name = "intermediate3",
exports = [":intermediate2"],
deps = [":intermediate2"],
)

haskell_library(
name = "intermediate4",
exports = [],
deps = [":intermediate2"],
)

haskell_library(
name = "intermediate5",
exports = [":intermediate4"],
deps = [":intermediate4"],
)

haskell_library(
Expand All @@ -30,8 +56,6 @@ haskell_library(
],
)

# Failure test for https://github.com/tweag/rules_haskell/issues/1145
# TODO Turn into regression test once that issue is resolved.
haskell_test(
name = "final",
srcs = ["Main.hs"],
Expand All @@ -47,3 +71,36 @@ test_suite(
tags = ["manual"],
tests = [":final"],
)

haskell_test(
name = "final-long",
srcs = ["Main.hs"],
tags = ["manual"],
deps = [
":intermediate3",
"//tests/hackage:base",
],
)

test_suite(
name = "long",
tags = ["manual"],
tests = [":final-long"],
)

haskell_test(
name = "final-interrupted",
srcs = ["Main.hs"],
tags = ["manual"],
deps = [
":intermediate5",
"//tests/hackage:base",
],
)

test_suite(
name = "interrupted",
tags = ["manual"],
tests = [":final-interrupted"],
)