Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse llvm-strip version #10787

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading