Commit 7f9ad6bc authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Stop converting between installed package id and source package id

In the LocalBuildInfo, for each component, for the list of component
dependencies, keep both the InstalledPackageId and the PackageId.
That way we don't need to keep converting the InstalledPackageId
to the PackageId, via the package index (which is just horrible).
parent dd4a4152
......@@ -21,13 +21,13 @@ module Distribution.Simple.Build.Macros (
) where
import Distribution.Package
( PackageIdentifier(PackageIdentifier), packageId )
( PackageIdentifier(PackageIdentifier) )
import Distribution.Version
( Version(versionBranch) )
import Distribution.PackageDescription
( PackageDescription )
import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo, externalPackageDeps, getLocalPackageInfo )
( LocalBuildInfo, externalPackageDeps )
import Distribution.Text
( display )
......@@ -46,9 +46,7 @@ generate _pkg_descr lbi = concat $
," (major1) == ",major1," && (major2) == ",major2," && (minor) <= ",minor
,"\n\n"
]
| pkgid@(PackageIdentifier name version) <-
--TODO: too many conversions from InstalledPackageId to source PackageId
map (packageId . getLocalPackageInfo lbi) $ externalPackageDeps lbi
| (_, pkgid@(PackageIdentifier name version)) <- externalPackageDeps lbi
, let (major1:major2:minor:_) = map show (versionBranch version ++ repeat 0)
pkgname = map fixchar (display name)
]
......
......@@ -456,13 +456,13 @@ configure (pkg_descr0, pbi) cfg
let configLib lib = configComponent (libBuildInfo lib)
configExe exe = (exeName exe, configComponent(buildInfo exe))
configComponent bi = ComponentLocalBuildInfo {
componentInstalledPackageDeps =
componentPackageDeps =
if newPackageDepsBehaviour pkg_descr'
then [ installedPackageId pkg
then [ (installedPackageId pkg, packageId pkg)
| pkg <- selectSubset bi externalPkgDeps ]
++ [ InstalledPackageId (display pkgid)
++ [ (InstalledPackageId (display pkgid), pkgid)
| pkgid <- selectSubset bi internalPkgDeps ]
else [ installedPackageId pkg
else [ (installedPackageId pkg, packageId pkg)
| pkg <- externalPkgDeps ]
}
selectSubset :: Package pkg => BuildInfo -> [pkg] -> [pkg]
......
......@@ -80,11 +80,10 @@ import Distribution.InstalledPackageInfo
( InstalledPackageInfo )
import qualified Distribution.InstalledPackageInfo as InstalledPackageInfo
( InstalledPackageInfo_(..) )
import Distribution.Simple.PackageIndex
import Distribution.Simple.PackageIndex (PackageIndex)
import qualified Distribution.Simple.PackageIndex as PackageIndex
import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo(..), ComponentLocalBuildInfo(..),
componentPackageDeps )
( LocalBuildInfo(..), ComponentLocalBuildInfo(..) )
import Distribution.Simple.InstallDirs
import Distribution.Simple.BuildPaths
import Distribution.Simple.Utils
......@@ -576,11 +575,7 @@ buildLib verbosity pkg_descr lbi lib clbi = do
"-o", sharedLibFilePath ]
++ dynamicObjectFiles
++ ["-package-name", display pkgid ]
++ concat (if compilerVersion comp >= Version [6,11] []
then [ ["-package-id", display ipid]
| ipid <- componentInstalledPackageDeps clbi ]
else [ ["-package", display pkg]
| pkg <- componentPackageDeps lbi clbi ])
++ ghcPackageFlags lbi clbi
++ ["-l"++extraLib | extraLib <- extraLibs libBi]
++ ["-L"++extraLibDir | extraLibDir <- extraLibDirs libBi]
......@@ -761,11 +756,7 @@ ghcOptions lbi bi clbi odir
, inc <- PD.includes bi ]
++ [ "-odir", odir, "-hidir", odir ]
++ concat [ ["-stubdir", odir] | ghcVer >= Version [6,8] [] ]
++ concat (if ghcVer >= Version [6,11] []
then [ ["-package-id", display ipid]
| ipid <- componentInstalledPackageDeps clbi ]
else [ ["-package", display pkg]
| pkg <- componentPackageDeps lbi clbi ])
++ ghcPackageFlags lbi clbi
++ (case withOptimization lbi of
NoOptimisation -> []
NormalOptimisation -> ["-O"]
......@@ -775,6 +766,17 @@ ghcOptions lbi bi clbi odir
where
ghcVer = compilerVersion (compiler lbi)
ghcPackageFlags :: LocalBuildInfo -> ComponentLocalBuildInfo -> [String]
ghcPackageFlags lbi clbi
| ghcVer >= Version [6,11] []
= concat [ ["-package-id", display ipkgid]
| (ipkgid, _) <- componentPackageDeps clbi ]
| otherwise = concat [ ["-package", display pkgid]
| (_, pkgid) <- componentPackageDeps clbi ]
where
ghcVer = compilerVersion (compiler lbi)
ghcPackageDbOptions :: PackageDBStack -> [String]
ghcPackageDbOptions dbstack = case dbstack of
(GlobalPackageDB:dbs)
......@@ -806,7 +808,7 @@ ghcCcOptions :: LocalBuildInfo -> BuildInfo -> ComponentLocalBuildInfo
ghcCcOptions lbi bi clbi odir
= ["-I" ++ dir | dir <- PD.includeDirs bi]
++ ghcPackageDbOptions (withPackageDB lbi)
++ concat [ ["-package", display pkg] | pkg <- componentPackageDeps lbi clbi ]
++ ghcPackageFlags lbi clbi
++ ["-optc" ++ opt | opt <- PD.ccOptions bi]
++ (case withOptimization lbi of
NoOptimisation -> []
......
......@@ -408,7 +408,7 @@ haddockPackageFlags :: LocalBuildInfo
-> IO ([(FilePath,Maybe FilePath)], Maybe String)
haddockPackageFlags lbi htmlTemplate = do
let allPkgs = installedPkgs lbi
directDeps = externalPackageDeps lbi
directDeps = map fst (externalPackageDeps lbi)
transitiveDeps <- case dependencyClosure allPkgs directDeps of
Left x -> return x
Right _ -> die "Can't find transitive deps for haddock"
......
......@@ -56,8 +56,7 @@ import qualified Distribution.InstalledPackageInfo as InstalledPackageInfo
import Distribution.Simple.PackageIndex (PackageIndex)
import qualified Distribution.Simple.PackageIndex as PackageIndex
import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo(..), ComponentLocalBuildInfo(..),
componentPackageDeps )
( LocalBuildInfo(..), ComponentLocalBuildInfo(..) )
import Distribution.Simple.BuildPaths
( autogenModulesDir, exeExtension )
import Distribution.Simple.Compiler
......@@ -172,7 +171,8 @@ constructJHCCmdLine lbi bi clbi _odir verbosity =
++ concat [["-i", l] | l <- nub (hsSourceDirs bi)]
++ ["-i", autogenModulesDir lbi]
++ ["-optc" ++ opt | opt <- PD.ccOptions bi]
++ (concat [ ["-p", display pkg] | pkg <- componentPackageDeps lbi clbi ])
++ (concat [ ["-p", display pkgid]
| (_, pkgid) <- componentPackageDeps clbi ])
jhcPkgConf :: PackageDescription -> String
jhcPkgConf pd =
......
......@@ -82,8 +82,7 @@ import Distribution.Simple.PackageIndex
import qualified Distribution.Simple.PackageIndex as PackageIndex
import Distribution.ParseUtils ( ParseResult(..) )
import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo(..), ComponentLocalBuildInfo(..),
componentPackageDeps )
( LocalBuildInfo(..), ComponentLocalBuildInfo(..) )
import Distribution.Simple.InstallDirs
import Distribution.Simple.BuildPaths
import Distribution.Simple.Utils
......@@ -459,7 +458,7 @@ buildLib verbosity pkg_descr lbi lib clbi = do
"-o", sharedLibFilePath ]
++ ghcSharedObjArgs
++ ["-package-name", display pkgid ]
++ (concat [ ["-package", display pkg] | pkg <- componentPackageDeps lbi clbi ])
++ ghcPackageFlags lbi clbi
++ ["-l"++extraLib | extraLib <- extraLibs libBi]
++ ["-L"++extraLibDir | extraLibDir <- extraLibDirs libBi]
......@@ -629,7 +628,7 @@ ghcOptions lbi bi clbi odir
++ [ "-odir", odir, "-hidir", odir ]
++ (if compilerVersion c >= Version [6,8] []
then ["-stubdir", odir] else [])
++ (concat [ ["-package", display pkg] | pkg <- componentPackageDeps lbi clbi ])
++ ghcPackageFlags lbi clbi
++ (case withOptimization lbi of
NoOptimisation -> []
NormalOptimisation -> ["-O"]
......@@ -638,6 +637,17 @@ ghcOptions lbi bi clbi odir
++ extensionsToFlags c (extensions bi)
where c = compiler lbi
ghcPackageFlags :: LocalBuildInfo -> ComponentLocalBuildInfo -> [String]
ghcPackageFlags lbi clbi
| ghcVer >= Version [6,11] []
= concat [ ["-package-id", display ipkgid]
| (ipkgid, _) <- componentPackageDeps clbi ]
| otherwise = concat [ ["-package", display pkgid]
| (_, pkgid) <- componentPackageDeps clbi ]
where
ghcVer = compilerVersion (compiler lbi)
ghcPackageDbOptions :: PackageDBStack -> [String]
ghcPackageDbOptions dbstack = case dbstack of
(GlobalPackageDB:UserPackageDB:dbs) -> concatMap specific dbs
......@@ -668,7 +678,7 @@ ghcCcOptions :: LocalBuildInfo -> BuildInfo -> ComponentLocalBuildInfo
ghcCcOptions lbi bi clbi odir
= ["-I" ++ dir | dir <- PD.includeDirs bi]
++ ghcPackageDbOptions (withPackageDB lbi)
++ concat [ ["-package", display pkg] | pkg <- componentPackageDeps lbi clbi ]
++ ghcPackageFlags lbi clbi
++ ["-optc" ++ opt | opt <- PD.ccOptions bi]
++ (case withOptimization lbi of
NoOptimisation -> []
......
......@@ -50,9 +50,6 @@ module Distribution.Simple.LocalBuildInfo (
withLibLBI,
withExeLBI,
ComponentLocalBuildInfo(..),
componentPackageDeps,
getLocalPackageInfo,
isInternalPackage,
-- * Installation directories
module Distribution.Simple.InstallDirs,
absoluteInstallDirs, prefixRelativeInstallDirs,
......@@ -73,9 +70,7 @@ import Distribution.Package
import Distribution.Simple.Compiler
( Compiler(..), PackageDBStack, OptimisationLevel )
import Distribution.Simple.PackageIndex
( PackageIndex, lookupInstalledPackageId )
import Distribution.InstalledPackageInfo
( InstalledPackageInfo )
( PackageIndex )
import Distribution.Simple.Utils
( die )
......@@ -117,38 +112,21 @@ data LocalBuildInfo = LocalBuildInfo {
} deriving (Read, Show)
data ComponentLocalBuildInfo = ComponentLocalBuildInfo {
-- | External package dependencies for this component. The 'BuildInfo'
-- specifies a set of build dependencies that must be satisfied in terms of
-- version ranges. This field fixes those dependencies to the specific
-- versions available on this machine for this compiler.
componentInstalledPackageDeps :: [InstalledPackageId]
-- | Resolved internal and external package dependencies for this component.
-- The 'BuildInfo' specifies a set of build dependencies that must be
-- satisfied in terms of version ranges. This field fixes those dependencies
-- to the specific versions available on this machine for this compiler.
componentPackageDeps :: [(InstalledPackageId, PackageId)]
}
deriving (Read, Show)
--TODO: check how these are used. In particular check how we handle
-- intra-package deps, are they really InstalledPackageId?
--TODO: having to do (packageId . getLocalPackageInfo lbi) to convert
-- an InstalledPackageId to a PackageId is not really ideal.
componentPackageDeps :: LocalBuildInfo -> ComponentLocalBuildInfo -> [PackageId]
componentPackageDeps lbi =
map (packageId.getLocalPackageInfo lbi) . componentInstalledPackageDeps
getLocalPackageInfo :: LocalBuildInfo -> InstalledPackageId
-> InstalledPackageInfo
getLocalPackageInfo lbi ipid@(InstalledPackageId s) =
case lookupInstalledPackageId (installedPkgs lbi) ipid of
Nothing -> error ("getLocalPackageInfo: unknown InstalledPackageId: " ++ s)
Just ipi -> ipi
-- | External package dependencies for the package as a whole, the union of the
-- individual 'targetPackageDeps'.
externalPackageDeps :: LocalBuildInfo -> [InstalledPackageId]
externalPackageDeps :: LocalBuildInfo -> [(InstalledPackageId, PackageId)]
externalPackageDeps lbi = nub $
-- TODO: what about non-buildable components?
maybe [] componentInstalledPackageDeps (libraryConfig lbi)
++ concatMap (componentInstalledPackageDeps . snd) (executableConfigs lbi)
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
......@@ -173,11 +151,6 @@ withExeLBI pkg_descr lbi f = withExe pkg_descr $ \exe ->
++ exeName exe ++ " but there is no corresponding "
++ "configuration data"
-- True if the specified package (or library) is defined internally
-- to the package.
isInternalPackage :: PackageDescription -> PackageId -> Bool
isInternalPackage pkg_descr pkgid = packageId pkg_descr == pkgid
-- -----------------------------------------------------------------------------
-- Wrappers for a couple functions from InstallDirs
......
......@@ -54,8 +54,7 @@ import Distribution.PackageDescription
import Distribution.ModuleName (ModuleName)
import qualified Distribution.ModuleName as ModuleName
import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo(..), ComponentLocalBuildInfo(..),
componentPackageDeps )
( LocalBuildInfo(..), ComponentLocalBuildInfo(..) )
import Distribution.Simple.BuildPaths
( mkLibName, objExtension, exeExtension )
import Distribution.Simple.Compiler
......@@ -156,8 +155,8 @@ buildLib verbosity pkg_descr lbi lib clbi = do
++ extensionFlags
++ maybe [] (hcOptions NHC . libBuildInfo)
(library pkg_descr)
++ concat [ ["-package", display (packageName pkg) ]
| pkg <- componentPackageDeps lbi clbi ]
++ concat [ ["-package", display (packageName pkgid) ]
| (_, pkgid) <- componentPackageDeps clbi ]
++ inFiles
{-
-- build any C sources
......@@ -221,8 +220,8 @@ buildExe verbosity pkg_descr lbi exe clbi = do
++ extensionFlags
++ maybe [] (hcOptions NHC . libBuildInfo)
(library pkg_descr)
++ concat [ ["-package", display (packageName pkg) ]
| pkg <- componentPackageDeps lbi clbi ]
++ concat [ ["-package", display (packageName pkgid) ]
| (_, pkgid) <- componentPackageDeps clbi ]
++ inFiles
++ [exeName exe]
......
......@@ -300,7 +300,7 @@ generalInstalledPackageInfo adjustRelIncDirs pkg lib clbi installDirs =
IPI.extraGHCiLibraries = [],
IPI.includeDirs = absinc ++ adjustRelIncDirs relinc,
IPI.includes = includes bi,
IPI.depends = componentInstalledPackageDeps clbi,
IPI.depends = map fst (componentPackageDeps clbi),
IPI.hugsOptions = hcOptions Hugs bi,
IPI.ccOptions = [], -- Note. NOT ccOptions bi!
-- We don't want cc-options to be propagated
......
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