From 9636f2340152347b88350bd92f8ea3940593307d Mon Sep 17 00:00:00 2001 From: andys8 Date: Thu, 11 Aug 2022 19:21:14 +0200 Subject: [PATCH 1/5] Probe-tools: Print stack ghc version The ghc version on the $PATH is often not relevant for stack projects. The ghc version stack is using is printed in addition. --- src/Ide/Version.hs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Ide/Version.hs b/src/Ide/Version.hs index e963767087..af9e3ccd21 100644 --- a/src/Ide/Version.hs +++ b/src/Ide/Version.hs @@ -38,9 +38,10 @@ hlsVersion = hlsGhcDisplayVersion = compilerName ++ "-" ++ VERSION_ghc data ProgramsOfInterest = ProgramsOfInterest - { cabalVersion :: Maybe Version - , stackVersion :: Maybe Version - , ghcVersion :: Maybe Version + { cabalVersion :: Maybe Version + , stackVersion :: Maybe Version + , ghcVersion :: Maybe Version + , stackGhcVersion :: Maybe Version } showProgramVersionOfInterest :: ProgramsOfInterest -> String @@ -49,6 +50,7 @@ showProgramVersionOfInterest ProgramsOfInterest {..} = [ "cabal:\t\t" ++ showVersionWithDefault cabalVersion , "stack:\t\t" ++ showVersionWithDefault stackVersion , "ghc:\t\t" ++ showVersionWithDefault ghcVersion + , "stack ghc:\t" ++ showVersionWithDefault stackGhcVersion ] where showVersionWithDefault :: Maybe Version -> String @@ -56,19 +58,19 @@ showProgramVersionOfInterest ProgramsOfInterest {..} = findProgramVersions :: IO ProgramsOfInterest findProgramVersions = ProgramsOfInterest - <$> findVersionOf "cabal" - <*> findVersionOf "stack" - <*> findVersionOf "ghc" + <$> findVersionOf "cabal" ["--numeric-version"] + <*> findVersionOf "stack" ["--numeric-version"] + <*> findVersionOf "ghc" ["--numeric-version"] + <*> findVersionOf "stack" ["ghc", "--", "--numeric-version"] -- | Find the version of the given program. --- Assumes the program accepts the cli argument "--numeric-version". -- If the invocation has a non-zero exit-code, we return 'Nothing' -findVersionOf :: FilePath -> IO (Maybe Version) -findVersionOf tool = +findVersionOf :: FilePath -> [String] -> IO (Maybe Version) +findVersionOf tool args = findExecutable tool >>= \case Nothing -> pure Nothing Just path -> - readProcessWithExitCode path ["--numeric-version"] "" >>= \case + readProcessWithExitCode path args "" >>= \case (ExitSuccess, sout, _) -> pure $ consumeParser myVersionParser sout _ -> pure Nothing where From 49bde680024ff5674992bb61e2a9016a67d333e0 Mon Sep 17 00:00:00 2001 From: andys8 Date: Fri, 12 Aug 2022 14:11:24 +0200 Subject: [PATCH 2/5] Probetools: cradle ghc version added to wrapper --- exe/Wrapper.hs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/exe/Wrapper.hs b/exe/Wrapper.hs index 0122cf319f..2f1fef74c0 100644 --- a/exe/Wrapper.hs +++ b/exe/Wrapper.hs @@ -14,6 +14,7 @@ module Main where import Control.Monad.Extra import Data.Char (isSpace) import Data.Default +import Data.Either (fromRight) import Data.Foldable import Data.List import Data.Void @@ -79,6 +80,10 @@ main = do putStrLn hlsVer putStrLn "Tool versions found on the $PATH" putStrLn $ showProgramVersionOfInterest programsOfInterest + putStrLn "Tool versions found by cradle" + cradle <- findProjectCradle' False + ghcVersion <- runExceptT $ getRuntimeGhcVersion' cradle + putStrLn $ "ghc:\t\t" ++ fromRight "Not found" ghcVersion VersionMode PrintVersion -> putStrLn hlsVer From f66e9e8bf17c06e13ce7c6a8523edc53e55ab76a Mon Sep 17 00:00:00 2001 From: andys8 Date: Fri, 12 Aug 2022 14:24:40 +0200 Subject: [PATCH 3/5] Revert stack ghc changes to Ide.Main --- src/Ide/Version.hs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Ide/Version.hs b/src/Ide/Version.hs index af9e3ccd21..e963767087 100644 --- a/src/Ide/Version.hs +++ b/src/Ide/Version.hs @@ -38,10 +38,9 @@ hlsVersion = hlsGhcDisplayVersion = compilerName ++ "-" ++ VERSION_ghc data ProgramsOfInterest = ProgramsOfInterest - { cabalVersion :: Maybe Version - , stackVersion :: Maybe Version - , ghcVersion :: Maybe Version - , stackGhcVersion :: Maybe Version + { cabalVersion :: Maybe Version + , stackVersion :: Maybe Version + , ghcVersion :: Maybe Version } showProgramVersionOfInterest :: ProgramsOfInterest -> String @@ -50,7 +49,6 @@ showProgramVersionOfInterest ProgramsOfInterest {..} = [ "cabal:\t\t" ++ showVersionWithDefault cabalVersion , "stack:\t\t" ++ showVersionWithDefault stackVersion , "ghc:\t\t" ++ showVersionWithDefault ghcVersion - , "stack ghc:\t" ++ showVersionWithDefault stackGhcVersion ] where showVersionWithDefault :: Maybe Version -> String @@ -58,19 +56,19 @@ showProgramVersionOfInterest ProgramsOfInterest {..} = findProgramVersions :: IO ProgramsOfInterest findProgramVersions = ProgramsOfInterest - <$> findVersionOf "cabal" ["--numeric-version"] - <*> findVersionOf "stack" ["--numeric-version"] - <*> findVersionOf "ghc" ["--numeric-version"] - <*> findVersionOf "stack" ["ghc", "--", "--numeric-version"] + <$> findVersionOf "cabal" + <*> findVersionOf "stack" + <*> findVersionOf "ghc" -- | Find the version of the given program. +-- Assumes the program accepts the cli argument "--numeric-version". -- If the invocation has a non-zero exit-code, we return 'Nothing' -findVersionOf :: FilePath -> [String] -> IO (Maybe Version) -findVersionOf tool args = +findVersionOf :: FilePath -> IO (Maybe Version) +findVersionOf tool = findExecutable tool >>= \case Nothing -> pure Nothing Just path -> - readProcessWithExitCode path args "" >>= \case + readProcessWithExitCode path ["--numeric-version"] "" >>= \case (ExitSuccess, sout, _) -> pure $ consumeParser myVersionParser sout _ -> pure Nothing where From 13b0e15732a1f041fb5685b9767beffeb077571e Mon Sep 17 00:00:00 2001 From: Andy Date: Fri, 12 Aug 2022 14:48:50 +0200 Subject: [PATCH 4/5] Update exe/Wrapper.hs Co-authored-by: fendor --- exe/Wrapper.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exe/Wrapper.hs b/exe/Wrapper.hs index 2f1fef74c0..858266f915 100644 --- a/exe/Wrapper.hs +++ b/exe/Wrapper.hs @@ -80,7 +80,7 @@ main = do putStrLn hlsVer putStrLn "Tool versions found on the $PATH" putStrLn $ showProgramVersionOfInterest programsOfInterest - putStrLn "Tool versions found by cradle" + putStrLn "Tool versions in your project" cradle <- findProjectCradle' False ghcVersion <- runExceptT $ getRuntimeGhcVersion' cradle putStrLn $ "ghc:\t\t" ++ fromRight "Not found" ghcVersion From 6cfb60820ce25480310a34c7ca70546ce95f4076 Mon Sep 17 00:00:00 2001 From: andys8 Date: Fri, 12 Aug 2022 15:18:06 +0200 Subject: [PATCH 5/5] Probe tools: Print version with padded spaces Addressing --- exe/Wrapper.hs | 4 ++-- src/Ide/Version.hs | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/exe/Wrapper.hs b/exe/Wrapper.hs index 858266f915..e4f50f2ad4 100644 --- a/exe/Wrapper.hs +++ b/exe/Wrapper.hs @@ -14,7 +14,7 @@ module Main where import Control.Monad.Extra import Data.Char (isSpace) import Data.Default -import Data.Either (fromRight) +import Data.Either.Extra (eitherToMaybe) import Data.Foldable import Data.List import Data.Void @@ -83,7 +83,7 @@ main = do putStrLn "Tool versions in your project" cradle <- findProjectCradle' False ghcVersion <- runExceptT $ getRuntimeGhcVersion' cradle - putStrLn $ "ghc:\t\t" ++ fromRight "Not found" ghcVersion + putStrLn $ showProgramVersion "ghc" $ mkVersion =<< eitherToMaybe ghcVersion VersionMode PrintVersion -> putStrLn hlsVer diff --git a/src/Ide/Version.hs b/src/Ide/Version.hs index e963767087..1c67c0da46 100644 --- a/src/Ide/Version.hs +++ b/src/Ide/Version.hs @@ -46,13 +46,17 @@ data ProgramsOfInterest = ProgramsOfInterest showProgramVersionOfInterest :: ProgramsOfInterest -> String showProgramVersionOfInterest ProgramsOfInterest {..} = unlines - [ "cabal:\t\t" ++ showVersionWithDefault cabalVersion - , "stack:\t\t" ++ showVersionWithDefault stackVersion - , "ghc:\t\t" ++ showVersionWithDefault ghcVersion + [ showProgramVersion "cabal" cabalVersion + , showProgramVersion "stack" stackVersion + , showProgramVersion "ghc" ghcVersion ] + +showProgramVersion :: String -> Maybe Version -> String +showProgramVersion name version = + pad 16 (name ++ ":") ++ showVersionWithDefault version where - showVersionWithDefault :: Maybe Version -> String showVersionWithDefault = maybe "Not found" showVersion + pad n s = s ++ replicate (n - length s) ' ' findProgramVersions :: IO ProgramsOfInterest findProgramVersions = ProgramsOfInterest @@ -69,8 +73,11 @@ findVersionOf tool = Nothing -> pure Nothing Just path -> readProcessWithExitCode path ["--numeric-version"] "" >>= \case - (ExitSuccess, sout, _) -> pure $ consumeParser myVersionParser sout + (ExitSuccess, sout, _) -> pure $ mkVersion sout _ -> pure Nothing + +mkVersion :: String -> Maybe Version +mkVersion = consumeParser myVersionParser where myVersionParser = do skipSpaces @@ -79,4 +86,5 @@ findVersionOf tool = pure version consumeParser :: ReadP a -> String -> Maybe a - consumeParser p input = listToMaybe $ map fst . filter (null . snd) $ readP_to_S p input + consumeParser p input = + listToMaybe $ map fst . filter (null . snd) $ readP_to_S p input