Skip to content

Commit

Permalink
Parse llvm-strip version
Browse files Browse the repository at this point in the history
  • Loading branch information
jasagredo committed Feb 9, 2025
1 parent 595d023 commit e1986d8
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Cabal/src/Distribution/Simple/Program/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,28 @@ import Prelude ()

-- | Extract the version number from the output of 'strip --version'.
--
-- Invoking "strip --version" gives very inconsistent results. We ignore
-- everything in parentheses (see #2497), look for the first word that starts
-- with a number, and try parsing out the first two components of it. Non-GNU
-- 'strip' doesn't appear to have a version flag.
-- Invoking "strip --version" gives very inconsistent results. We
-- ignore everything in parentheses (see #2497), look for the first
-- word that starts with a number, and try parsing out the first two
-- components of it. Non-GNU, non-LLVM 'strip' doesn't appear to have
-- a version flag.
stripExtractVersion :: String -> String
stripExtractVersion str =
let numeric "" = False
numeric (x : _) = isDigit x

closingParentheses = [
")"
-- LLVM strip outputs "llvm-strip, compatible with GNU strip\nLLVM (http://llvm.org/):\n..."
, "):"
]

-- Filter out everything in parentheses.
filterPar' :: Int -> [String] -> [String]
filterPar' _ [] = []
filterPar' n (x : xs)
| n >= 0 && "(" `isPrefixOf` x = filterPar' (n + 1) ((safeTail x) : xs)
| n > 0 && ")" `isSuffixOf` x = filterPar' (n - 1) xs
| n > 0 && any (`isSuffixOf` x) closingParentheses = filterPar' (n - 1) xs
| n > 0 = filterPar' n xs
| otherwise = x : filterPar' n xs

Expand Down

0 comments on commit e1986d8

Please sign in to comment.