Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Glasgow Haskell Compiler
Packages
Cabal
Commits
757d14e9
Commit
757d14e9
authored
Aug 31, 2014
by
Mikhail Glushenkov
Browse files
Add a non-throwing variant of 'requireProgramVersion'.
parent
b3a0e6da
Changes
2
Hide whitespace changes
Inline
Side-by-side
Cabal/Distribution/Simple/Program.hs
View file @
757d14e9
...
...
@@ -79,6 +79,7 @@ module Distribution.Simple.Program (
,
userSpecifyArgss
,
userSpecifiedArgs
,
lookupProgram
,
lookupProgramVersion
,
updateProgram
,
configureProgram
,
configureAllKnownPrograms
...
...
Cabal/Distribution/Simple/Program/Db.hs
View file @
757d14e9
...
...
@@ -50,6 +50,7 @@ module Distribution.Simple.Program.Db (
-- ** Query and manipulate the program db
configureProgram
,
configureAllKnownPrograms
,
lookupProgramVersion
,
reconfigurePrograms
,
requireProgram
,
requireProgramVersion
,
...
...
@@ -73,6 +74,7 @@ import Distribution.Verbosity
(
Verbosity
)
import
Data.Binary
(
Binary
(
..
))
import
Data.Functor
((
<$>
))
import
Data.List
(
foldl'
)
import
Data.Maybe
...
...
@@ -410,32 +412,35 @@ requireProgram verbosity prog conf = do
-- | 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] [])@
-- Additionally check that the
program version
number is suitable and
return
-- it. For example you could require 'AnyVersion' or
@'orLaterVersion'
-- ('Version' [1,0] [])@
--
-- It r
aises an exception if the program could not be configured or the version
--
is unsuitable, otherwise it returns the configured program and its
version
--
number
.
-- It r
eturns the configured program, its version number and a possibly updated
--
'ProgramDb'. If the program could not be configured or the
version
is
--
unsuitable, it returns an error value
.
--
requireProgramVersion
::
Verbosity
->
Program
->
Version
Range
->
ProgramDb
->
IO
(
ConfiguredProgram
,
Version
,
ProgramDb
)
require
ProgramVersion
verbosity
prog
range
conf
=
do
lookup
ProgramVersion
::
Verbosity
->
Program
->
VersionRange
->
ProgramDb
->
IO
(
Either
String
(
ConfiguredProgram
,
Version
,
ProgramDb
)
)
lookup
ProgramVersion
verbosity
prog
range
programDb
=
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
programDb
'
<-
case
lookupProgram
prog
programDb
of
Nothing
->
configureProgram
verbosity
prog
programDb
Just
_
->
return
programDb
case
lookupProgram
prog
conf
'
of
Nothing
->
die
notFound
case
lookupProgram
prog
programDb
'
of
Nothing
->
return
$!
Left
notFound
Just
configuredProg
@
ConfiguredProgram
{
programLocation
=
location
}
->
case
programVersion
configuredProg
of
Just
version
|
withinRange
version
range
->
return
(
configuredProg
,
version
,
conf'
)
|
otherwise
->
die
(
badVersion
version
location
)
Nothing
->
die
(
noVersion
location
)
|
withinRange
version
range
->
return
$!
Right
(
configuredProg
,
version
,
programDb'
)
|
otherwise
->
return
$!
Left
(
badVersion
version
location
)
Nothing
->
return
$!
Left
(
noVersion
location
)
where
notFound
=
"The program '"
++
programName
prog
++
"'"
++
versionRequirement
...
...
@@ -451,3 +456,13 @@ requireProgramVersion verbosity prog range conf = do
versionRequirement
|
isAnyVersion
range
=
""
|
otherwise
=
" version "
++
display
range
-- | Like 'lookupProgramVersion', but raises an exception in case of error
-- instead of returning 'Left errMsg'.
--
requireProgramVersion
::
Verbosity
->
Program
->
VersionRange
->
ProgramDb
->
IO
(
ConfiguredProgram
,
Version
,
ProgramDb
)
requireProgramVersion
verbosity
prog
range
programDb
=
join
$
either
die
return
<$>
lookupProgramVersion
verbosity
prog
range
programDb
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment