Commit 397985f7 authored by duncan.coutts@worc.ox.ac.uk's avatar duncan.coutts@worc.ox.ac.uk
Browse files

make it build with cabal-1.1.7

But it does not work yet as it need to be updated to take configurations into
account. At the moment it thinks no packages have any dependencies since
it does not finalise the configuration for the package.
parent 494f451c
......@@ -16,7 +16,8 @@ import Network.Hackage.CabalInstall.Dependency (getPackages, getBuildDeps, depTo
import Network.Hackage.CabalInstall.Install (install, installPkg)
import Network.Hackage.CabalInstall.Types (ConfigFlags (..), UnresolvedDependency)
import Distribution.PackageDescription (readPackageDescription, buildDepends)
import Distribution.PackageDescription (readPackageDescription, buildDepends,
GenericPackageDescription(..))
import Distribution.Simple.Configure (getInstalledPackages)
{-|
......@@ -31,8 +32,10 @@ buildDep cfg globalArgs deps
-- | 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?
-- FIXME: packageDescription will give us empty build-depends. We have to
-- finalise the configuration at this point to find the actual build deps.
buildDepLocalPkg :: ConfigFlags -> FilePath -> IO ()
buildDepLocalPkg cfg pkgDescPath =
do pkgDesc <- readPackageDescription (configVerbose cfg) pkgDescPath
let deps = map depToUnresolvedDep $ buildDepends pkgDesc
let deps = map depToUnresolvedDep $ buildDepends $ packageDescription pkgDesc
install cfg [] deps
......@@ -23,15 +23,17 @@ import Network.Hackage.CabalInstall.Config
(getDefaultConfigDir, getLocalConfigDir, getLocalCacheDir,
getLocalPkgListDir, getKnownServers, selectValidConfigDir)
import qualified Distribution.Simple.Configure as Configure (findProgram, configCompiler)
import qualified Distribution.Simple.Configure as Configure (configCompiler)
import Distribution.Simple.Program
import Distribution.ParseUtils (showDependency)
import Distribution.Package (showPackageId)
import Distribution.Version (VersionRange(..))
import Distribution.Verbosity
import System.FilePath ((</>))
import Text.Printf (printf)
import System.IO (openFile, IOMode (..))
import System.Directory (getHomeDirectory, getAppUserDataDirectory)
import System.Directory (doesFileExist, getHomeDirectory, getAppUserDataDirectory)
import Data.Maybe (fromMaybe)
{-|
......@@ -85,11 +87,6 @@ defaultOutputGen verbosity
showDep dep = show (showDependency (fulfilling dep))
findProgramOrDie :: String -> Maybe FilePath -> IO FilePath
findProgramOrDie name p = fmap (fromMaybe (error $ printf "No %s found." name)) (Configure.findProgram name p)
-- |Compute the default prefix when doing a local install ('~/usr' on Linux).
localPrefix :: IO FilePath
localPrefix
......@@ -109,9 +106,13 @@ localPrefix
-}
mkConfigFlags :: TempFlags -> IO ConfigFlags
mkConfigFlags cfg
= do runHc <- findProgramOrDie "runhaskell" (tempRunHc cfg)
tarProg <- findProgramOrDie "tar" (tempTarPath cfg)
comp <- Configure.configCompiler (tempHcFlavor cfg) (tempHcPath cfg) (tempHcPkg cfg) (tempVerbose cfg)
= do let verbosity = tempVerbose cfg
conf = userMaybeSpecifyPath "runhaskell" (tempRunHc cfg) $
userMaybeSpecifyPath "tar" (tempTarPath cfg) $
defaultProgramConfiguration
(runHc, conf') <- requireProgram verbosity runhaskellProgram AnyVersion conf
(tarProg, conf'') <- requireProgram verbosity tarProgram AnyVersion conf'
(comp, conf''') <- Configure.configCompiler (tempHcFlavor cfg) (tempHcPath cfg) (tempHcPkg cfg) conf'' verbosity
let userIns = tempUserIns cfg
prefix <- if userIns
then fmap Just (maybe localPrefix return (tempPrefix cfg))
......@@ -124,9 +125,10 @@ mkConfigFlags cfg
[localConfigDir, defaultConfigDir] )
let cacheDir = fromMaybe localCacheDir (tempCacheDir cfg)
pkgListDir = fromMaybe localPkgListDir (tempPkgListDir cfg)
when (tempVerbose cfg > normal) $ do printf "Using config dir: %s\n" confDir
printf "Using cache dir: %s\n" cacheDir
printf "Using pkglist dir: %s\n" pkgListDir
when (verbosity > normal) $ do
printf "Using config dir: %s\n" confDir
printf "Using cache dir: %s\n" cacheDir
printf "Using pkglist dir: %s\n" pkgListDir
outputGen <- defaultOutputGen (tempVerbose cfg)
let config = ConfigFlags
{ configCompiler = comp
......@@ -135,8 +137,8 @@ mkConfigFlags cfg
, configPkgListDir = pkgListDir
, configPrefix = prefix
, configServers = []
, configTarPath = tarProg
, configRunHc = runHc
, configTarPath = programPath tarProg
, configRunHc = programPath runHc
, configOutputGen = outputGen
, configVerbose = tempVerbose cfg
-- , configUpgradeDeps = tempUpgradeDeps cfg
......@@ -145,3 +147,5 @@ mkConfigFlags cfg
knownServers <- getKnownServers config
return (config{ configServers = knownServers ++ tempServers cfg})
runhaskellProgram :: Program
runhaskellProgram = simpleProgram "runhaskell"
......@@ -26,7 +26,7 @@ import Network.Hackage.CabalInstall.Types (ConfigFlags(..), UnresolvedDependency
,OutputGen(..))
import Network.Hackage.CabalInstall.TarUtils
import Distribution.SetupWrapper (setupWrapper)
import Distribution.Simple.SetupWrapper (setupWrapper)
import Distribution.Simple.Configure (getInstalledPackages)
import Distribution.Package (showPackageId, PackageIdentifier)
import Distribution.Verbosity
......
......@@ -20,7 +20,7 @@ import Control.Monad (when)
import Data.Maybe (fromMaybe)
import Text.ParserCombinators.ReadP (readP_to_S)
import Distribution.ParseUtils (parseDependency)
import Distribution.Setup (defaultCompilerFlavor, CompilerFlavor(..))
import Distribution.Compiler (defaultCompilerFlavor, CompilerFlavor(..))
import Distribution.Verbosity
import Data.List (find)
import System.Console.GetOpt (ArgDescr (..), ArgOrder (..), OptDescr (..), usageInfo, getOpt')
......
......@@ -12,7 +12,7 @@
-----------------------------------------------------------------------------
module Network.Hackage.CabalInstall.Types where
import Distribution.Setup (CompilerFlavor(..),Compiler)
import Distribution.Simple.Compiler (CompilerFlavor(..),Compiler)
import Distribution.Package (PackageIdentifier)
import Distribution.Version (Dependency)
import Distribution.Verbosity
......
......@@ -21,7 +21,7 @@ import Network.Hackage.CabalInstall.Utils (isVerbose)
import Network.Hackage.CabalInstall.Fetch (downloadIndex, packagesDirectory)
import Distribution.Package (PackageIdentifier(..), pkgName, showPackageId)
import Distribution.PackageDescription (PackageDescription(..), readPackageDescription)
import Distribution.PackageDescription (PackageDescription(..), readPackageDescription, GenericPackageDescription(..))
import Distribution.Verbosity
import System.FilePath ((</>), joinPath, addExtension, takeExtension)
......@@ -44,11 +44,13 @@ update cfg =
cabalFiles = [ packageDir </> path
| path <- contents
, ".cabal" == takeExtension path ]
v = configVerbose cfg
v'= if v == verbose then normal else v
packageDescriptions <-
mapM (readPackageDescription v') cabalFiles
return $ map (parsePkg server) packageDescriptions
--TODO: we can't just take the packageDescription out of the
-- GenericPackageDescription since the build-depends is empty
-- we should store the whole GenericPackageDescription and
-- resolve the configuration later when we build.
mapM (liftM (parsePkg server . packageDescription)
. readPackageDescription (lessVerbose (configVerbose cfg)))
cabalFiles
when (isVerbose cfg) $ printf "Processed %d package descriptions\n" (length packages)
writeKnownPackages cfg packages
where servers = configServers cfg
......
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