Commit 02c35c6d authored by rubbernecking.trumpet.stephen's avatar rubbernecking.trumpet.stephen
Browse files

Add *LBI variants of withLib and withExe that give corresponding build info

parent f91b8b0a
......@@ -67,7 +67,7 @@ import Distribution.Simple.Compiler
( CompilerFlavor(..), compilerFlavor )
import Distribution.PackageDescription
( PackageDescription(..), BuildInfo(..)
, Library(..), withLib, Executable(..), withExe )
, Library(..), Executable(..) )
import qualified Distribution.ModuleName as ModuleName
import Distribution.Simple.Setup
......@@ -75,8 +75,8 @@ import Distribution.Simple.Setup
import Distribution.Simple.PreProcess
( preprocessSources, PPSuffixHandler )
import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo(compiler, buildDir, libraryConfig, executableConfigs)
, ComponentLocalBuildInfo )
( LocalBuildInfo(compiler, buildDir)
, ComponentLocalBuildInfo, withLibLBI, withExeLBI )
import Distribution.Simple.BuildPaths
( autogenModulesDir, autogenModuleName, cppHeaderName )
import Distribution.Simple.Utils
......@@ -109,14 +109,12 @@ build pkg_descr lbi flags suffixes = do
initialBuildSteps distPref pkg_descr lbi verbosity suffixes
setupMessage verbosity "Building" (packageId pkg_descr)
withLib pkg_descr $ \lib -> do
withLibLBI pkg_descr lbi $ \lib clbi -> do
info verbosity "Building library..."
let Just clbi = libraryConfig lbi
buildLib verbosity pkg_descr lbi lib clbi
withExe pkg_descr $ \exe -> do
withExeLBI pkg_descr lbi $ \exe clbi -> do
info verbosity $ "Building executable " ++ exeName exe ++ "..."
let Just clbi = lookup (exeName exe) (executableConfigs lbi)
buildExe verbosity pkg_descr lbi exe clbi
buildLib :: Verbosity -> PackageDescription -> LocalBuildInfo
......
......@@ -75,7 +75,7 @@ import Distribution.Simple.InstallDirs (InstallDirs(..), PathTemplate,
initialPathTemplateEnv)
import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo(..), externalPackageDeps
, ComponentLocalBuildInfo(..) )
, ComponentLocalBuildInfo(..), withLibLBI, withExeLBI )
import Distribution.Simple.BuildPaths ( haddockName,
hscolourPref, autogenModulesDir,
)
......@@ -197,19 +197,15 @@ haddock pkg_descr lbi suffixes flags = do
[ fromFlags flags
, fromPackageDescription pkg_descr ]
withLib pkg_descr $ \lib -> do
withLibLBI pkg_descr lbi $ \lib clbi -> do
let bi = libBuildInfo lib
--TODO: need a withLib variant that gives us the per-component info
let Just clbi = libraryConfig lbi
libArgs <- fromLibrary lbi lib clbi
prepareSources verbosity lbi isVersion2 bi (args `mappend` libArgs) $
runHaddock verbosity confHaddock
when (flag haddockExecutables) $
withExe pkg_descr $ \exe -> do
withExeLBI pkg_descr lbi $ \exe clbi -> do
let bi = buildInfo exe
--TODO: need a withLib variant that gives us the per-component info
let Just clbi = lookup (exeName exe) (executableConfigs lbi)
exeArgs <- fromExecutable lbi exe clbi
prepareSources verbosity lbi isVersion2 bi (args `mappend` exeArgs) $
runHaddock verbosity confHaddock
......
......@@ -47,6 +47,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module Distribution.Simple.LocalBuildInfo (
LocalBuildInfo(..),
externalPackageDeps,
withLibLBI,
withExeLBI,
ComponentLocalBuildInfo(..),
-- * Installation directories
module Distribution.Simple.InstallDirs,
......@@ -61,7 +63,9 @@ import Distribution.Simple.InstallDirs hiding (absoluteInstallDirs,
import qualified Distribution.Simple.InstallDirs as InstallDirs
import Distribution.Simple.Setup (CopyDest(..))
import Distribution.Simple.Program (ProgramConfiguration)
import Distribution.PackageDescription (PackageDescription(..))
import Distribution.PackageDescription
( PackageDescription(..), withLib, Library, withExe
, Executable(exeName) )
import Distribution.Package (PackageId, Package(..))
import Distribution.Simple.Compiler
( Compiler(..), PackageDB, OptimisationLevel )
......@@ -122,6 +126,27 @@ externalPackageDeps lbi = nub $
maybe [] componentPackageDeps (libraryConfig lbi)
++ concatMap (componentPackageDeps . snd) (executableConfigs lbi)
-- |If the package description has a library section, call the given
-- function with the library build info as argument. Extended version of
-- 'withLib' that also gives corresponding build info.
withLibLBI :: PackageDescription -> LocalBuildInfo
-> (Library -> ComponentLocalBuildInfo -> IO ()) -> IO ()
withLibLBI pkg_descr lbi f = withLib pkg_descr $ \lib ->
case libraryConfig lbi of
Just clbi -> f lib clbi
Nothing -> error "withLibLBI: inconsistent data"
-- | Perform the action on each buildable 'Executable' in the package
-- description. Extended version of 'withExe' that also gives corresponding
-- build info.
withExeLBI :: PackageDescription -> LocalBuildInfo
-> (Executable -> ComponentLocalBuildInfo -> IO ()) -> IO ()
withExeLBI pkg_descr lbi f = withExe pkg_descr $ \exe ->
case lookup (exeName exe) (executableConfigs lbi) of
Just clbi -> f exe clbi
Nothing -> error "withExeLBI: inconsistent data"
-- -----------------------------------------------------------------------------
-- Wrappers for a couple functions from InstallDirs
......
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