Commit 5be6dffd authored by Ian Lynagh's avatar Ian Lynagh
Browse files

Tweaks to make Cabal play nicer with haddock

The path for the html docs now includes the package name at the end,
which works nicer for multiple packages sharing a contents/index.

Use --ghc-pkg when available (in haddock darcs only currently) to tell
haddock which ghc-pkg to use.

Use --allow-missing-html when available (in haddock darcs only
currently) to tell haddock not to worry if it can't find the HTML for
packages we depend on. This is necessary when haddocking a group of
packages before moving them all into place.
parent 1bb176b2
......@@ -70,7 +70,7 @@ import Distribution.Compiler
import Distribution.Package --must not specify imports, since we're exporting moule.
import Distribution.PackageDescription
import Distribution.Program(lookupProgram, Program(..), ProgramConfiguration(..),
haddockProgram, rawSystemProgram, defaultProgramConfiguration,
haddockProgram, ghcPkgProgram, rawSystemProgram, defaultProgramConfiguration,
pfesetupProgram, updateProgram, rawSystemProgramConf)
import Distribution.PreProcess (knownSuffixHandlers, ppSuffixes, ppCpp',
ppUnlit, removePreprocessedPackage,
......@@ -85,7 +85,8 @@ import Distribution.Simple.Register ( register, unregister,
)
import Distribution.Simple.Configure(getPersistBuildConfig, maybeGetPersistBuildConfig,
configure, writePersistBuildConfig, localBuildInfoFile)
configure, writePersistBuildConfig, localBuildInfoFile,
haddockVersion)
import Distribution.Simple.LocalBuildInfo ( LocalBuildInfo(..), distPref,
srcPref, haddockPref )
......@@ -397,7 +398,7 @@ haddock pkg_descr lbi hooks (HaddockFlags hoogle verbose) = do
let tmpDir = joinPaths (buildDir lbi) "tmp"
createDirectoryIfMissing True tmpDir
createDirectoryIfMissing True haddockPref
createDirectoryIfMissing True $ haddockPref pkg_descr
preprocessSources pkg_descr lbi verbose pps
setupMessage verbose "Running Haddock for" pkg_descr
......@@ -407,6 +408,13 @@ haddock pkg_descr lbi hooks (HaddockFlags hoogle verbose) = do
let showPkg = showPackageId (package pkg_descr)
let showDepPkgs = map showPackageId (packageDeps lbi)
let outputFlag = if hoogle then "--hoogle" else "--html"
have_new_flags <- fmap (> Version [0,8] []) (haddockVersion lbi)
let ghcpkgFlags = if have_new_flags
then ["--ghc-pkg=" ++ compilerPkgTool (compiler lbi)]
else []
let allowMissingHtmlFlags = if have_new_flags
then ["--allow-missing-html"]
else []
withLib pkg_descr () $ \lib -> do
let bi = libBuildInfo lib
......@@ -415,15 +423,18 @@ haddock pkg_descr lbi hooks (HaddockFlags hoogle verbose) = do
let prologName = showPkg ++ "-haddock-prolog.txt"
writeFile prologName (description pkg_descr ++ "\n")
let outFiles = replaceLitExts inFiles
let haddockFile = joinFileName haddockPref (haddockName pkg_descr)
let haddockFile = joinFileName (haddockPref pkg_descr)
(haddockName pkg_descr)
-- FIX: replace w/ rawSystemProgramConf?
rawSystemProgram verbose confHaddock
([outputFlag,
"--odir=" ++ haddockPref,
"--odir=" ++ haddockPref pkg_descr,
"--title=" ++ showPkg ++ ": " ++ synopsis pkg_descr,
"--package=" ++ showPkg,
"--dump-interface=" ++ haddockFile,
"--prologue=" ++ prologName]
++ ghcpkgFlags
++ allowMissingHtmlFlags
++ (if haddockUsePackages lbi
then map ("--use-package=" ++) showDepPkgs
else [])
......@@ -435,7 +446,7 @@ haddock pkg_descr lbi hooks (HaddockFlags hoogle verbose) = do
removeFile prologName
withExe pkg_descr $ \exe -> do
let bi = buildInfo exe
exeTargetDir = haddockPref `joinFileName` exeName exe
exeTargetDir = haddockPref pkg_descr `joinFileName` exeName exe
createDirectoryIfMissing True exeTargetDir
inFiles' <- getModulePaths bi (otherModules bi)
srcMainPath <- findFile (hsSourceDirs bi) (modulePath exe)
......@@ -446,6 +457,8 @@ haddock pkg_descr lbi hooks (HaddockFlags hoogle verbose) = do
([outputFlag,
"--odir=" ++ exeTargetDir,
"--title=" ++ exeName exe]
++ ghcpkgFlags
++ allowMissingHtmlFlags
++ (if haddockUsePackages lbi
then map ("--use-package=" ++) showDepPkgs
else [])
......
......@@ -90,9 +90,9 @@ install :: PackageDescription -- ^information from the .cabal file
-> IO ()
install pkg_descr lbi (CopyFlags copydest verbose) = do
let dataFilesExist = not (null (dataFiles pkg_descr))
docExists <- doesDirectoryExist haddockPref
docExists <- doesDirectoryExist $ haddockPref pkg_descr
when (verbose >= 4)
(putStrLn ("directory " ++ haddockPref ++
(putStrLn ("directory " ++ haddockPref pkg_descr ++
" does exist: " ++ show docExists))
when (dataFilesExist || docExists) $ do
let dataPref = mkDataDir pkg_descr lbi copydest
......@@ -104,7 +104,7 @@ install pkg_descr lbi (CopyFlags copydest verbose) = do
when docExists $ do
let targetDir = mkHaddockDir pkg_descr lbi copydest
createDirectoryIfMissing True targetDir
copyDirectoryRecursiveVerbose verbose haddockPref targetDir
copyDirectoryRecursiveVerbose verbose (haddockPref pkg_descr) targetDir
-- setPermissionsRecursive [Read] targetDir
let buildPref = buildDir lbi
let libPref = mkLibDir pkg_descr lbi copydest
......
......@@ -130,8 +130,9 @@ distPref = "dist"
srcPref :: FilePath
srcPref = distPref `joinFileName` "src"
haddockPref :: FilePath
haddockPref = foldl1 joinPaths [distPref, "doc", "html"]
haddockPref :: PackageDescription -> FilePath
haddockPref pkg_descr
= foldl1 joinPaths [distPref, "doc", "html", pkgName (package pkg_descr)]
-- |The directory in which we put auto-generated modules
autogenModulesDir :: LocalBuildInfo -> String
......@@ -288,7 +289,8 @@ mkDataDirRel pkg_descr lbi copydest =
mkHaddockDir :: PackageDescription -> LocalBuildInfo -> CopyDest -> FilePath
mkHaddockDir pkg_descr lbi copydest =
foldl1 joinPaths [mkDataDir pkg_descr lbi copydest, "doc", "html"]
foldl1 joinPaths [mkDataDir pkg_descr lbi copydest,
"doc", "html", pkgName (package pkg_descr)]
......
......@@ -257,6 +257,9 @@ mkInstalledPackageInfo pkg_descr lbi inplace = do
(absinc,relinc) = partition isAbsolutePath (includeDirs bi)
haddockDir = mkHaddockDir pkg_descr lbi NoCopyDest
haddockFile = joinPaths haddockDir (haddockName pkg_descr)
inplace_lbi = lbi { datadir = pwd, datasubdir = "dist" }
haddockDirInplace = mkHaddockDir pkg_descr inplace_lbi NoCopyDest
haddockFileInplace = joinPaths haddockDirInplace (haddockName pkg_descr)
in
return emptyInstalledPackageInfo{
IPI.package = package pkg_descr,
......@@ -289,7 +292,8 @@ mkInstalledPackageInfo pkg_descr lbi inplace = do
IPI.ldOptions = ldOptions bi,
IPI.frameworkDirs = [],
IPI.frameworks = frameworks bi,
IPI.haddockInterfaces = [haddockFile],
IPI.haddockInterfaces = [if inplace then haddockFileInplace
else haddockFile],
IPI.haddockHTMLs = [haddockDir]
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment