Commit 2e348126 authored by intractable's avatar intractable
Browse files

intrapackage-deps-and-per-component-preprocessing

This patch adds intrapackage dependency resolution so that components
(libraries, exes, test suites) are build in the correct order.  This mean it's
now possible to have, e.g., executables that depend on other executables defined
in the same package description: the build-tools namespace has been extended
accordingly.
  
Related to this change is the refactoring of the do-it-all preprocessSources
function, formerly invoked by initialBuildSteps, into a a function
preprocessComponent that is invoked when a component is being built.  This lets
us use executables defined in a package to be used as a custom preprocessor when
building other components.
  
Finally, a number of functions now operate on values of the sum type
PackageDescription.Component rather than specifically operating on Library or
Executable and so forth.
parent bfc301cb
......@@ -59,6 +59,10 @@ module Distribution.PackageDescription (
BuildType(..),
knownBuildTypes,
-- ** Primary Components
Component(..),
compSel,
-- ** Libraries
Library(..),
emptyLibrary,
......@@ -89,6 +93,7 @@ module Distribution.PackageDescription (
BuildInfo(..),
emptyBuildInfo,
allBuildInfo,
allComponentsBy,
allLanguages,
allExtensions,
usedExtensions,
......@@ -600,21 +605,45 @@ instance Monoid BuildInfo where
emptyBuildInfo :: BuildInfo
emptyBuildInfo = mempty
-- | The 'BuildInfo' for the library (if there is one and it's buildable) and
-- all the buildable executables. Useful for gathering dependencies.
-- | The 'BuildInfo' for the library (if there is one and it's buildable), and
-- all buildable executables and test suites. Useful for gathering dependencies.
allBuildInfo :: PackageDescription -> [BuildInfo]
allBuildInfo pkg_descr = [ bi | Just lib <- [library pkg_descr]
, let bi = libBuildInfo lib
, buildable bi ]
++ [ bi | exe <- executables pkg_descr
, let bi = buildInfo exe
, buildable bi ]
++ [ bi | tst <- testSuites pkg_descr
, let bi = testBuildInfo tst
, buildable bi ]
allBuildInfo = flip allComponentsBy
$ compSel libBuildInfo buildInfo testBuildInfo
--FIXME: many of the places where this is used, we actually want to look at
-- unbuildable bits too, probably need separate functions
data Component = CLib Library
| CExe Executable
| CTst TestSuite
deriving (Show, Eq, Read)
compSel :: (Library -> a)
-> (Executable -> a)
-> (TestSuite -> a)
-> Component
-> a
compSel f _ _ (CLib l) = f l
compSel _ f _ (CExe e) = f e
compSel _ _ f (CTst t) = f t
-- | Obtains all components (libs, exes, or test suites), transformed by the
-- given function. Useful for gathering dependencies with component context.
allComponentsBy :: PackageDescription
-> (Component -> a)
-> [a]
allComponentsBy pkg_descr f = [ f (CLib l) | Just l <- [library pkg_descr]
, buildable (libBuildInfo l)
]
++
[ f (CExe e) | e <- executables pkg_descr
, buildable (buildInfo e)
]
++
[ f (CTst t) | t <- testSuites pkg_descr
, buildable (testBuildInfo t)
]
-- | The 'Language's used by this component
--
allLanguages :: BuildInfo -> [Language]
......
......@@ -69,18 +69,18 @@ import Distribution.Simple.Compiler
( CompilerFlavor(..), compilerFlavor, PackageDB(..) )
import Distribution.PackageDescription
( PackageDescription(..), BuildInfo(..), Library(..), Executable(..)
, TestSuite(..), TestSuiteInterface(..) )
, TestSuite(..), TestSuiteInterface(..), Component(..) )
import qualified Distribution.InstalledPackageInfo as IPI
import qualified Distribution.ModuleName as ModuleName
import Distribution.Simple.Setup
( BuildFlags(..), fromFlag )
import Distribution.Simple.PreProcess
( preprocessSources, PPSuffixHandler )
( preprocessComponent, PPSuffixHandler )
import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo(compiler, buildDir, withPackageDB)
, ComponentLocalBuildInfo(..), withLibLBI, withExeLBI
, inplacePackageId, withTestLBI )
, ComponentLocalBuildInfo(..), withComponentsLBI
, inplacePackageId )
import Distribution.Simple.BuildPaths
( autogenModulesDir, autogenModuleName, cppHeaderName )
import Distribution.Simple.Register
......@@ -107,100 +107,102 @@ import System.Directory
-- -----------------------------------------------------------------------------
-- |Build the libraries and executables in this package.
build :: PackageDescription -- ^mostly information from the .cabal file
-> LocalBuildInfo -- ^Configuration information
-> BuildFlags -- ^Flags that the user passed to build
-> [ PPSuffixHandler ] -- ^preprocessors to run before compiling
build :: PackageDescription -- ^ Mostly information from the .cabal file
-> LocalBuildInfo -- ^ Configuration information
-> BuildFlags -- ^ Flags that the user passed to build
-> [ PPSuffixHandler ] -- ^ preprocessors to run before compiling
-> IO ()
build pkg_descr lbi flags suffixes = do
let distPref = fromFlag (buildDistPref flags)
verbosity = fromFlag (buildVerbosity flags)
initialBuildSteps distPref pkg_descr lbi verbosity suffixes
initialBuildSteps distPref pkg_descr lbi verbosity
setupMessage verbosity "Building" (packageId pkg_descr)
internalPackageDB <- createInternalPackageDB distPref
withLibLBI pkg_descr lbi $ \lib clbi -> do
info verbosity "Building library..."
buildLib verbosity pkg_descr lbi lib clbi
-- Register the library in-place, so exes can depend
-- on internally defined libraries.
pwd <- getCurrentDirectory
let installedPkgInfo =
(inplaceInstalledPackageInfo pwd distPref pkg_descr lib lbi clbi) {
-- The inplace registration uses the "-inplace" suffix,
-- not an ABI hash.
IPI.installedPackageId = inplacePackageId (packageId installedPkgInfo)
}
registerPackage verbosity
installedPkgInfo pkg_descr lbi True -- True meaning inplace
(withPackageDB lbi ++ [internalPackageDB])
-- Use the internal package db for the exes.
let lbi' = lbi { withPackageDB = withPackageDB lbi ++ [internalPackageDB] }
withExeLBI pkg_descr lbi' $ \exe clbi -> do
info verbosity $ "Building executable " ++ exeName exe ++ "..."
buildExe verbosity pkg_descr lbi' exe clbi
withTestLBI pkg_descr lbi' $ \test clbi ->
case testInterface test of
TestSuiteExeV10 _ f -> do
let exe = Executable
{ exeName = testName test
, modulePath = f
, buildInfo = testBuildInfo test
}
info verbosity $ "Building test suite " ++ testName test ++ "..."
buildExe verbosity pkg_descr lbi' exe clbi
TestSuiteLibV09 _ m -> do
pwd <- getCurrentDirectory
let lib = Library
{ exposedModules = [ m ]
, libExposed = True
, libBuildInfo = testBuildInfo test
}
pkg = pkg_descr
{ package = (package pkg_descr)
{ pkgName = PackageName $ testName test
let pre c = preprocessComponent pkg_descr c lbi False verbosity suffixes
lbi' = lbi {withPackageDB = withPackageDB lbi ++ [internalPackageDB]}
-- Use the internal package DB for the exes.
withComponentsLBI lbi $ \comp clbi -> do
pre comp
case comp of
CLib lib -> do
info verbosity "Building library..."
buildLib verbosity pkg_descr lbi lib clbi
-- Register the library in-place, so exes can depend
-- on internally defined libraries.
pwd <- getCurrentDirectory
let installedPkgInfo =
(inplaceInstalledPackageInfo pwd distPref pkg_descr lib lbi clbi) {
-- The inplace registration uses the "-inplace" suffix,
-- not an ABI hash.
IPI.installedPackageId = inplacePackageId (packageId installedPkgInfo)
}
registerPackage verbosity
installedPkgInfo pkg_descr lbi True -- True meaning inplace
(withPackageDB lbi ++ [internalPackageDB])
CExe exe -> do
info verbosity $ "Building executable " ++ exeName exe ++ "..."
buildExe verbosity pkg_descr lbi' exe clbi
CTst test -> do
case testInterface test of
TestSuiteExeV10 _ f -> do
let exe = Executable
{ exeName = testName test
, modulePath = f
, buildInfo = testBuildInfo test
}
, buildDepends = targetBuildDepends $ testBuildInfo test
, executables = []
, testSuites = []
, library = Just lib
}
ipi = (inplaceInstalledPackageInfo
pwd distPref pkg lib lbi clbi)
{ IPI.installedPackageId = inplacePackageId $ packageId ipi
}
testDir = buildDir lbi' </> stubName test
</> stubName test ++ "-tmp"
testLibDep = thisPackageVersion $ package pkg
exe = Executable
{ exeName = stubName test
, modulePath = stubFilePath test
, buildInfo = (testBuildInfo test)
{ hsSourceDirs = [ testDir ]
, targetBuildDepends = testLibDep
: (targetBuildDepends $ testBuildInfo test)
info verbosity $ "Building test suite " ++ testName test ++ "..."
buildExe verbosity pkg_descr lbi' exe clbi
TestSuiteLibV09 _ m -> do
pwd <- getCurrentDirectory
let lib = Library
{ exposedModules = [ m ]
, libExposed = True
, libBuildInfo = testBuildInfo test
}
}
-- | The stub executable needs a new 'ComponentLocalBuildInfo'
-- that exposes the relevant test suite library.
exeClbi = clbi
{ componentPackageDeps =
(IPI.installedPackageId ipi, packageId ipi)
: (filter (\(_, x) -> let PackageName name = pkgName x in name == "Cabal" || name == "base")
$ componentPackageDeps clbi)
}
info verbosity $ "Building test suite " ++ testName test ++ "..."
buildLib verbosity pkg lbi' lib clbi
registerPackage verbosity ipi pkg lbi' True $ withPackageDB lbi'
buildExe verbosity pkg_descr lbi' exe exeClbi
TestSuiteUnsupported tt -> die $ "No support for building test suite "
++ "type " ++ display tt
pkg = pkg_descr
{ package = (package pkg_descr)
{ pkgName = PackageName $ testName test
}
, buildDepends = targetBuildDepends $ testBuildInfo test
, executables = []
, testSuites = []
, library = Just lib
}
ipi = (inplaceInstalledPackageInfo
pwd distPref pkg lib lbi clbi)
{ IPI.installedPackageId = inplacePackageId $ packageId ipi
}
testDir = buildDir lbi' </> stubName test
</> stubName test ++ "-tmp"
testLibDep = thisPackageVersion $ package pkg
exe = Executable
{ exeName = stubName test
, modulePath = stubFilePath test
, buildInfo = (testBuildInfo test)
{ hsSourceDirs = [ testDir ]
, targetBuildDepends = testLibDep
: (targetBuildDepends $ testBuildInfo test)
}
}
-- | The stub executable needs a new 'ComponentLocalBuildInfo'
-- that exposes the relevant test suite library.
exeClbi = clbi
{ componentPackageDeps =
(IPI.installedPackageId ipi, packageId ipi)
: (filter (\(_, x) -> let PackageName name = pkgName x in name == "Cabal" || name == "base")
$ componentPackageDeps clbi)
}
info verbosity $ "Building test suite " ++ testName test ++ "..."
buildLib verbosity pkg lbi' lib clbi
registerPackage verbosity ipi pkg lbi' True $ withPackageDB lbi'
buildExe verbosity pkg_descr lbi' exe exeClbi
TestSuiteUnsupported tt -> die $ "No support for building test suite "
++ "type " ++ display tt
-- | Initialize a new package db file for libraries defined
-- internally to the package.
......@@ -241,9 +243,8 @@ initialBuildSteps :: FilePath -- ^"dist" prefix
-> PackageDescription -- ^mostly information from the .cabal file
-> LocalBuildInfo -- ^Configuration information
-> Verbosity -- ^The verbosity to use
-> [ PPSuffixHandler ] -- ^preprocessors to run before compiling
-> IO ()
initialBuildSteps _distPref pkg_descr lbi verbosity suffixes = do
initialBuildSteps _distPref pkg_descr lbi verbosity = do
-- check that there's something to build
let buildInfos =
map libBuildInfo (maybeToList (library pkg_descr)) ++
......@@ -256,8 +257,6 @@ initialBuildSteps _distPref pkg_descr lbi verbosity suffixes = do
writeAutogenFiles verbosity pkg_descr lbi
preprocessSources pkg_descr lbi False verbosity suffixes
-- | Generate and write out the Paths_<pkg>.hs and cabal_macros.h files
--
writeAutogenFiles :: Verbosity
......
......@@ -14,7 +14,7 @@
-- tools are available (including version checks if appropriate); checks for
-- any required @pkg-config@ packages (updating the 'BuildInfo' with the
-- results)
--
--
-- Then based on all this it saves the info in the 'LocalBuildInfo' and writes
-- it out to the @dist\/setup-config@ file. It also displays various details to
-- the user, the amount of information displayed depending on the verbosity
......@@ -69,7 +69,7 @@ import Distribution.Simple.Compiler
, showCompilerId, unsupportedLanguages, unsupportedExtensions
, PackageDB(..), PackageDBStack )
import Distribution.Package
( PackageName(PackageName), PackageIdentifier(PackageIdentifier), PackageId
( PackageName(PackageName), PackageIdentifier(..), PackageId
, packageName, packageVersion, Package(..)
, Dependency(Dependency), simplifyDependency
, InstalledPackageId(..) )
......@@ -82,7 +82,8 @@ import Distribution.PackageDescription as PD
( PackageDescription(..), specVersion, GenericPackageDescription(..)
, Library(..), hasLibs, Executable(..), BuildInfo(..), allExtensions
, HookedBuildInfo, updatePackageDescription, allBuildInfo
, FlagName(..), TestSuite(..) )
, FlagName(..), TestSuite(..)
, allComponentsBy, Component(..), compSel )
import Distribution.PackageDescription.Configuration
( finalizePackageDescription, mapTreeData )
import Distribution.PackageDescription.Check
......@@ -107,7 +108,7 @@ import Distribution.Simple.BuildPaths
import Distribution.Simple.Utils
( die, warn, info, setupMessage, createDirectoryIfMissingVerbose
, intercalate, cabalVersion
, withFileContents, writeFileAtomic
, withFileContents, writeFileAtomic
, withTempFile )
import Distribution.System
( OS(..), buildOS, buildPlatform )
......@@ -124,13 +125,15 @@ import qualified Distribution.Simple.Hugs as Hugs
import qualified Distribution.Simple.UHC as UHC
import Control.Monad
( when, unless, foldM, filterM )
( when, unless, foldM, filterM, forM )
import Data.List
( nub, partition, isPrefixOf, inits )
( nub, partition, isPrefixOf, inits, find )
import Data.Maybe
( isNothing, catMaybes )
( isNothing, catMaybes, mapMaybe )
import Data.Monoid
( Monoid(..) )
import Data.Graph
( SCC(..), graphFromEdges, transposeG, vertices, stronglyConnCompR )
import System.Directory
( doesFileExist, getModificationTime, createDirectoryIfMissing, getTemporaryDirectory )
import System.Exit
......@@ -437,7 +440,7 @@ configure (pkg_descr0, pbi) cfg
programsConfig''' <-
configureAllKnownPrograms (lessVerbose verbosity) programsConfig''
>>= configureRequiredPrograms verbosity requiredBuildTools
>>= configureRequiredPrograms verbosity requiredBuildTools
(pkg_descr', programsConfig'''') <-
configurePkgconfigPackages verbosity pkg_descr programsConfig'''
......@@ -458,7 +461,7 @@ configure (pkg_descr0, pbi) cfg
-- needs. Note, this only works because we cannot yet depend on two
-- versions of the same package.
let configLib lib = configComponent (libBuildInfo lib)
configExe exe = (exeName exe, configComponent(buildInfo exe))
configExe exe = (exeName exe, configComponent (buildInfo exe))
configTest test = (testName test,
configComponent(testBuildInfo test))
configComponent bi = ComponentLocalBuildInfo {
......@@ -477,20 +480,49 @@ configure (pkg_descr0, pbi) cfg
where
names = [ name | Dependency name _ <- targetBuildDepends bi ]
let lbi = LocalBuildInfo{
-- Obtains the intrapackage dependencies for the given component
let ipDeps component =
mapMaybe exeDepToComp (buildTools bi)
++ mapMaybe libDepToComp (targetBuildDepends bi)
where
bi = compSel libBuildInfo buildInfo testBuildInfo $ component
exeDepToComp (Dependency (PackageName name) _) =
CExe `fmap` find ((==) name . exeName)
(executables pkg_descr')
libDepToComp (Dependency pn _)
| pn `elem` map packageName internalPkgDeps =
CLib `fmap` library pkg_descr'
libDepToComp _ = Nothing
let sccs = (stronglyConnCompR . map lkup . vertices . transposeG) g
where (g, lkup, _) = graphFromEdges
$ allComponentsBy pkg_descr'
$ \c -> (c, key c, map key (ipDeps c))
key = compSel (const "library") exeName testName
-- check for cycles in the dependency graph
buildOrder <- forM sccs $ \scc -> case scc of
AcyclicSCC (c,_,_) -> return c
CyclicSCC vs ->
die $ "Found cycle in intrapackage dependency graph:\n "
++ intercalate " depends on "
(map (\(_,k,_) -> "'" ++ k ++ "'") (vs ++ [head vs]))
let lbi = LocalBuildInfo {
configFlags = cfg,
extraConfigArgs = [], -- Currently configure does not
-- take extra args, but if it
-- did they would go here.
installDirTemplates = installDirs,
compiler = comp,
buildDir = buildDir',
buildDir = buildDir',
scratchDir = fromFlagOrDefault
(distPref </> "scratch")
(configScratchDir cfg),
libraryConfig = configLib `fmap` library pkg_descr',
executableConfigs = configExe `fmap` executables pkg_descr',
testSuiteConfigs = configTest `fmap` filter testEnabled (testSuites pkg_descr'),
compBuildOrder = buildOrder,
installedPkgs = packageDependsIndex,
pkgDescrFile = Nothing,
localPkgDescr = pkg_descr',
......@@ -543,9 +575,9 @@ configure (pkg_descr0, pbi) cfg
addInternalExe bd exe =
let nm = exeName exe in
addKnownProgram Program {
programName = nm,
programName = nm,
programFindLocation = \_ -> return $ Just $ bd </> nm </> nm,
programFindVersion = \_ _ -> return Nothing,
programFindVersion = \_ _ -> return Nothing,
programPostConf = \_ _ -> return []
}
......
......@@ -56,8 +56,7 @@ import Distribution.Package
import qualified Distribution.ModuleName as ModuleName
import Distribution.PackageDescription as PD
( PackageDescription(..), BuildInfo(..), allExtensions
, Library(..), hasLibs, withLib
, Executable(..), withExe )
, Library(..), hasLibs, Executable(..), Component(..) )
import Distribution.Simple.Compiler
( Compiler(..), compilerVersion )
import Distribution.Simple.GHC ( ghcLibDir )
......@@ -65,8 +64,9 @@ import Distribution.Simple.Program
( ConfiguredProgram(..), requireProgramVersion
, rawSystemProgram, rawSystemProgramStdout
, hscolourProgram, haddockProgram )
import Distribution.Simple.PreProcess (ppCpp', ppUnlit,
PPSuffixHandler, runSimplePreProcessor)
import Distribution.Simple.PreProcess (ppCpp', ppUnlit
, PPSuffixHandler, runSimplePreProcessor
, preprocessComponent)
import Distribution.Simple.Setup
( defaultHscolourFlags, Flag(..), flagToMaybe, fromFlag
, HaddockFlags(..), HscolourFlags(..) )
......@@ -78,7 +78,7 @@ import Distribution.Simple.InstallDirs (InstallDirs(..), PathTemplate,
initialPathTemplateEnv)
import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo(..), externalPackageDeps
, ComponentLocalBuildInfo(..), withLibLBI, withExeLBI )
, ComponentLocalBuildInfo(..), withComponentsLBI )
import Distribution.Simple.BuildPaths ( haddockName,
hscolourPref, autogenModulesDir,
)
......@@ -112,7 +112,7 @@ import System.FilePath((</>), (<.>), splitFileName, splitExtension,
import System.IO (hClose, hPutStrLn)
import Distribution.Version
-- Types
-- Types
-- | record that represents the arguments to the haddock executable, a product monoid.
data HaddockArgs = HaddockArgs {
......@@ -122,7 +122,7 @@ data HaddockArgs = HaddockArgs {
argIgnoreExports :: Any, -- ^ ingore export lists in modules?
argLinkSource :: Flag (Template,Template), -- ^ (template for modules, template for symbols)
argCssFile :: Flag FilePath, -- ^ optinal custom css file.
argVerbose :: Any,
argVerbose :: Any,
argOutput :: Flag [Output], -- ^ Html or Hoogle doc or both? required.
argInterfaces :: [(FilePath, Maybe FilePath)], -- ^ [(interface file, path to the html docs for links)]
argOutputDir :: Directory, -- ^ where to generate the documentation.
......@@ -164,7 +164,7 @@ haddock pkg_descr lbi suffixes flags = do
-- various sanity checks
let isVersion2 = version >= Version [2,0] []
when ( flag haddockHoogle
when ( flag haddockHoogle
&& version > Version [2] []
&& version < Version [2,2] []) $
die "haddock 2.0 and 2.1 do not support the --hoogle flag."
......@@ -188,35 +188,37 @@ haddock pkg_descr lbi suffixes flags = do
-- the tools match the requests, we can proceed
initialBuildSteps (flag haddockDistPref) pkg_descr lbi verbosity suffixes
when (flag haddockHscolour) $ hscolour' pkg_descr lbi $
initialBuildSteps (flag haddockDistPref) pkg_descr lbi verbosity
when (flag haddockHscolour) $ hscolour' pkg_descr lbi suffixes $
defaultHscolourFlags `mappend` haddockToHscolour flags
args <- fmap mconcat . sequence $
[ getInterfaces verbosity lbi (flagToMaybe (haddockHtmlLocation flags))
, getGhcLibDir verbosity lbi isVersion2 ]
++ map return
args <- fmap mconcat . sequence $
[ getInterfaces verbosity lbi (flagToMaybe (haddockHtmlLocation flags))
, getGhcLibDir verbosity lbi isVersion2 ]
++ map return
[ fromFlags flags
, fromPackageDescription pkg_descr ]
withLibLBI pkg_descr lbi $ \lib clbi ->
withTempDirectory verbosity (buildDir lbi) "tmp" $ \tmp -> do
let bi = libBuildInfo lib
libArgs <- fromLibrary tmp lbi lib clbi
libArgs' <- prepareSources verbosity tmp
lbi isVersion2 bi (args `mappend` libArgs)
runHaddock verbosity confHaddock libArgs'
when (flag haddockExecutables) $
withExeLBI pkg_descr lbi $ \exe clbi ->
withTempDirectory verbosity (buildDir lbi) "tmp" $ \tmp -> do
let bi = buildInfo exe
exeArgs <- fromExecutable tmp lbi exe clbi
exeArgs' <- prepareSources verbosity tmp
lbi isVersion2 bi (args `mappend` exeArgs)
runHaddock verbosity confHaddock exeArgs'
let pre c = preprocessComponent pkg_descr c lbi False verbosity suffixes
withComponentsLBI lbi $ \comp clbi -> do
pre comp
case comp of
CLib lib -> do
withTempDirectory verbosity (buildDir lbi) "tmp" $ \tmp -> do
let bi = libBuildInfo lib
libArgs <- fromLibrary tmp lbi lib clbi
libArgs' <- prepareSources verbosity tmp
lbi isVersion2 bi (args `mappend` libArgs)
runHaddock verbosity confHaddock libArgs'
CExe exe -> when (flag haddockExecutables) $ do
withTempDirectory verbosity (buildDir lbi) "tmp" $ \tmp -> do
let bi = buildInfo exe
exeArgs <- fromExecutable tmp lbi exe clbi
exeArgs' <- prepareSources verbosity tmp
lbi isVersion2 bi (args `mappend` exeArgs)
runHaddock verbosity confHaddock exeArgs'
_ -> return ()
where
verbosity = flag haddockVerbosity
flag f = fromFlag $ f flags
......@@ -233,13 +235,13 @@ prepareSources :: Verbosity
prepareSources verbosity tmp lbi isVersion2 bi args@HaddockArgs{argTargets=files} =
mapM (mockPP tmp) files >>= \targets -> return args {argTargets=targets}
where
mockPP pref file = do
mockPP pref file = do
let (filePref, fileName) = splitFileName file
targetDir = pref </> filePref
targetFile = targetDir </> fileName
(targetFileNoext, targetFileExt) = splitExtension $ targetFile
hsFile = targetFileNoext <.> "hs"
assert (targetFileExt `elem` [".lhs",".hs"]) $ return ()
createDirectoryIfMissing True targetDir
......@@ -264,7 +266,7 @@ prepareSources verbosity tmp lbi isVersion2 bi args@HaddockArgs{argTargets=files
-- constributions to HaddockArgs
fromFlags :: HaddockFlags -> HaddockArgs
fromFlags flags =
fromFlags flags =
mempty {
argHideModules = (maybe mempty (All . not) $ flagToMaybe (haddockInternal flags), mempty),
argLinkSource = if fromFlag (haddockHscolour flags)
......@@ -282,15 +284,15 @@ fromFlags flags =
}
fromPackageDescription :: PackageDescription -> HaddockArgs
fromPackageDescription pkg_descr =
fromPackageDescription pkg_descr =
mempty {
argInterfaceFile = Flag $ haddockName pkg_descr,
argPackageName = Flag $ packageId $ pkg_descr,
argInterfaceFile = Flag $ haddockName pkg_descr,
argPackageName = Flag $ packageId $ pkg_descr,
argOutputDir = Dir $ "doc" </> "html" </> display (packageName pkg_descr),
argPrologue = Flag $ if null desc then synopsis pkg_descr else desc,
argTitle = Flag $ showPkg ++ subtitle
}
where
where
desc = PD.description pkg_descr
showPkg = display (packageId pkg_descr)
subtitle | null (synopsis pkg_descr) = ""
......@@ -310,11 +312,11 @@ fromLibrary tmp lbi lib clbi =
-- haddock to write them elsewhere.
++ [ "-odir", tmp, "-hidir", tmp
, "-stubdir", tmp ],
argTargets = inFiles
argTargets = inFiles