Commit 46ef42b7 authored by Duncan Coutts's avatar Duncan Coutts

Filter the configure flags based on the Cabal lib version

Allows us to use cabal-install to build packages where we build the
Setup.hs script using an older version of the Cabal library.
This is important for packages that claim to need an older version
and it's also pretty useful for testing.
parent e2a352d1
......@@ -35,7 +35,8 @@ import Hackage.Fetch (fetchPackage)
import qualified Hackage.IndexUtils as IndexUtils
import qualified Hackage.InstallPlan as InstallPlan
import Hackage.InstallPlan (InstallPlan)
import Hackage.Setup (InstallFlags(..))
import Hackage.Setup
( InstallFlags(..), configureCommand, filterConfigureFlags )
import Hackage.Tar (extractTarGzFile)
import Hackage.Types as Available
( UnresolvedDependency(..), AvailablePackage(..)
......@@ -132,7 +133,7 @@ installWithPlanner planner verbosity packageDB repos comp conf configFlags insta
progress <- planner installed available
info verbosity "Resolving dependencies..."
notice verbosity "Resolving dependencies..."
maybePlan <- foldProgress (\message rest -> info verbosity message >> rest)
(return . Left) (return . Right) progress
case maybePlan of
......@@ -317,17 +318,17 @@ installUnpackedPackage :: Verbosity
-> IO BuildResult
installUnpackedPackage verbosity scriptOptions miscOptions configFlags pkg mpath
= onFailure ConfigureFailed $ do
setup configureCommand configFlags
setup configureCommand (filterConfigureFlags configFlags)
onFailure BuildFailed $ do
setup buildCommand Cabal.emptyBuildFlags
setup buildCommand (const Cabal.emptyBuildFlags)
onFailure InstallFailed $ do
case rootCmd miscOptions of
(Just cmd) -> reexec cmd
Nothing -> setup Cabal.installCommand Cabal.emptyInstallFlags
Nothing -> setup Cabal.installCommand
(const Cabal.emptyInstallFlags)
return BuildOk
where
configureCommand = Cabal.configureCommand defaultProgramConfiguration
buildCommand = Cabal.buildCommand defaultProgramConfiguration
buildCommand = Cabal.buildCommand defaultProgramConfiguration
setup cmd flags = inDir mpath $
setupWrapper verbosity scriptOptions
(Just $ PackageDescription.packageDescription pkg)
......
......@@ -12,7 +12,7 @@
-----------------------------------------------------------------------------
module Hackage.Setup
( globalCommand, Cabal.GlobalFlags(..)
, configureCommand
, configureCommand, filterConfigureFlags
, installCommand, InstallFlags(..)
, listCommand, ListFlags(..)
, updateCommand
......@@ -44,7 +44,7 @@ import qualified Distribution.Simple.Setup as Cabal
import Distribution.Simple.Setup
( Flag(..), toFlag, flagToList, trueArg, optionVerbosity )
import Distribution.Version
( Version )
( Version(Version) )
import Distribution.Text
( Text(parse), display )
import Distribution.ReadE
......@@ -75,6 +75,13 @@ configureCommand = (Cabal.configureCommand defaultProgramConfiguration) {
commandDefaultFlags = mempty
}
filterConfigureFlags :: Cabal.ConfigFlags -> Version -> Cabal.ConfigFlags
filterConfigureFlags flags cabalLibVersion
| cabalLibVersion >= Version [1,3,10] [] = flags
-- older Cabal does not grok the constraints flag:
| otherwise = flags { Cabal.configConstraints = [] }
fetchCommand :: CommandUI (Flag Verbosity)
fetchCommand = CommandUI {
commandName = "fetch",
......
......@@ -86,7 +86,7 @@ setupWrapper :: Verbosity
-> SetupScriptOptions
-> Maybe PackageDescription
-> CommandUI flags
-> flags
-> (Version -> flags)
-> [String]
-> IO ()
setupWrapper verbosity options mpkg cmd flags extraArgs = do
......@@ -99,7 +99,7 @@ setupWrapper verbosity options mpkg cmd flags extraArgs = do
}
buildType' = fromMaybe Custom (buildType pkg)
mkArgs cabalLibVersion = commandName cmd
: commandShowOptions cmd flags
: commandShowOptions cmd (flags cabalLibVersion)
++ extraArgs
setupMethod verbosity pkg buildType' mkArgs
where
......@@ -166,8 +166,6 @@ externalSetupMethod options verbosity pkg bt mkargs = do
case savedVersion of
Just version | version `withinRange` useCabalVersion options
-> return (version, options)
Nothing | packageName pkg == "Cabal"
-> return (packageVersion pkg, options)
_ -> do (comp, conf, options') <- configureCompiler options
version <- installedCabalVersion options comp conf
writeFile setupVersionFile (show version ++ "\n")
......@@ -181,6 +179,8 @@ externalSetupMethod options verbosity pkg bt mkargs = do
installedCabalVersion :: SetupScriptOptions -> Compiler
-> ProgramConfiguration -> IO Version
installedCabalVersion _ _ _ | packageName pkg == "Cabal" =
return (packageVersion pkg)
installedCabalVersion options' comp conf = do
index <- case usePackageIndex options' of
Just index -> return index
......
......@@ -121,7 +121,8 @@ wrapperAction command verbosityFlag distPrefFlag =
(useDistPref defaultSetupScriptOptions)
(distPrefFlag flags)
}
setupWrapper verbosity setupScriptOptions Nothing command flags extraArgs
setupWrapper verbosity setupScriptOptions Nothing
command (const flags) extraArgs
configureAction :: Cabal.ConfigFlags -> [String] -> IO ()
configureAction flags extraArgs = do
......@@ -139,7 +140,7 @@ configureAction flags extraArgs = do
(Cabal.configDistPref flags)
}
setupWrapper verbosity setupScriptOptions Nothing
configureCommand flags' extraArgs
configureCommand (const flags') extraArgs
installAction :: (Cabal.ConfigFlags, InstallFlags) -> [String] -> IO ()
installAction (cflags,iflags) _
......
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