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

feat: Specify component types in detailed deps page #1280

Merged
merged 1 commit into from
Sep 8, 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 src/Distribution/Server/Features/Html.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ mkHtmlCandidates ServerEnv{..} utilities@HtmlUtilities{..}
dependenciesPage :: Bool -> PackageRender -> URL -> Resource.XHtml
dependenciesPage isCandidate render docURL =
Resource.XHtml $ hackagePage (pkg ++ ": dependencies") $
[h2 << heading, Pages.renderDetailedDependencies render]
[h1 << heading, Pages.renderDetailedDependencies render]
++ Pages.renderPackageFlags render docURL
where
pkg = display $ rendPkgId render
Expand Down
10 changes: 8 additions & 2 deletions src/Distribution/Server/Packages/Render.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ data ModSigIndex = ModSigIndex {
data PackageRender = PackageRender {
rendPkgId :: PackageIdentifier,
rendLibName :: LibraryName -> String,
rendComponentName :: ComponentName -> String,
rendDepends :: [Dependency],
rendExecNames :: [String],
rendLibraryDeps :: [(LibraryName, DependencyTree)],
rendExecutableDeps :: [(String, DependencyTree)],
rendExecutableDeps :: [(ComponentName, DependencyTree)],
rendLicenseName :: String,
rendLicenseFiles :: [FilePath],
rendMaintainer :: Maybe String,
Expand Down Expand Up @@ -100,8 +101,9 @@ doPackageRender users info = PackageRender
{ rendPkgId = packageId'
, rendDepends = flatDependencies genDesc
, rendLibName = renderLibName
, rendComponentName = renderComponentName
, rendExecNames = map (unUnqualComponentName . exeName) (executables flatDesc)
, rendExecutableDeps = (unUnqualComponentName *** depTree buildInfo)
, rendExecutableDeps = (CExeName *** depTree buildInfo)
`map` condExecutables genDesc
, rendLibraryDeps = second (depTree libBuildInfo) <$> allCondLibs genDesc
, rendLicenseName = prettyShow (license desc) -- maybe make this a bit more human-readable
Expand Down Expand Up @@ -182,6 +184,10 @@ doPackageRender users info = PackageRender
renderLibName (LSubLibName name) =
packageName' ++ ":" ++ unUnqualComponentName name

renderComponentName :: ComponentName -> String
renderComponentName (CLibName name) = renderLibName name
renderComponentName name@(CNotLibName _) = componentNameRaw name

allCondLibs :: GenericPackageDescription -> [(LibraryName, CondTree ConfVar [Dependency] Library)]
allCondLibs desc = maybeToList ((LMainLibName,) <$> condLibrary desc)
++ (first LSubLibName <$> condSubLibraries desc)
Expand Down
30 changes: 18 additions & 12 deletions src/Distribution/Server/Pages/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import qualified Text.XHtml.Strict
import Data.Bool (bool)
import Data.Maybe (fromMaybe, isJust, mapMaybe, catMaybes)
import Data.List (intersperse, intercalate, partition)
import Control.Arrow (second, Arrow (..))
import Control.Arrow (Arrow (..))
import System.FilePath.Posix ((</>), (<.>))

import qualified Documentation.Haddock.Markup as Haddock
Expand Down Expand Up @@ -201,11 +201,6 @@ moduleSection render mdocIndex docURL mPkgId quickNav = case renderedModules of
renderedModules :: [(LibraryName, ModSigIndex)]
renderedModules = rendModules render mdocIndex

tabulate :: [(String, Html)] -> Html
tabulate items = table ! [theclass "properties"] <<
[tr << [th << t, td << d] | (t, d) <- items]


renderDependencies :: PackageRender -> (String, Html)
renderDependencies render =
("Dependencies", summary +++ detailsLink)
Expand Down Expand Up @@ -236,12 +231,23 @@ nonbreakingSpan :: Html -> Html
nonbreakingSpan str = thespan ! [thestyle "white-space: nowrap"] << str

renderDetailedDependencies :: PackageRender -> Html
renderDetailedDependencies pkgRender =
tabulate $ map (second (fromMaybe noDeps . render)) targets
renderDetailedDependencies pkgRender
= mconcat (mapMaybe renderComponentType componentsByType)

where
targets :: [(String, DependencyTree)]
targets = (first (rendLibName pkgRender) <$> rendLibraryDeps pkgRender)
++ rendExecutableDeps pkgRender
componentsByType :: [(String, [(ComponentName, DependencyTree)])]
componentsByType =
[ ("Libraries", first CLibName <$> rendLibraryDeps pkgRender)
, ("Executables", rendExecutableDeps pkgRender)
]

renderComponentType :: (String, [(ComponentName, DependencyTree)]) -> Maybe Html
renderComponentType (_, []) = Nothing
renderComponentType (componentType, items) = Just $ mconcat
[ h2 << componentType
, flip foldMap items $ \(componentName, deptree) ->
h3 << rendComponentName pkgRender componentName +++ fromMaybe noDeps (render deptree)
]

noDeps = list [toHtml "No dependencies"]

Expand All @@ -257,7 +263,7 @@ renderDetailedDependencies pkgRender =
NotBuildable -> [strong << "buildable:" +++ " False"]

list :: [Html] -> Html
list items = thediv ! [identifier "detailed-dependencies"] << unordList items
list items = unordList items ! [identifier "detailed-dependencies"]

renderComponent :: CondBranch ConfVar [Dependency] IsBuildable
-> Maybe Html
Expand Down