Commit 36abbcb2 authored by bjorn@bringert.net's avatar bjorn@bringert.net
Browse files

Only configure the compiler once per command.

parent 77aace39
......@@ -12,6 +12,7 @@
-----------------------------------------------------------------------------
module Network.Hackage.CabalInstall.BuildDep where
import Network.Hackage.CabalInstall.Config (findCompiler)
import Network.Hackage.CabalInstall.Dependency (getPackages, getBuildDeps
, listInstalledPackages
, depToUnresolvedDep, resolveDependenciesAux)
......@@ -27,10 +28,11 @@ import Distribution.PackageDescription (readPackageDescription, buildDepends,
-}
buildDep :: ConfigFlags -> [String] -> [UnresolvedDependency] -> IO ()
buildDep cfg globalArgs deps
= do ipkgs <- listInstalledPackages cfg
= do (comp,conf) <- findCompiler cfg
ipkgs <- listInstalledPackages cfg comp conf
apkgs <- fmap getPackages (fmap (getBuildDeps ipkgs)
(resolveDependenciesAux cfg ipkgs deps))
installPackages cfg globalArgs apkgs
(resolveDependenciesAux cfg comp conf ipkgs deps))
installPackages cfg comp globalArgs apkgs
-- | Takes the path to a .cabal file, and installs the build-dependencies listed there.
-- FIXME: what if the package uses hooks which modify the build-dependencies?
......
......@@ -20,7 +20,6 @@ module Network.Hackage.CabalInstall.Config
, pkgURL
, defaultConfigFile
, loadConfig
, programConfiguration
, findCompiler
) where
......@@ -121,17 +120,11 @@ pkgURL pkg repo = joinWith "/" [repoURL repo, pkgName pkg, showVersion (pkgVersi
-- * Compiler and programs
--
-- FIXME: should look at config
programConfiguration :: ConfigFlags -> IO ProgramConfiguration
programConfiguration cfg = return defaultProgramConfiguration
-- FIXME: should use --with flags
findCompiler :: ConfigFlags -> IO (Compiler, ProgramConfiguration)
findCompiler cfg =
do conf <- programConfiguration cfg
Configure.configCompiler
(Just (configCompiler cfg))
Nothing Nothing conf (configVerbose cfg)
findCompiler cfg = Configure.configCompiler
(Just (configCompiler cfg))
Nothing Nothing defaultProgramConfiguration (configVerbose cfg)
--
-- * Default config
......
......@@ -35,6 +35,7 @@ import Distribution.PackageDescription
import Distribution.ParseUtils (showDependency)
import Distribution.Simple.Configure (getInstalledPackages)
import Distribution.Simple.Compiler (PackageDB(..), Compiler, showCompilerId, compilerVersion)
import Distribution.Simple.Program (ProgramConfiguration)
import Data.Char (toLower)
import Data.List (nub, maximumBy, isPrefixOf)
......@@ -109,7 +110,7 @@ isInstalled :: [PackageIdentifier] -- ^Installed packages.
isInstalled ps dep = any (fulfillDependency dep) ps
getDependency :: Compiler
getDependency :: Compiler
-> [PackageIdentifier]
-> [PkgInfo]
-> UnresolvedDependency -> ResolvedPackage
......@@ -170,12 +171,13 @@ finalizePackage comp installed available flags desc
-- |Resolve some dependencies from the known packages while filtering out installed packages.
-- The result hasn't been modified to put the dependencies in front of the packages.
resolveDependenciesAux :: ConfigFlags
-> Compiler
-> ProgramConfiguration
-> [PackageIdentifier] -- ^Installed packages.
-> [UnresolvedDependency] -- ^Dependencies in need of resolution.
-> IO [ResolvedPackage]
resolveDependenciesAux cfg ps deps
= do (comp,_) <- findCompiler cfg
installed <- listInstalledPackages cfg
resolveDependenciesAux cfg comp conf ps deps
= do installed <- listInstalledPackages cfg comp conf
knownPkgs <- getKnownPackages cfg
let resolve dep
= let rDep = getDependency comp installed knownPkgs dep
......@@ -187,19 +189,20 @@ resolveDependenciesAux cfg ps deps
-- |Resolve some dependencies from the known packages while filtering out installed packages.
-- The result has been modified to put the dependencies in front of the packages.
resolveDependencies :: ConfigFlags
-> Compiler
-> ProgramConfiguration
-> [PackageIdentifier] -- ^Installed packages.
-> [UnresolvedDependency] -- ^Dependencies in need of resolution.
-> IO [ResolvedPackage]
resolveDependencies cfg ps deps
= fmap (flattenDepList ps) (resolveDependenciesAux cfg ps deps)
resolveDependencies cfg comp conf ps deps
= fmap (flattenDepList ps) (resolveDependenciesAux cfg comp conf ps deps)
listInstalledPackages :: ConfigFlags -> IO [PackageIdentifier]
listInstalledPackages cfg =
do (comp, conf) <- findCompiler cfg
Just ipkgs <- getInstalledPackages
listInstalledPackages :: ConfigFlags -> Compiler -> ProgramConfiguration -> IO [PackageIdentifier]
listInstalledPackages cfg comp conf =
do Just ipkgs <- getInstalledPackages
(configVerbose cfg) comp
(if configUserInstall cfg then UserPackageDB
else GlobalPackageDB)
conf
return ipkgs
return ipkgs
\ No newline at end of file
......@@ -32,7 +32,7 @@ import Text.Printf (printf)
import System.Directory (doesFileExist, createDirectoryIfMissing)
import Network.Hackage.CabalInstall.Types (ConfigFlags (..), UnresolvedDependency (..), Repo(..))
import Network.Hackage.CabalInstall.Config (packagesDirectory, repoCacheDir, packageFile, packageDir, pkgURL, message)
import Network.Hackage.CabalInstall.Config (packagesDirectory, repoCacheDir, packageFile, packageDir, pkgURL, message, findCompiler)
import Network.Hackage.CabalInstall.Dependency (filterFetchables, resolveDependencies)
import Distribution.Package (PackageIdentifier(..), showPackageId)
......@@ -126,7 +126,8 @@ fetchPackage cfg pkg repo
-- |Fetch a list of packages and their dependencies.
fetch :: ConfigFlags -> [String] -> IO ()
fetch cfg pkgs
= do apkgs <- fmap filterFetchables (resolveDependencies cfg [] (map parseDep pkgs))
= do (comp,conf) <- findCompiler cfg
apkgs <- fmap filterFetchables (resolveDependencies cfg comp conf [] (map parseDep pkgs))
mapM_ (\(pkg,repo)
-> fetchPackage cfg pkg repo
) =<< filterM isNotFetched apkgs
......
......@@ -12,7 +12,7 @@
-----------------------------------------------------------------------------
module Network.Hackage.CabalInstall.Info where
import Network.Hackage.CabalInstall.Config (pkgURL)
import Network.Hackage.CabalInstall.Config (pkgURL, findCompiler)
import Network.Hackage.CabalInstall.Dependency
(resolveDependencies, fulfillDependency, listInstalledPackages)
import Network.Hackage.CabalInstall.Fetch (isFetched, packageFile)
......@@ -27,8 +27,9 @@ import Text.Printf (printf)
info :: ConfigFlags -> [String] -> [UnresolvedDependency] -> IO ()
info cfg globalArgs deps
= do ipkgs <- listInstalledPackages cfg
apkgs <- resolveDependencies cfg [] deps
= do (comp,conf) <- findCompiler cfg
ipkgs <- listInstalledPackages cfg comp conf
apkgs <- resolveDependencies cfg comp conf [] deps
mapM_ (infoPkg cfg ipkgs globalArgs) apkgs
{-|
......
......@@ -45,12 +45,13 @@ import Distribution.Verbosity
-- |Installs the packages needed to satisfy a list of dependencies.
install :: ConfigFlags -> [String] -> [UnresolvedDependency] -> IO ()
install cfg globalArgs deps
= do ipkgs <- listInstalledPackages cfg
resolvedDeps <- resolveDependencies cfg ipkgs deps
= do (comp,conf) <- findCompiler cfg
ipkgs <- listInstalledPackages cfg comp conf
resolvedDeps <- resolveDependencies cfg comp conf ipkgs deps
let apkgs = getPackages resolvedDeps
if null apkgs
then putStrLn "All requested packages already installed. Nothing to do."
else installPackages cfg globalArgs apkgs
else installPackages cfg comp globalArgs apkgs
-- Fetch a package and output nice messages.
downloadPkg :: ConfigFlags -> PackageIdentifier -> Repo -> IO FilePath
......@@ -88,11 +89,11 @@ installDirFlags dirs =
where flag s f = "--" ++ s ++ "=" ++ f dirs
installPackages :: ConfigFlags
-> Compiler
-> [String] -- ^Options which will be parse to every package.
-> [(PackageIdentifier,[String],Repo)] -- ^(Package, list of configure options, package location)
-> IO ()
installPackages cfg globalArgs pkgs =
do (comp, _) <- findCompiler cfg
installPackages cfg comp globalArgs pkgs =
mapM_ (installPkg cfg comp globalArgs) pkgs
{-|
......
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