Commit 569fef28 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Use VersionRange abstractly

parent 94a39fb2
......@@ -58,7 +58,7 @@ module Distribution.Package (
) where
import Distribution.Version
( Version(..), VersionRange(AnyVersion,ThisVersion), notThisVersion )
( Version(..), VersionRange, anyVersion, thisVersion, notThisVersion )
import Distribution.Text (Text(..))
import qualified Distribution.Compat.ReadP as Parse
......@@ -117,13 +117,13 @@ instance Text Dependency where
parse = do name <- parse
Parse.skipSpaces
ver <- parse <++ return AnyVersion
ver <- parse <++ return anyVersion
Parse.skipSpaces
return (Dependency name ver)
thisPackageVersion :: PackageIdentifier -> Dependency
thisPackageVersion (PackageIdentifier n v) =
Dependency n (ThisVersion v)
Dependency n (thisVersion v)
notThisPackageVersion :: PackageIdentifier -> Dependency
notThisPackageVersion (PackageIdentifier n v) =
......
......@@ -100,7 +100,7 @@ import Distribution.Package
( PackageName(PackageName), PackageIdentifier(PackageIdentifier)
, Dependency, Package(..) )
import Distribution.ModuleName (ModuleName)
import Distribution.Version (Version(Version), VersionRange(AnyVersion))
import Distribution.Version (Version(Version), VersionRange, anyVersion)
import Distribution.License (License(AllRightsReserved))
import Distribution.Compiler (CompilerFlavor)
import Distribution.System (OS, Arch)
......@@ -161,7 +161,7 @@ emptyPackageDescription
(Version [] []),
license = AllRightsReserved,
licenseFile = "",
descCabalVersion = AnyVersion,
descCabalVersion = anyVersion,
buildType = Nothing,
copyright = "",
maintainer = "",
......
......@@ -67,7 +67,7 @@ import Distribution.PackageDescription
import Distribution.Simple.PackageIndex (PackageIndex)
import qualified Distribution.Simple.PackageIndex as PackageIndex
import Distribution.Version
( VersionRange(..), withinRange )
( VersionRange, anyVersion, intersectVersionRanges, withinRange )
import Distribution.Compiler
( CompilerId(CompilerId) )
import Distribution.System
......@@ -179,7 +179,7 @@ parseCondition = condOr
oper s = sp >> string s >> sp
sp = skipSpaces
implIdent = do i <- parse
vr <- sp >> option AnyVersion parse
vr <- sp >> option anyVersion parse
return $ Impl i vr
------------------------------------------------------------------------------
......@@ -271,7 +271,7 @@ resolveWithFlags dom os arch impl constrs trees checkDeps =
where tightenConstraint n c l =
case M.lookup n l of
Nothing -> l
Just vr -> M.insert n (IntersectVersionRanges vr c) l
Just vr -> M.insert n (intersectVersionRanges vr c) l
-- @try@ recursively tries all possible flag assignments in the domain and
-- either succeeds or returns a binary tree with the missing dependencies
......@@ -320,7 +320,7 @@ resolveWithFlags dom os arch impl constrs trees checkDeps =
lazyLengthCmp (_:xs) (_:ys) = lazyLengthCmp xs ys
-- | A map of dependencies. Newtyped since the default monoid instance is not
-- appropriate. The monoid instance uses 'IntersectVersionRanges'.
-- appropriate. The monoid instance uses 'intersectVersionRanges'.
newtype DependencyMap = DependencyMap { unDependencyMap :: Map PackageName VersionRange }
#if !defined(__GLASGOW_HASKELL__) || (__GLASGOW_HASKELL__ >= 606)
deriving (Show, Read)
......@@ -354,11 +354,11 @@ instance Read DependencyMap where
instance Monoid DependencyMap where
mempty = DependencyMap M.empty
(DependencyMap a) `mappend` (DependencyMap b) =
DependencyMap (M.unionWith IntersectVersionRanges a b)
DependencyMap (M.unionWith intersectVersionRanges a b)
toDepMap :: [Dependency] -> DependencyMap
toDepMap ds =
DependencyMap $ fromListWith IntersectVersionRanges [ (p,vr) | Dependency p vr <- ds ]
DependencyMap $ fromListWith intersectVersionRanges [ (p,vr) | Dependency p vr <- ds ]
fromDepMap :: DependencyMap -> [Dependency]
fromDepMap m = [ Dependency p vr | (p,vr) <- toList (unDependencyMap m) ]
......
......@@ -76,7 +76,7 @@ import Distribution.Package
( PackageName(..), PackageIdentifier(..), Dependency(..)
, packageName, packageVersion )
import Distribution.Version
( VersionRange(AnyVersion), isAnyVersion, withinRange )
( anyVersion, isAnyVersion, withinRange )
import Distribution.Verbosity (Verbosity)
import Distribution.Compiler (CompilerFlavor(..))
import Distribution.PackageDescription.Configuration (parseCondition, freeVars)
......@@ -472,7 +472,7 @@ parsePackageDescription file = do
head $ [ versionRange
| Just versionRange <- [ simpleParse v
| F _ "cabal-version" v <- fields0 ] ]
++ [AnyVersion]
++ [anyVersion]
handleFutureVersionParseFailure cabalVersionNeeded $ do
......
......@@ -69,6 +69,7 @@ module Distribution.ParseUtils (
import Distribution.Compiler (CompilerFlavor, parseCompilerFlavorCompat)
import Distribution.License
import Distribution.Version
( Version(..), VersionRange, anyVersion )
import Distribution.Package ( PackageName(..), Dependency(..) )
import Distribution.ModuleName (ModuleName)
import Distribution.Compat.ReadP as ReadP hiding (get)
......@@ -568,7 +569,7 @@ parseFilePathQ = parseTokenQ
parseBuildTool :: ReadP r Dependency
parseBuildTool = do name <- parseBuildToolNameQ
skipSpaces
ver <- parseVersionRangeQ <++ return AnyVersion
ver <- parseVersionRangeQ <++ return anyVersion
skipSpaces
return $ Dependency name ver
......@@ -589,7 +590,7 @@ parseBuildToolName = do ns <- sepBy1 component (ReadP.char '-')
parsePkgconfigDependency :: ReadP r Dependency
parsePkgconfigDependency = do name <- munch1 (\c -> isAlphaNum c || c `elem` "+-._")
skipSpaces
ver <- parseVersionRangeQ <++ return AnyVersion
ver <- parseVersionRangeQ <++ return anyVersion
skipSpaces
return $ Dependency (PackageName name) ver
......@@ -608,7 +609,7 @@ parseTestedWithQ :: ReadP r (CompilerFlavor,VersionRange)
parseTestedWithQ = parseQuoted tw <++ tw
where tw = do compiler <- parseCompilerFlavorCompat
skipSpaces
version <- parse <++ return AnyVersion
version <- parse <++ return anyVersion
skipSpaces
return (compiler,version)
......
......@@ -110,7 +110,8 @@ import Distribution.Simple.Register
import Distribution.System
( OS(..), buildOS, buildArch )
import Distribution.Version
( Version(..), VersionRange(..), orLaterVersion, withinRange )
( Version(..)
, orLaterVersion, withinRange, isSpecificVersion, isAnyVersion )
import Distribution.Verbosity
( Verbosity, lessVerbose )
......@@ -475,12 +476,11 @@ configure (pkg_descr0, pbi) cfg
-- |Converts build dependencies to a versioned dependency. only sets
-- version information for exact versioned dependencies.
inventBogusPackageId :: Dependency -> PackageIdentifier
-- if they specify the exact version, use that:
inventBogusPackageId (Dependency s (ThisVersion v)) = PackageIdentifier s v
-- otherwise, just set it to empty
inventBogusPackageId (Dependency s _) = PackageIdentifier s (Version [] [])
inventBogusPackageId (Dependency s vr) = case isSpecificVersion vr of
-- if they specify the exact version, use that:
Just v -> PackageIdentifier s v
-- otherwise, just set it to empty
Nothing -> PackageIdentifier s (Version [] [])
reportProgram :: Verbosity -> Program -> Maybe ConfiguredProgram -> IO ()
reportProgram verbosity prog Nothing
......@@ -573,8 +573,8 @@ configurePkgconfigPackages verbosity pkg_descr conf
++ ": using version " ++ display v
versionRequirement
| range == AnyVersion = ""
| otherwise = " version " ++ display range
| isAnyVersion range = ""
| otherwise = " version " ++ display range
updateLibrary Nothing = return Nothing
updateLibrary (Just lib) = do
......
......@@ -106,7 +106,7 @@ import Distribution.Simple.Compiler
( CompilerFlavor(..), CompilerId(..), Compiler(..), compilerVersion
, OptimisationLevel(..), PackageDB(..), Flag, extensionsToFlags )
import Distribution.Version
( Version(..), VersionRange(..), orLaterVersion )
( Version(..), anyVersion, orLaterVersion )
import Distribution.System
( OS(..), buildOS )
import Distribution.Verbosity
......@@ -772,9 +772,9 @@ makefile pkg_descr lbi flags = do
bi = libBuildInfo lib
packageIdStr = display (packageId pkg_descr)
(arProg, _) <- requireProgram verbosity arProgram AnyVersion
(arProg, _) <- requireProgram verbosity arProgram anyVersion
(withPrograms lbi)
(ldProg, _) <- requireProgram verbosity ldProgram AnyVersion
(ldProg, _) <- requireProgram verbosity ldProgram anyVersion
(withPrograms lbi)
let builddir = buildDir lbi
Just ghcProg = lookupProgram ghcProgram (withPrograms lbi)
......
......@@ -54,7 +54,7 @@ import Distribution.Simple.Compiler
import Distribution.Simple.Program ( ProgramConfiguration, userMaybeSpecifyPath,
requireProgram, rawSystemProgramConf,
ffihugsProgram, hugsProgram )
import Distribution.Version ( Version(..), VersionRange(AnyVersion) )
import Distribution.Version ( Version(..), anyVersion )
import Distribution.Simple.PreProcess ( ppCpp, runSimplePreProcessor )
import Distribution.Simple.PreProcess.Unlit
( unlit )
......@@ -94,9 +94,9 @@ configure :: Verbosity -> Maybe FilePath -> Maybe FilePath
-> ProgramConfiguration -> IO (Compiler, ProgramConfiguration)
configure verbosity hcPath _hcPkgPath conf = do
(_ffihugsProg, conf') <- requireProgram verbosity ffihugsProgram AnyVersion
(_ffihugsProg, conf') <- requireProgram verbosity ffihugsProgram anyVersion
(userMaybeSpecifyPath "ffihugs" hcPath conf)
(_hugsProg, conf'') <- requireProgram verbosity hugsProgram AnyVersion conf'
(_hugsProg, conf'') <- requireProgram verbosity hugsProgram anyVersion conf'
let comp = Compiler {
compilerId = CompilerId Hugs (Version [] []),
......
......@@ -67,7 +67,7 @@ import Distribution.Simple.Program ( ConfiguredProgram(..), jhcProgram,
ProgramConfiguration, userMaybeSpecifyPath,
requireProgram, lookupProgram,
rawSystemProgram, rawSystemProgramStdoutConf )
import Distribution.Version ( VersionRange(AnyVersion) )
import Distribution.Version ( anyVersion )
import Distribution.Package
( Package(..) )
import Distribution.Simple.Utils
......@@ -92,7 +92,7 @@ configure :: Verbosity -> Maybe FilePath -> Maybe FilePath
-> ProgramConfiguration -> IO (Compiler, ProgramConfiguration)
configure verbosity hcPath _hcPkgPath conf = do
(jhcProg, conf') <- requireProgram verbosity jhcProgram AnyVersion
(jhcProg, conf') <- requireProgram verbosity jhcProgram anyVersion
(userMaybeSpecifyPath "jhc" hcPath conf)
let Just version = programVersion jhcProg
......
......@@ -65,7 +65,7 @@ import Distribution.Simple.Program
, userMaybeSpecifyPath, requireProgram, lookupProgram
, userSpecifyArgs, rawSystemProgram )
import Distribution.Version
( Version(..), VersionRange(AnyVersion) )
( Version(..), anyVersion )
import Distribution.Package
( Package(..), packageName, packageVersion )
import Distribution.Simple.Utils
......@@ -89,7 +89,7 @@ configure :: Verbosity -> Maybe FilePath -> Maybe FilePath
-> ProgramConfiguration -> IO (Compiler, ProgramConfiguration)
configure verbosity hcPath _hcPkgPath conf = do
(lhcProg, conf') <- requireProgram verbosity lhcProgram AnyVersion
(lhcProg, conf') <- requireProgram verbosity lhcProgram anyVersion
(userMaybeSpecifyPath "lhc" hcPath conf)
let Just version = programVersion lhcProg
......@@ -110,7 +110,7 @@ lhcLanguageExtensions =
getLhcLibDirs :: Verbosity -> ProgramConfiguration -> IO (String, String)
getLhcLibDirs verbosity conf
= do (lhc,_conf') <- requireProgram verbosity lhcProgram AnyVersion conf
= do (lhc,_conf') <- requireProgram verbosity lhcProgram anyVersion conf
getLhcLibDirsFromVersion (programVersion lhc)
getLhcLibDirsFromVersion :: Maybe Version -> IO (String, String)
......
......@@ -71,7 +71,7 @@ import Distribution.Simple.Utils
( die, info, findFileWithExtension,
createDirectoryIfMissingVerbose, copyFileVerbose, smartCopySources )
import Distribution.Version
( Version(..), VersionRange(..), orLaterVersion )
( Version(..), anyVersion, orLaterVersion )
import Distribution.Verbosity
import Distribution.Text
( display )
......@@ -99,14 +99,14 @@ configure verbosity hcPath _hcPkgPath conf = do
(_hmakeProg, conf'') <- requireProgram verbosity hmakeProgram
(orLaterVersion (Version [3,13] [])) conf'
(_ldProg, conf''') <- requireProgram verbosity ldProgram AnyVersion conf''
(_arProg, conf'''') <- requireProgram verbosity arProgram AnyVersion conf'''
(_ldProg, conf''') <- requireProgram verbosity ldProgram anyVersion conf''
(_arProg, conf'''') <- requireProgram verbosity arProgram anyVersion conf'''
--TODO: put this stuff in a monad so we can say just:
-- requireProgram hmakeProgram (orLaterVersion (Version [3,13] []))
-- requireProgram ldProgram AnyVersion
-- requireProgram ldPrograrProgramam AnyVersion
-- unless (null (cSources bi)) $ requireProgram ccProgram AnyVersion
-- requireProgram ldProgram anyVersion
-- requireProgram ldPrograrProgramam anyVersion
-- unless (null (cSources bi)) $ requireProgram ccProgram anyVersion
let comp = Compiler {
compilerId = CompilerId NHC nhcVersion,
......
......@@ -108,7 +108,7 @@ import qualified Data.Map as Map
import Distribution.Simple.Utils
(die, debug, warn, rawSystemExit, rawSystemStdout)
import Distribution.Version
( Version(..), VersionRange(AnyVersion), withinRange )
( Version(..), VersionRange, isAnyVersion, withinRange )
import Distribution.Text
( simpleParse, display )
import Distribution.Verbosity
......@@ -478,7 +478,7 @@ requireProgram verbosity prog range conf = do
case lookupProgram prog conf' of
Nothing -> die notFound
Just configuredProg
| range == AnyVersion -> return (configuredProg, conf')
| isAnyVersion range -> return (configuredProg, conf')
Just configuredProg@ConfiguredProgram { programLocation = location } ->
case programVersion configuredProg of
Just version
......@@ -495,8 +495,8 @@ requireProgram verbosity prog range conf = do
++ " is required but the version of "
++ locationPath l ++ " could not be determined."
versionRequirement
| range == AnyVersion = ""
| otherwise = " version " ++ display range
| isAnyVersion range = ""
| otherwise = " version " ++ display range
-- ------------------------------------------------------------
-- * Running programs
......
......@@ -75,7 +75,7 @@ import Distribution.Package
import Distribution.ModuleName (ModuleName)
import qualified Distribution.ModuleName as ModuleName
import Distribution.Version
( Version(versionBranch), VersionRange(AnyVersion) )
( Version(versionBranch), anyVersion )
import Distribution.Simple.Utils
( createDirectoryIfMissingVerbose, withUTF8FileContents, writeUTF8File
, copyFiles, copyFileVerbose
......@@ -298,7 +298,7 @@ createArchive :: Verbosity -- ^verbosity
createArchive verbosity pkg_descr mb_lbi tmpDir targetPref = do
let tarBallFilePath = targetPref </> tarBallName pkg_descr <.> "tar.gz"
(tarProg, _) <- requireProgram verbosity tarProgram AnyVersion
(tarProg, _) <- requireProgram verbosity tarProgram anyVersion
(maybe defaultProgramConfiguration withPrograms mb_lbi)
-- Hmm: I could well be skating on thinner ice here by using the -C option (=> GNU tar-specific?)
......
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