Commit 247cd70a authored by Duncan Coutts's avatar Duncan Coutts
Browse files

executables can now depend on a library in the same package.

Fixes ticket #89. The library gets registered into an inplace
package db file which is used when building the executables.
Based partly on an original patch by Stephen Blackheath.
parent db38885f
...@@ -64,21 +64,23 @@ import qualified Distribution.Simple.Build.PathsModule as Build.PathsModule ...@@ -64,21 +64,23 @@ import qualified Distribution.Simple.Build.PathsModule as Build.PathsModule
import Distribution.Package import Distribution.Package
( Package(..) ) ( Package(..) )
import Distribution.Simple.Compiler import Distribution.Simple.Compiler
( CompilerFlavor(..), compilerFlavor ) ( CompilerFlavor(..), compilerFlavor, PackageDB(..) )
import Distribution.PackageDescription import Distribution.PackageDescription
( PackageDescription(..), BuildInfo(..) ( PackageDescription(..), BuildInfo(..)
, Library(..), Executable(..) ) , Library(..), Executable(..) )
import qualified Distribution.ModuleName as ModuleName import qualified Distribution.ModuleName as ModuleName
import Distribution.Simple.Setup import Distribution.Simple.Setup
( BuildFlags(..), fromFlag ) ( BuildFlags(..), fromFlag, defaultRegisterFlags
, RegisterFlags(..), Flag(..) )
import Distribution.Simple.PreProcess import Distribution.Simple.PreProcess
( preprocessSources, PPSuffixHandler ) ( preprocessSources, PPSuffixHandler )
import Distribution.Simple.LocalBuildInfo import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo(compiler, buildDir) ( LocalBuildInfo(compiler, buildDir, withPackageDB)
, ComponentLocalBuildInfo, withLibLBI, withExeLBI ) , ComponentLocalBuildInfo, withLibLBI, withExeLBI )
import Distribution.Simple.BuildPaths import Distribution.Simple.BuildPaths
( autogenModulesDir, autogenModuleName, cppHeaderName ) ( autogenModulesDir, autogenModuleName, cppHeaderName )
import Distribution.Simple.Register ( register )
import Distribution.Simple.Utils import Distribution.Simple.Utils
( createDirectoryIfMissingVerbose, rewriteFile ( createDirectoryIfMissingVerbose, rewriteFile
, die, info, setupMessage ) , die, info, setupMessage )
...@@ -109,13 +111,35 @@ build pkg_descr lbi flags suffixes = do ...@@ -109,13 +111,35 @@ build pkg_descr lbi flags suffixes = do
initialBuildSteps distPref pkg_descr lbi verbosity suffixes initialBuildSteps distPref pkg_descr lbi verbosity suffixes
setupMessage verbosity "Building" (packageId pkg_descr) setupMessage verbosity "Building" (packageId pkg_descr)
internalPackageDB <- createInternalPackageDB distPref
withLibLBI pkg_descr lbi $ \lib clbi -> do withLibLBI pkg_descr lbi $ \lib clbi -> do
info verbosity "Building library..." info verbosity "Building library..."
buildLib verbosity pkg_descr lbi lib clbi buildLib verbosity pkg_descr lbi lib clbi
withExeLBI pkg_descr lbi $ \exe clbi -> do -- Register library in-place, so exes can depend on internally defined libraries.
--TODO: go through a proper register api, not the generic command line action
register pkg_descr lbi defaultRegisterFlags {
regPackageDB = Flag internalPackageDB,
regInPlace = Flag True,
regDistPref = Flag distPref
}
-- 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 ++ "..." info verbosity $ "Building executable " ++ exeName exe ++ "..."
buildExe verbosity pkg_descr lbi exe clbi buildExe verbosity pkg_descr lbi' exe clbi
-- | Initialize a new package db file for libraries defined
-- internally to the package.
createInternalPackageDB :: FilePath -> IO PackageDB
createInternalPackageDB distPref = do
let dbFile = distPref </> "package.conf.inplace"
packageDB = SpecificPackageDB dbFile
writeFile dbFile "[]"
return packageDB
buildLib :: Verbosity -> PackageDescription -> LocalBuildInfo buildLib :: Verbosity -> PackageDescription -> LocalBuildInfo
-> Library -> ComponentLocalBuildInfo -> IO () -> Library -> ComponentLocalBuildInfo -> IO ()
......
...@@ -371,11 +371,12 @@ configure (e_pkg_descr, pbi) cfg ...@@ -371,11 +371,12 @@ configure (e_pkg_descr, pbi) cfg
let (internalPkgDeps, externalPkgDeps) = partition (isInternalPackage pkg_descr) allPkgDeps let (internalPkgDeps, externalPkgDeps) = partition (isInternalPackage pkg_descr) allPkgDeps
when (not (null internalPkgDeps)) $ when (not (null internalPkgDeps) && not (newPackageDepsBehaviour pkg_descr)) $
die $ "The field 'build-depends: " die $ "The field 'build-depends: "
++ intercalate ", " (map (display . packageName) internalPkgDeps) ++ intercalate ", " (map (display . packageName) internalPkgDeps)
++ "' refers to a library which defined within the same " ++ "' refers to a library which defined within the same "
++ "package. This feature is not yet supported." ++ "package. To use this feature the package must specify at "
++ "least 'cabal-version: >= 1.8'."
packageDependsIndex <- packageDependsIndex <-
case PackageIndex.dependencyClosure packageSet externalPkgDeps of case PackageIndex.dependencyClosure packageSet externalPkgDeps of
......
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