From 1cb4d8aa534a304c066cc91b64144394602b4237 Mon Sep 17 00:00:00 2001 From: brandon s allbery kf8nh Date: Thu, 11 Dec 2025 15:56:29 -0500 Subject: [PATCH] add `--version-full` and compiler info This may count as "significant" since it's a new command line option, but it's deliberately out of the way. --- Cabal/Cabal.cabal | 1 + Cabal/src/Distribution/Compat/SysInfo.hs | 15 +++++++++++++++ Cabal/src/Distribution/Make.hs | 11 +++++++++++ Cabal/src/Distribution/Simple.hs | 12 +++++++++++- Cabal/src/Distribution/Simple/Setup/Global.hs | 9 +++++++++ Cabal/src/Distribution/Simple/Utils.hs | 19 +++++++++++++++++++ .../src/Distribution/Client/Config.hs | 1 + .../src/Distribution/Client/GlobalFlags.hs | 2 ++ cabal-install/src/Distribution/Client/Main.hs | 14 ++++++++++++++ .../Client/ProjectConfig/Legacy.hs | 1 + .../src/Distribution/Client/Setup.hs | 7 +++++++ .../src/Distribution/Client/Version.hs | 18 ++++++++++++++++++ changelog.d/pr-11339 | 13 +++++++++++++ 13 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 Cabal/src/Distribution/Compat/SysInfo.hs create mode 100644 changelog.d/pr-11339 diff --git a/Cabal/Cabal.cabal b/Cabal/Cabal.cabal index 55dd7ff5053..5777f2ced85 100644 --- a/Cabal/Cabal.cabal +++ b/Cabal/Cabal.cabal @@ -100,6 +100,7 @@ library Distribution.Compat.Prelude.Internal Distribution.Compat.Process Distribution.Compat.Stack + Distribution.Compat.SysInfo Distribution.Compat.Time Distribution.Make Distribution.PackageDescription.Check diff --git a/Cabal/src/Distribution/Compat/SysInfo.hs b/Cabal/src/Distribution/Compat/SysInfo.hs new file mode 100644 index 00000000000..28ceed7f415 --- /dev/null +++ b/Cabal/src/Distribution/Compat/SysInfo.hs @@ -0,0 +1,15 @@ +{-# LANGUAGE CPP #-} + +module Distribution.Compat.SysInfo + ( fullCompilerVersion + ) where + +import Data.Version (Version) +import qualified System.Info as SI + +fullCompilerVersion :: Version +#if MIN_VERSION_base(4,15,0) +fullCompilerVersion = SI.fullCompilerVersion +#else +fullCompilerVersion = SI.compilerVersion +#endif diff --git a/Cabal/src/Distribution/Make.hs b/Cabal/src/Distribution/Make.hs index 1568abaac60..db982cae835 100644 --- a/Cabal/src/Distribution/Make.hs +++ b/Cabal/src/Distribution/Make.hs @@ -96,6 +96,7 @@ defaultMainHelper args = do case commandParse of _ | fromFlag (globalVersion flags) -> printVersion + | fromFlag (globalFullVersion flags) -> printFullVersion | fromFlag (globalNumericVersion flags) -> printNumericVersion CommandHelp help -> printHelp help CommandList opts -> printOptionsList opts @@ -112,6 +113,16 @@ defaultMainHelper args = do putStrLn $ "Cabal library version " ++ prettyShow cabalVersion + printFullVersion = + putStrLn $ + "Cabal library version " + ++ prettyShow cabalVersion + ++ cabalGitInfo' + ++ "\nwith " + ++ cabalCompilerInfo + cabalGitInfo' + | null cabalGitInfo = [] + | otherwise = ' ' : cabalGitInfo progs = defaultProgramDb commands = [ configureCommand progs `commandAddAction` configureAction diff --git a/Cabal/src/Distribution/Simple.hs b/Cabal/src/Distribution/Simple.hs index 3a7ffbfdf39..2f16fab0fa6 100644 --- a/Cabal/src/Distribution/Simple.hs +++ b/Cabal/src/Distribution/Simple.hs @@ -293,6 +293,7 @@ defaultMainHelper hooks args = topHandler (isUserException (Proxy @(VerboseExcep case commandParse of _ | fromFlag (globalVersion globalFlags) -> printVersion + | fromFlag (globalFullVersion globalFlags) -> printFullVersion | fromFlag (globalNumericVersion globalFlags) -> printNumericVersion CommandHelp help -> printHelp help CommandList opts -> printOptionsList opts @@ -309,7 +310,16 @@ defaultMainHelper hooks args = topHandler (isUserException (Proxy @(VerboseExcep putStrLn $ "Cabal library version " ++ prettyShow cabalVersion - + printFullVersion = + putStrLn $ + "Cabal library version " + ++ prettyShow cabalVersion + ++ cabalGitInfo' + ++ "\nwith " + ++ cabalCompilerInfo + cabalGitInfo' + | null cabalGitInfo = [] + | otherwise = ' ' : cabalGitInfo progs = addKnownPrograms (hookedPrograms hooks) defaultProgramDb addAction :: CommandUI flags -> (GlobalFlags -> UserHooks -> flags -> [String] -> IO res) -> Command (GlobalFlags -> IO ()) addAction cmd action = diff --git a/Cabal/src/Distribution/Simple/Setup/Global.hs b/Cabal/src/Distribution/Simple/Setup/Global.hs index fa7994b39ec..1608dc60b99 100644 --- a/Cabal/src/Distribution/Simple/Setup/Global.hs +++ b/Cabal/src/Distribution/Simple/Setup/Global.hs @@ -44,6 +44,7 @@ import Distribution.Utils.Path -- | Flags that apply at the top level, not to any sub-command. data GlobalFlags = GlobalFlags { globalVersion :: Flag Bool + , globalFullVersion :: Flag Bool , globalNumericVersion :: Flag Bool , globalWorkingDir :: Flag (SymbolicPath CWD (Dir Pkg)) } @@ -53,6 +54,7 @@ defaultGlobalFlags :: GlobalFlags defaultGlobalFlags = GlobalFlags { globalVersion = Flag False + , globalFullVersion = Flag False , globalNumericVersion = Flag False , globalWorkingDir = NoFlag } @@ -101,6 +103,13 @@ globalCommand commands = globalVersion (\v flags -> flags{globalVersion = v}) trueArg + , option + [] + ["version-full"] + "Print the version, Git revision if available, and compiler information" + globalFullVersion + (\v flags -> flags{globalFullVersion = v}) + trueArg , option [] ["numeric-version"] diff --git a/Cabal/src/Distribution/Simple/Utils.hs b/Cabal/src/Distribution/Simple/Utils.hs index 0992009459e..dcd5e5f07b6 100644 --- a/Cabal/src/Distribution/Simple/Utils.hs +++ b/Cabal/src/Distribution/Simple/Utils.hs @@ -33,6 +33,7 @@ module Distribution.Simple.Utils ( cabalVersion , cabalGitInfo + , cabalCompilerInfo -- * logging and errors , dieNoVerbosity @@ -213,6 +214,7 @@ import Distribution.Compat.Internal.TempFile import Distribution.Compat.Lens (Lens', over) import Distribution.Compat.Prelude import Distribution.Compat.Stack +import Distribution.Compat.SysInfo as SIC import Distribution.ModuleName as ModuleName import Distribution.Simple.Errors import Distribution.Simple.PreProcess.Types @@ -244,6 +246,7 @@ import Data.Typeable import qualified Control.Exception as Exception import Data.Time.Clock.POSIX (POSIXTime, getPOSIXTime) +import qualified Data.Version as DV import Distribution.Compat.Process (proc) import Foreign.C.Error (Errno (..), ePIPE) import qualified GHC.IO.Exception as GHC @@ -293,6 +296,7 @@ import System.IO.Error import System.IO.Unsafe ( unsafeInterleaveIO ) +import qualified System.Info as SI import qualified System.Process as Process import qualified Text.PrettyPrint as Disp @@ -344,6 +348,21 @@ cabalGitInfo = if giHash' == "" cabalGitInfo = "" #endif +-- | +-- `Cabal` compiler information, reported by `--version-full` but otherwise +-- unused. +cabalCompilerInfo :: String +cabalCompilerInfo = + concat + [ SI.compilerName + , " " + , intercalate "." (map show (DV.versionBranch SIC.fullCompilerVersion)) + , " on " + , SI.os + , " " + , SI.arch + ] + -- ---------------------------------------------------------------------------- -- Exception and logging utils diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index 9036932b6b2..3a71c384e24 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -358,6 +358,7 @@ instance Semigroup SavedConfig where combinedSavedGlobalFlags = GlobalFlags { globalVersion = combine globalVersion + , globalFullVersion = combine globalFullVersion , globalNumericVersion = combine globalNumericVersion , globalConfigFile = combine globalConfigFile , globalConstraintsFile = combine globalConstraintsFile diff --git a/cabal-install/src/Distribution/Client/GlobalFlags.hs b/cabal-install/src/Distribution/Client/GlobalFlags.hs index 885fc191bca..af796bbe241 100644 --- a/cabal-install/src/Distribution/Client/GlobalFlags.hs +++ b/cabal-install/src/Distribution/Client/GlobalFlags.hs @@ -81,6 +81,7 @@ import qualified Hackage.Security.Util.Pretty as Sec -- | Flags that apply at the top level, not to any sub-command. data GlobalFlags = GlobalFlags { globalVersion :: Flag Bool + , globalFullVersion :: Flag Bool , globalNumericVersion :: Flag Bool , globalConfigFile :: Flag FilePath , globalConstraintsFile :: Flag FilePath @@ -103,6 +104,7 @@ defaultGlobalFlags :: GlobalFlags defaultGlobalFlags = GlobalFlags { globalVersion = Flag False + , globalFullVersion = Flag False , globalNumericVersion = Flag False , globalConfigFile = mempty , globalConstraintsFile = mempty diff --git a/cabal-install/src/Distribution/Client/Main.hs b/cabal-install/src/Distribution/Client/Main.hs index 7583369cda2..ade10b87705 100644 --- a/cabal-install/src/Distribution/Client/Main.hs +++ b/cabal-install/src/Distribution/Client/Main.hs @@ -226,6 +226,7 @@ import Distribution.Simple.Program.Db (reconfigurePrograms) import qualified Distribution.Simple.Setup as Cabal import Distribution.Simple.Utils ( VerboseException + , cabalCompilerInfo , cabalGitInfo , cabalVersion , createDirectoryIfMissingVerbose @@ -346,6 +347,8 @@ mainWorker args = do _ | fromFlagOrDefault False (globalVersion globalFlags) -> printVersion + | fromFlagOrDefault False (globalFullVersion globalFlags) -> + printFullVersion | fromFlagOrDefault False (globalNumericVersion globalFlags) -> printNumericVersion CommandHelp help -> printCommandHelp help @@ -415,6 +418,13 @@ mainWorker args = do printErrors errs = dieNoVerbosity $ intercalate "\n" errs printNumericVersion = putStrLn $ display cabalInstallVersion printVersion = + putStrLn $ + "cabal-install version " + ++ display cabalInstallVersion + ++ "\ncompiled using version " + ++ display cabalVersion + ++ " of the Cabal library " + printFullVersion = putStrLn $ "cabal-install version " ++ display cabalInstallVersion @@ -423,6 +433,10 @@ mainWorker args = do ++ display cabalVersion ++ " of the Cabal library " ++ cabalGitInfo' + ++ "\nwith " + -- it's impossible for cabal-install to have been built with a different compiler + -- from Cabal, so just reuse its info + ++ cabalCompilerInfo where cabalInstallGitInfo' | null cabalInstallGitInfo = "" diff --git a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs b/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs index 37ffb185db1..fcd8333c498 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs @@ -984,6 +984,7 @@ convertToLegacySharedConfig globalFlags = GlobalFlags { globalVersion = mempty + , globalFullVersion = mempty , globalNumericVersion = mempty , globalConfigFile = projectConfigConfigFile , globalConstraintsFile = mempty diff --git a/cabal-install/src/Distribution/Client/Setup.hs b/cabal-install/src/Distribution/Client/Setup.hs index 148633d20a4..08bc3e1fc37 100644 --- a/cabal-install/src/Distribution/Client/Setup.hs +++ b/cabal-install/src/Distribution/Client/Setup.hs @@ -487,6 +487,13 @@ globalCommand commands = globalVersion (\v flags -> flags{globalVersion = v}) trueArg + , option + [] + ["version-full"] + "Print full version information with git revision (if available) and compiler" + globalFullVersion + (\v flags -> flags{globalFullVersion = v}) + trueArg , option [] ["numeric-version"] diff --git a/cabal-install/src/Distribution/Client/Version.hs b/cabal-install/src/Distribution/Client/Version.hs index ea8c7be9b57..af9545c3825 100644 --- a/cabal-install/src/Distribution/Client/Version.hs +++ b/cabal-install/src/Distribution/Client/Version.hs @@ -9,7 +9,11 @@ module Distribution.Client.Version , cabalInstallGitInfo ) where +import Data.List (intercalate) +import qualified Data.Version as DV +import qualified Distribution.Compat.SysInfo as SIC import Distribution.Version +import qualified System.Info as SI import qualified Paths_cabal_install as PackageInfo @@ -28,6 +32,20 @@ import GitHash cabalInstallVersion :: Version cabalInstallVersion = mkVersion' PackageInfo.version +-- | +-- `cabal-install` compiler information. +cabalInstallCompilerInfo :: String +cabalInstallCompilerInfo = + concat + [ SI.compilerName + , " " + , intercalate "." (map show (DV.versionBranch SIC.fullCompilerVersion)) + , " on " + , SI.os + , " " + , SI.arch + ] + -- | -- `cabal-install` Git information. Only filled in if built in a Git tree in -- development mode and Template Haskell is available. diff --git a/changelog.d/pr-11339 b/changelog.d/pr-11339 new file mode 100644 index 00000000000..529c84e995a --- /dev/null +++ b/changelog.d/pr-11339 @@ -0,0 +1,13 @@ +--- +synopsis: Add `--version-full` option and move additional version information to it +packages: [Cabal, cabal-install] +prs: 11339 +--- + +A new option `--version-full` has been added to `cabal` and `Setup.hs`. The previously added git revision information has been moved to it, and compiler and host information added to it. + +The `--version` option now reports the same information it originally did, in case scripts were relying on its output. + +Git revision information still is not provided for release builds, largely to avoid bootstrapping issues when building GHC. (Both cabal-install (not distributed, but used by hadrian) and the Cabal library are built as part of GHC builds.) + +This _shouldn't_ affect most people, unless someone has been relying on the output of `--version` instead of using `--numeric-version`; but they would have been forced to support both output forms, and that only if supporting unreleased cabal builds.