aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Richardson <everythingfunctional@protonmail.com>2020-12-10 18:43:30 -0600
committerBrad Richardson <everythingfunctional@protonmail.com>2020-12-10 18:43:30 -0600
commit1986edbbfa012d6bbe8ddbd9f1c487a901f587d8 (patch)
tree2cc4b457239fbf9868ca9817c0665e3c6a556026
parent3ec6e97ccb77e01c55185d7d5a823b402f3ffca3 (diff)
downloadfpm-1986edbbfa012d6bbe8ddbd9f1c487a901f587d8.tar.gz
fpm-1986edbbfa012d6bbe8ddbd9f1c487a901f587d8.zip
feat(bootstrap): try multiple ways to get compiler version info
-rw-r--r--bootstrap/src/Fpm.hs19
1 files changed, 18 insertions, 1 deletions
diff --git a/bootstrap/src/Fpm.hs b/bootstrap/src/Fpm.hs
index 6acf82b..443d083 100644
--- a/bootstrap/src/Fpm.hs
+++ b/bootstrap/src/Fpm.hs
@@ -71,6 +71,7 @@ import System.Exit ( ExitCode(..)
, exitWith
)
import System.Process ( readProcess
+ , readProcessWithExitCode
, system
)
import Toml ( TomlCodec
@@ -928,7 +929,23 @@ makeBuildPrefix :: FilePath -> [String] -> IO FilePath
makeBuildPrefix compiler flags = do
-- TODO Figure out what other info should be part of this
-- Probably version, and make sure to not include path to the compiler
- versionInfo <- readProcess compiler ["--version"] []
+ versionInfo <- do
+ (exitCode, stdout, stderr) <- readProcessWithExitCode compiler
+ ["--version"]
+ []
+ case exitCode of
+ ExitSuccess -> case stdout of
+ "" -> return stderr -- Guess this compiler outputs version info to stderr instead?
+ _ -> return stdout
+ _ -> do -- guess this compiler doesn't support the --version option. let's try -version
+ (exitCode, stdout, stderr) <- readProcessWithExitCode compiler
+ ["-version"]
+ []
+ case exitCode of
+ ExitSuccess -> case stdout of
+ "" -> return stderr -- Guess this compiler outputs version info to stderr instead?
+ _ -> return stdout
+ _ -> return "" -- Don't know how to get version info, we'll let defineCompilerSettings report it as unsupported
let compilerName = last (splitDirectories compiler)
let versionHash = abs (hash versionInfo)
let flagsHash = abs (hash flags)