Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Cabal/Cabal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions Cabal/src/Distribution/Compat/SysInfo.hs
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions Cabal/src/Distribution/Make.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion Cabal/src/Distribution/Simple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 =
Expand Down
9 changes: 9 additions & 0 deletions Cabal/src/Distribution/Simple/Setup/Global.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -53,6 +54,7 @@ defaultGlobalFlags :: GlobalFlags
defaultGlobalFlags =
GlobalFlags
{ globalVersion = Flag False
, globalFullVersion = Flag False
, globalNumericVersion = Flag False
, globalWorkingDir = NoFlag
}
Expand Down Expand Up @@ -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"]
Expand Down
19 changes: 19 additions & 0 deletions Cabal/src/Distribution/Simple/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
module Distribution.Simple.Utils
( cabalVersion
, cabalGitInfo
, cabalCompilerInfo

-- * logging and errors
, dieNoVerbosity
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions cabal-install/src/Distribution/Client/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/src/Distribution/Client/GlobalFlags.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -103,6 +104,7 @@ defaultGlobalFlags :: GlobalFlags
defaultGlobalFlags =
GlobalFlags
{ globalVersion = Flag False
, globalFullVersion = Flag False
, globalNumericVersion = Flag False
, globalConfigFile = mempty
, globalConstraintsFile = mempty
Expand Down
14 changes: 14 additions & 0 deletions cabal-install/src/Distribution/Client/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,7 @@ convertToLegacySharedConfig
globalFlags =
GlobalFlags
{ globalVersion = mempty
, globalFullVersion = mempty
, globalNumericVersion = mempty
, globalConfigFile = projectConfigConfigFile
, globalConstraintsFile = mempty
Expand Down
7 changes: 7 additions & 0 deletions cabal-install/src/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
18 changes: 18 additions & 0 deletions cabal-install/src/Distribution/Client/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions changelog.d/pr-11339
Original file line number Diff line number Diff line change
@@ -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.
Loading