From b210ba1891cf8f4bd28553a9f8452a761c3a329a Mon Sep 17 00:00:00 2001 From: Philipp Zander Date: Tue, 20 Feb 2024 19:52:05 +0100 Subject: [PATCH] use `depset` for transitive reexports in `HaskellLibraryInfo` --- haskell/cabal.bzl | 2 +- haskell/private/haskell_impl.bzl | 10 ++- haskell/providers.bzl | 4 +- rules_haskell_tests/tests/RunTests.hs | 11 ++- .../package-reexport-transitive/BUILD.bazel | 73 +++++++++++++++++-- 5 files changed, 82 insertions(+), 18 deletions(-) diff --git a/haskell/cabal.bzl b/haskell/cabal.bzl index 0cdcee1d7..01c51832b 100644 --- a/haskell/cabal.bzl +++ b/haskell/cabal.bzl @@ -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, diff --git a/haskell/private/haskell_impl.bzl b/haskell/private/haskell_impl.bzl index c242b3298..00efa619b 100644 --- a/haskell/private/haskell_impl.bzl +++ b/haskell/private/haskell_impl.bzl @@ -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 = [] @@ -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), diff --git a/haskell/providers.bzl b/haskell/providers.bzl index c8fbbc521..6311e875e 100644 --- a/haskell/providers.bzl +++ b/haskell/providers.bzl @@ -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): diff --git a/rules_haskell_tests/tests/RunTests.hs b/rules_haskell_tests/tests/RunTests.hs index 870da9b94..a8dc37793 100644 --- a/rules_haskell_tests/tests/RunTests.hs +++ b/rules_haskell_tests/tests/RunTests.hs @@ -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. @@ -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"]) diff --git a/rules_haskell_tests/tests/package-reexport-transitive/BUILD.bazel b/rules_haskell_tests/tests/package-reexport-transitive/BUILD.bazel index 43e275fd2..cf7e32b99 100644 --- a/rules_haskell_tests/tests/package-reexport-transitive/BUILD.bazel +++ b/rules_haskell_tests/tests/package-reexport-transitive/BUILD.bazel @@ -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( @@ -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"], @@ -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"], +) +