Skip to content

Commit

Permalink
Merge pull request #9821 from haskell/coot/haddock-project-sublibs
Browse files Browse the repository at this point in the history
haddock-project support public sublibraries
  • Loading branch information
coot committed Jun 30, 2024
2 parents e7657ad + b118edb commit 8466a8f
Show file tree
Hide file tree
Showing 45 changed files with 626 additions and 185 deletions.
118 changes: 115 additions & 3 deletions Cabal/src/Distribution/Simple/BuildPaths.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@ module Distribution.Simple.BuildPaths
, srcPref
, buildInfoPref
, haddockDirName
, haddockLibraryDirPath
, haddockTestDirPath
, haddockBenchmarkDirPath
, hscolourPref
, haddockPref
, autogenPackageModulesDir
, autogenComponentModulesDir
, autogenPathsModuleName
, autogenPackageInfoModuleName
, cppHeaderName
, haddockName
, haddockPath
, haddockPackageLibraryName
, haddockPackageLibraryName'
, haddockLibraryName
, haddockLibraryPath
, mkGenericStaticLibName
, mkLibName
, mkProfLibName
Expand All @@ -44,6 +51,8 @@ module Distribution.Simple.BuildPaths
, getSourceFiles
, getLibSourceFiles
, getExeSourceFiles
, getTestSourceFiles
, getBenchmarkSourceFiles
, getFLibSourceFiles
, exeBuildDir
, flibBuildDir
Expand Down Expand Up @@ -92,10 +101,44 @@ buildInfoPref distPref = distPref </> makeRelativePathEx "build-info.json"

-- | This is the name of the directory in which the generated haddocks
-- should be stored. It does not include the @<dist>/doc/html@ prefix.
--
-- It is also used by `haddock-project` when constructing its output directory.
haddockDirName :: HaddockTarget -> PackageDescription -> FilePath
haddockDirName ForDevelopment = prettyShow . packageName
haddockDirName ForHackage = (++ "-docs") . prettyShow . packageId

-- | This is the name of the directory in which the generated haddocks for
-- a (sub)library should be stored. It does not include the @<dist>/doc/html@
-- prefix.
--
-- It is also used by `haddock-project` when constructing its output directory.
haddockLibraryDirPath
:: HaddockTarget
-> PackageDescription
-> Library
-> FilePath
haddockLibraryDirPath haddockTarget pkg_descr lib =
case libName lib of
LSubLibName sublib_name ->
haddockDirName haddockTarget pkg_descr </> prettyShow sublib_name
_ -> haddockDirName haddockTarget pkg_descr

haddockTestDirPath
:: HaddockTarget
-> PackageDescription
-> TestSuite
-> FilePath
haddockTestDirPath haddockTarget pkg_descr test =
haddockDirName haddockTarget pkg_descr </> prettyShow (testName test)

haddockBenchmarkDirPath
:: HaddockTarget
-> PackageDescription
-> Benchmark
-> FilePath
haddockBenchmarkDirPath haddockTarget pkg_descr bench =
haddockDirName haddockTarget pkg_descr </> prettyShow (benchmarkName bench)

-- | The directory to which generated haddock documentation should be written.
haddockPref
:: HaddockTarget
Expand Down Expand Up @@ -139,8 +182,35 @@ autogenPackageInfoModuleName pkg_descr =
fixchar '-' = '_'
fixchar c = c

haddockName :: PackageDescription -> FilePath
haddockName pkg_descr = prettyShow (packageName pkg_descr) <.> "haddock"
haddockPath :: PackageDescription -> FilePath
haddockPath pkg_descr = prettyShow (packageName pkg_descr) <.> "haddock"

-- | A name of a (sub)library used by haddock, in the form
-- `<package>:<library>` if it is a sublibrary, or `<package>` if it is the
-- main library.
--
-- Used by `haddock-project` and `Distribution.Simple.Haddock`.
haddockPackageLibraryName :: PackageDescription -> Library -> String
haddockPackageLibraryName pkg_descr lib =
haddockPackageLibraryName' (packageName pkg_descr) (libName lib)

haddockPackageLibraryName' :: PackageName -> LibraryName -> String
haddockPackageLibraryName' pkg_name lib_name =
case lib_name of
LSubLibName sublib_name ->
prettyShow pkg_name ++ ":" ++ prettyShow sublib_name
LMainLibName -> prettyShow pkg_name

-- | A name of a (sub)library used by haddock.
haddockLibraryName :: PackageDescription -> Library -> String
haddockLibraryName pkg_descr lib =
case libName lib of
LSubLibName sublib_name -> prettyShow sublib_name
LMainLibName -> prettyShow (packageName pkg_descr)

-- | File path of the ".haddock" file.
haddockLibraryPath :: PackageDescription -> Library -> FilePath
haddockLibraryPath pkg_descr lib = haddockLibraryName pkg_descr lib <.> "haddock"

-- -----------------------------------------------------------------------------
-- Source File helper
Expand Down Expand Up @@ -184,6 +254,48 @@ getExeSourceFiles verbosity lbi exe clbi = do
: coerceSymbolicPath (exeBuildDir lbi exe)
: hsSourceDirs bi

getTestSourceFiles
:: Verbosity
-> LocalBuildInfo
-> TestSuite
-> ComponentLocalBuildInfo
-> IO [(ModuleName.ModuleName, SymbolicPath Pkg 'File)]
getTestSourceFiles verbosity lbi test@TestSuite{testInterface = TestSuiteExeV10 _ path} clbi = do
moduleFiles <- getSourceFiles verbosity mbWorkDir searchpaths modules
srcMainPath <- findFileCwd verbosity mbWorkDir (hsSourceDirs bi) path
return ((ModuleName.main, srcMainPath) : moduleFiles)
where
mbWorkDir = mbWorkDirLBI lbi
bi = testBuildInfo test
modules = otherModules bi
searchpaths =
autogenComponentModulesDir lbi clbi
: autogenPackageModulesDir lbi
: coerceSymbolicPath (testBuildDir lbi test)
: hsSourceDirs bi
getTestSourceFiles _ _ _ _ = return []

getBenchmarkSourceFiles
:: Verbosity
-> LocalBuildInfo
-> Benchmark
-> ComponentLocalBuildInfo
-> IO [(ModuleName.ModuleName, SymbolicPath Pkg 'File)]
getBenchmarkSourceFiles verbosity lbi bench@Benchmark{benchmarkInterface = BenchmarkExeV10 _ path} clbi = do
moduleFiles <- getSourceFiles verbosity mbWorkDir searchpaths modules
srcMainPath <- findFileCwd verbosity mbWorkDir (hsSourceDirs bi) path
return ((ModuleName.main, srcMainPath) : moduleFiles)
where
mbWorkDir = mbWorkDirLBI lbi
bi = benchmarkBuildInfo bench
modules = otherModules bi
searchpaths =
autogenComponentModulesDir lbi clbi
: autogenPackageModulesDir lbi
: coerceSymbolicPath (benchmarkBuildDir lbi bench)
: hsSourceDirs bi
getBenchmarkSourceFiles _ _ _ _ = return []

getFLibSourceFiles
:: Verbosity
-> LocalBuildInfo
Expand Down
Loading

0 comments on commit 8466a8f

Please sign in to comment.