@@ -42,6 +42,7 @@ import Distribution.Types.VersionInterval.Legacy
4242 -- I criticized this unfortunate development at length at:
4343 -- https://github.com/haskell/cabal/issues/7916
4444import Distribution.ModuleName as ModuleName
45+ import Distribution.Types.LibraryVisibility (LibraryVisibility (LibraryVisibilityPublic ))
4546
4647-- hackage-server
4748import Distribution.Server.Framework.CacheControl (ETag )
@@ -148,14 +149,18 @@ doPackageRender users info = PackageRender
148149 else NotBuildable
149150
150151 renderModules :: Maybe TarIndex -> [(LibraryName , ModSigIndex )]
151- renderModules docindex = flip fmap (allLibraries flatDesc) $ \ lib ->
152+ renderModules docindex = flip fmap (filter isPublicLibrary $ allLibraries flatDesc) $ \ lib ->
152153 let mod_ix = mkForest $ exposedModules lib
153154 -- Assumes that there is an HTML per reexport
154155 ++ map moduleReexportName (reexportedModules lib)
155156 ++ virtualModules (libBuildInfo lib)
156157 sig_ix = mkForest $ signatures lib
157158 mkForest = moduleForest . map (\ m -> (m, moduleHasDocs docindex m))
158159 in (libName lib, ModSigIndex { modIndex = mod_ix, sigIndex = sig_ix })
160+ where
161+ -- Only show main library or internal libraries with public visibility
162+ isPublicLibrary lib = libName lib == LMainLibName
163+ || libVisibility lib == LibraryVisibilityPublic
159164
160165 moduleHasDocs :: Maybe TarIndex -> ModuleName -> Bool
161166 moduleHasDocs Nothing = const False
@@ -189,8 +194,15 @@ doPackageRender users info = PackageRender
189194 renderComponentName name@ (CNotLibName _) = componentNameRaw name
190195
191196allCondLibs :: GenericPackageDescription -> [(LibraryName , CondTree ConfVar [Dependency ] Library )]
192- allCondLibs desc = maybeToList ((LMainLibName ,) <$> condLibrary desc)
197+ allCondLibs desc = filter (isPublicCondLib . snd ) $
198+ maybeToList ((LMainLibName ,) <$> condLibrary desc)
193199 ++ (first LSubLibName <$> condSubLibraries desc)
200+ where
201+ -- Check if a conditional library tree contains a public library
202+ -- We check the root node since visibility is a property of the library itself
203+ isPublicCondLib condTree =
204+ let lib = condTreeData condTree
205+ in libName lib == LMainLibName || libVisibility lib == LibraryVisibilityPublic
194206
195207type DependencyTree = CondTree ConfVar [Dependency ] IsBuildable
196208
0 commit comments