1 -----------------------------------------------------------------------------
4 -- Module : Distribution.Simple.Program.Internal
6 -- Maintainer : cabal-devel@haskell.org
7 -- Portability : portable
9 -- Internal utilities used by Distribution.Simple.Program.*.
10 module Distribution
.Simple
.Program
.Internal
14 import Distribution
.Compat
.Prelude
15 import Distribution
.Utils
.Generic
(safeTail
)
18 -- | Extract the version number from the output of 'strip --version'.
20 -- Invoking "strip --version" gives very inconsistent results. We ignore
21 -- everything in parentheses (see #2497), look for the first word that starts
22 -- with a number, and try parsing out the first two components of it. Non-GNU
23 -- 'strip' doesn't appear to have a version flag.
24 stripExtractVersion
:: String -> String
25 stripExtractVersion str
=
26 let numeric
"" = False
27 numeric
(x
: _
) = isDigit x
29 -- Filter out everything in parentheses.
30 filterPar
' :: Int -> [String] -> [String]
33 | n
>= 0 && "(" `
isPrefixOf` x
= filterPar
' (n
+ 1) ((safeTail x
) : xs
)
34 | n
> 0 && ")" `
isSuffixOf` x
= filterPar
' (n
- 1) xs
35 | n
> 0 = filterPar
' n xs
36 |
otherwise = x
: filterPar
' n xs
38 filterPar
= filterPar
' 0
39 in case dropWhile (not . numeric
) (filterPar
. words $ str
) of
41 -- take the first two version components
43 (major
, rest
) = break isDot ver
44 minor
= takeWhile isDigit (dropWhile isDot rest
)
45 in major
++ "." ++ minor