Commit 05d3ca2b authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Split requireProgram into two different functions

Now requireProgram doesn't take a version range and does not check
the program version (indeed it doesn't need to have one). The new
function requireProgramVersion takes a required program version
range and returns the program version. Also update callers.
Also fixes the check that GHC has a version number.
parent 469bef21
......@@ -94,8 +94,8 @@ import Distribution.Simple.Program
, ProgramConfiguration, defaultProgramConfiguration
, configureAllKnownPrograms, knownPrograms, lookupKnownProgram
, userSpecifyArgss, userSpecifyPaths
, lookupProgram, requireProgram, pkgConfigProgram, gccProgram
, rawSystemProgramStdoutConf )
, lookupProgram, requireProgram, requireProgramVersion
, pkgConfigProgram, gccProgram, rawSystemProgramStdoutConf )
import Distribution.Simple.Setup
( ConfigFlags(..), CopyDest(..), fromFlag, fromFlagOrDefault, flagToMaybe )
import Distribution.Simple.InstallDirs
......@@ -113,7 +113,8 @@ import Distribution.Simple.Register
import Distribution.System
( OS(..), buildOS, buildArch )
import Distribution.Version
( Version(..), orLaterVersion, withinRange, isSpecificVersion, isAnyVersion
( Version(..), anyVersion, orLaterVersion, withinRange
, isSpecificVersion, isAnyVersion
, LowerBound(..), asVersionIntervals, simplifyVersionRange )
import Distribution.Verbosity
( Verbosity, lessVerbose )
......@@ -645,7 +646,16 @@ configureRequiredProgram :: Verbosity -> ProgramConfiguration -> Dependency -> I
configureRequiredProgram verbosity conf (Dependency (PackageName progName) verRange) =
case lookupKnownProgram progName conf of
Nothing -> die ("Unknown build tool " ++ progName)
Just prog -> snd `fmap` requireProgram verbosity prog verRange conf
Just prog
-- requireProgramVersion always requires the program have a version
-- but if the user says "build-depends: foo" ie no version constraint
-- then we should not fail if we cannot discover the program version.
| verRange == anyVersion -> do
(_, conf') <- requireProgram verbosity prog conf
return conf'
| otherwise -> do
(_, _, conf') <- requireProgramVersion verbosity prog verRange conf
return conf'
-- -----------------------------------------------------------------------------
-- Configuring pkg-config package dependencies
......@@ -656,8 +666,9 @@ configurePkgconfigPackages :: Verbosity -> PackageDescription
configurePkgconfigPackages verbosity pkg_descr conf
| null allpkgs = return (pkg_descr, conf)
| otherwise = do
(_, conf') <- requireProgram (lessVerbose verbosity) pkgConfigProgram
(orLaterVersion $ Version [0,9,0] []) conf
(_, _, conf') <- requireProgramVersion
(lessVerbose verbosity) pkgConfigProgram
(orLaterVersion $ Version [0,9,0] []) conf
mapM_ requirePkg allpkgs
lib' <- updateLibrary (library pkg_descr)
exes' <- mapM updateExecutable (executables pkg_descr)
......
......@@ -94,7 +94,8 @@ import qualified Distribution.ModuleName as ModuleName
import Distribution.Simple.Program
( Program(..), ConfiguredProgram(..), ProgramConfiguration, ProgArg
, ProgramLocation(..), rawSystemProgram, rawSystemProgramConf
, rawSystemProgramStdout, rawSystemProgramStdoutConf, requireProgram
, rawSystemProgramStdout, rawSystemProgramStdoutConf
, requireProgramVersion
, userMaybeSpecifyPath, programPath, lookupProgram, addKnownProgram
, ghcProgram, ghcPkgProgram, arProgram, ranlibProgram, ldProgram
, gccProgram, stripProgram )
......@@ -103,7 +104,7 @@ import Distribution.Simple.Compiler
, OptimisationLevel(..), PackageDB(..), PackageDBStack
, Flag, extensionsToFlags )
import Distribution.Version
( Version(..), orLaterVersion )
( Version(..), anyVersion, orLaterVersion )
import Distribution.System
( OS(..), buildOS )
import Distribution.Verbosity
......@@ -130,20 +131,19 @@ configure :: Verbosity -> Maybe FilePath -> Maybe FilePath
-> ProgramConfiguration -> IO (Compiler, ProgramConfiguration)
configure verbosity hcPath hcPkgPath conf = do
(ghcProg, conf') <- requireProgram verbosity ghcProgram
(orLaterVersion (Version [6,4] []))
(userMaybeSpecifyPath "ghc" hcPath conf)
let Just ghcVersion = programVersion ghcProg
(ghcProg, ghcVersion, conf') <-
requireProgramVersion verbosity ghcProgram
(orLaterVersion (Version [6,4] []))
(userMaybeSpecifyPath "ghc" hcPath conf)
-- This is slightly tricky, we have to configure ghc first, then we use the
-- location of ghc to help find ghc-pkg in the case that the user did not
-- specify the location of ghc-pkg directly:
(ghcPkgProg, conf'') <- requireProgram verbosity ghcPkgProgram {
programFindLocation = guessGhcPkgFromGhcPath ghcProg
}
(orLaterVersion (Version [0] []))
(userMaybeSpecifyPath "ghc-pkg" hcPkgPath conf')
let Just ghcPkgVersion = programVersion ghcPkgProg
(ghcPkgProg, ghcPkgVersion, conf'') <-
requireProgramVersion verbosity ghcPkgProgram {
programFindLocation = guessGhcPkgFromGhcPath ghcProg
}
anyVersion (userMaybeSpecifyPath "ghc-pkg" hcPkgPath conf')
when (ghcVersion /= ghcPkgVersion) $ die $
"Version mismatch between ghc and ghc-pkg: "
......
......@@ -61,7 +61,7 @@ import Distribution.PackageDescription as PD
import Distribution.Simple.Compiler
( Compiler(..), compilerVersion )
import Distribution.Simple.Program
( ConfiguredProgram(..), requireProgram
( ConfiguredProgram(..), requireProgramVersion
, rawSystemProgram, rawSystemProgramStdoutConf, rawSystemProgramStdout
, hscolourProgram, haddockProgram, ghcProgram )
import Distribution.Simple.PreProcess (ppCpp', ppUnlit,
......@@ -154,11 +154,11 @@ haddock pkg_descr _ _ haddockFlags
haddock pkg_descr lbi suffixes flags = do
setupMessage verbosity "Running Haddock for" (packageId pkg_descr)
(confHaddock, _) <- requireProgram verbosity haddockProgram
(orLaterVersion (Version [0,6] [])) (withPrograms lbi)
(confHaddock, version, _) <-
requireProgramVersion verbosity haddockProgram
(orLaterVersion (Version [0,6] [])) (withPrograms lbi)
-- various sanity checks
let Just version = programVersion confHaddock
let isVersion2 = version >= Version [2,0] []
when ( flag haddockHoogle
......@@ -458,8 +458,10 @@ hscolour' :: PackageDescription
-> IO ()
hscolour' pkg_descr lbi flags = do
let distPref = fromFlag $ hscolourDistPref flags
(hscolourProg, _) <- requireProgram verbosity hscolourProgram
(orLaterVersion (Version [1,8] [])) (withPrograms lbi)
(hscolourProg, _, _) <-
requireProgramVersion
verbosity hscolourProgram
(orLaterVersion (Version [1,8] [])) (withPrograms lbi)
setupMessage verbosity "Running hscolour for" (packageId pkg_descr)
createDirectoryIfMissingVerbose verbosity True $ hscolourPref distPref pkg_descr
......
......@@ -97,9 +97,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
(userMaybeSpecifyPath "ffihugs" hcPath conf)
(_hugsProg, conf'') <- requireProgram verbosity hugsProgram anyVersion conf'
(_hugsProg, conf'') <- requireProgram verbosity hugsProgram conf'
let comp = Compiler {
compilerId = CompilerId Hugs (Version [] []),
......
......@@ -63,10 +63,10 @@ import Distribution.Simple.Compiler
( CompilerFlavor(..), CompilerId(..), Compiler(..)
, PackageDB(..), PackageDBStack, Flag, extensionsToFlags )
import Language.Haskell.Extension (Extension(..))
import Distribution.Simple.Program ( ConfiguredProgram(..), jhcProgram,
ProgramConfiguration, userMaybeSpecifyPath,
requireProgram, lookupProgram,
rawSystemProgram, rawSystemProgramStdoutConf )
import Distribution.Simple.Program
( ConfiguredProgram(..), jhcProgram, ProgramConfiguration
, userMaybeSpecifyPath, requireProgramVersion, lookupProgram
, rawSystemProgram, rawSystemProgramStdoutConf )
import Distribution.Version ( anyVersion )
import Distribution.Package
( Package(..) )
......@@ -93,8 +93,8 @@ configure :: Verbosity -> Maybe FilePath -> Maybe FilePath
-> ProgramConfiguration -> IO (Compiler, ProgramConfiguration)
configure verbosity hcPath _hcPkgPath conf = do
(jhcProg, conf') <- requireProgram verbosity jhcProgram anyVersion
(userMaybeSpecifyPath "jhc" hcPath conf)
(jhcProg, _, conf') <- requireProgramVersion verbosity jhcProgram anyVersion
(userMaybeSpecifyPath "jhc" hcPath conf)
let Just version = programVersion jhcProg
comp = Compiler {
......
......@@ -92,7 +92,8 @@ import qualified Distribution.ModuleName as ModuleName
import Distribution.Simple.Program
( Program(..), ConfiguredProgram(..), ProgramConfiguration, ProgArg
, ProgramLocation(..), rawSystemProgram, rawSystemProgramConf
, rawSystemProgramStdout, rawSystemProgramStdoutConf, requireProgram
, rawSystemProgramStdout, rawSystemProgramStdoutConf
, requireProgramVersion
, userMaybeSpecifyPath, programPath, lookupProgram, addKnownProgram
, arProgram, ranlibProgram, ldProgram
, gccProgram, stripProgram
......@@ -102,7 +103,7 @@ import Distribution.Simple.Compiler
, OptimisationLevel(..), PackageDB(..), PackageDBStack
, Flag, extensionsToFlags )
import Distribution.Version
( Version(..), orLaterVersion )
( Version(..), anyVersion, orLaterVersion )
import Distribution.System
( OS(..), buildOS )
import Distribution.Verbosity
......@@ -129,15 +130,15 @@ configure :: Verbosity -> Maybe FilePath -> Maybe FilePath
-> ProgramConfiguration -> IO (Compiler, ProgramConfiguration)
configure verbosity hcPath hcPkgPath conf = do
(lhcProg, conf') <- requireProgram verbosity lhcProgram
(orLaterVersion (Version [0,7] []))
(userMaybeSpecifyPath "lhc" hcPath conf)
let Just lhcVersion = programVersion lhcProg
(lhcProg, lhcVersion, conf') <-
requireProgramVersion verbosity lhcProgram
(orLaterVersion (Version [0,7] []))
(userMaybeSpecifyPath "lhc" hcPath conf)
(lhcPkgProg, conf'') <- requireProgram verbosity lhcPkgProgram
(orLaterVersion (Version [0,7] []))
(userMaybeSpecifyPath "lhc-pkg" hcPkgPath conf')
let Just lhcPkgVersion = programVersion lhcPkgProg
(lhcPkgProg, lhcPkgVersion, conf'') <-
requireProgramVersion verbosity lhcPkgProgram
(orLaterVersion (Version [0,7] []))
(userMaybeSpecifyPath "lhc-pkg" hcPkgPath conf')
when (lhcVersion /= lhcPkgVersion) $ die $
"Version mismatch between lhc and lhc-pkg: "
......
......@@ -63,16 +63,16 @@ import Distribution.Simple.Compiler
import Language.Haskell.Extension
( Extension(..) )
import Distribution.Simple.Program
( ProgramConfiguration, userMaybeSpecifyPath, requireProgram,
lookupProgram, ConfiguredProgram(programVersion), programPath,
nhcProgram, hmakeProgram, ldProgram, arProgram,
rawSystemProgramConf )
( ProgramConfiguration, userMaybeSpecifyPath, programPath
, requireProgram, requireProgramVersion, lookupProgram
, nhcProgram, hmakeProgram, ldProgram, arProgram
, rawSystemProgramConf )
import Distribution.Simple.Utils
( die, info, findFileWithExtension, findModuleFiles
, installOrdinaryFile, installExecutableFile, installOrdinaryFiles
, createDirectoryIfMissingVerbose )
import Distribution.Version
( Version(..), anyVersion, orLaterVersion )
( Version(..), orLaterVersion )
import Distribution.Verbosity
import Distribution.Text
( display )
......@@ -93,15 +93,16 @@ configure :: Verbosity -> Maybe FilePath -> Maybe FilePath
-> ProgramConfiguration -> IO (Compiler, ProgramConfiguration)
configure verbosity hcPath _hcPkgPath conf = do
(nhcProg, conf') <- requireProgram verbosity nhcProgram
(orLaterVersion (Version [1,20] []))
(userMaybeSpecifyPath "nhc98" hcPath conf)
let Just nhcVersion = programVersion nhcProg
(_nhcProg, nhcVersion, conf') <-
requireProgramVersion verbosity nhcProgram
(orLaterVersion (Version [1,20] []))
(userMaybeSpecifyPath "nhc98" hcPath conf)
(_hmakeProg, conf'') <- requireProgram verbosity hmakeProgram
(orLaterVersion (Version [3,13] [])) conf'
(_ldProg, conf''') <- requireProgram verbosity ldProgram anyVersion conf''
(_arProg, conf'''') <- requireProgram verbosity arProgram anyVersion conf'''
(_hmakeProg, _hmakeVersion, conf'') <-
requireProgramVersion verbosity hmakeProgram
(orLaterVersion (Version [3,13] [])) conf'
(_ldProg, conf''') <- requireProgram verbosity ldProgram conf''
(_arProg, conf'''') <- requireProgram verbosity arProgram conf'''
--TODO: put this stuff in a monad so we can say just:
-- requireProgram hmakeProgram (orLaterVersion (Version [3,13] []))
......
......@@ -71,6 +71,7 @@ module Distribution.Simple.Program (
, configureAllKnownPrograms
, reconfigurePrograms
, requireProgram
, requireProgramVersion
, rawSystemProgramConf
, rawSystemProgramStdoutConf
......@@ -462,14 +463,39 @@ reconfigurePrograms verbosity paths argss conf = do
-- | Check that a program is configured and available to be run.
--
-- Additionally check that the version of the program number is suitable.
-- For example 'AnyVersion' or @'orLaterVersion' ('Version' [1,0] [])@
-- It raises an exception if the program could not be configured, otherwise
-- it returns the configured program.
--
-- It raises an exception if the program could not be configured or the version
-- is unsuitable, otherwise it returns the configured program.
requireProgram :: Verbosity -> Program -> VersionRange -> ProgramConfiguration
requireProgram :: Verbosity -> Program -> ProgramConfiguration
-> IO (ConfiguredProgram, ProgramConfiguration)
requireProgram verbosity prog range conf = do
requireProgram verbosity prog conf = do
-- If it's not already been configured, try to configure it now
conf' <- case lookupProgram prog conf of
Nothing -> configureProgram verbosity prog conf
Just _ -> return conf
case lookupProgram prog conf' of
Nothing -> die notFound
Just configuredProg -> return (configuredProg, conf')
where notFound = programName prog
++ " is required but it could not be found."
-- | Check that a program is configured and available to be run.
--
-- Additionally check that the version of the program number is suitable and
-- return it. For example you could require 'AnyVersion' or
-- @'orLaterVersion' ('Version' [1,0] [])@
--
-- It raises an exception if the program could not be configured or the version
-- is unsuitable, otherwise it returns the configured program and its version
-- number.
--
requireProgramVersion :: Verbosity -> Program -> VersionRange
-> ProgramConfiguration
-> IO (ConfiguredProgram, Version, ProgramConfiguration)
requireProgramVersion verbosity prog range conf = do
-- If it's not already been configured, try to configure it now
conf' <- case lookupProgram prog conf of
......@@ -478,12 +504,10 @@ requireProgram verbosity prog range conf = do
case lookupProgram prog conf' of
Nothing -> die notFound
Just configuredProg
| isAnyVersion range -> return (configuredProg, conf')
Just configuredProg@ConfiguredProgram { programLocation = location } ->
case programVersion configuredProg of
Just version
| withinRange version range -> return (configuredProg, conf')
| withinRange version range -> return (configuredProg, version, conf')
| otherwise -> die (badVersion version location)
Nothing -> die (noVersion location)
......
......@@ -75,7 +75,7 @@ import Distribution.Package
import Distribution.ModuleName (ModuleName)
import qualified Distribution.ModuleName as ModuleName
import Distribution.Version
( Version(versionBranch), anyVersion )
( Version(versionBranch) )
import Distribution.Simple.Utils
( createDirectoryIfMissingVerbose, withUTF8FileContents, writeUTF8File
, copyFiles, copyFileVerbose
......@@ -294,7 +294,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
(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