Skip to content

Commit

Permalink
Merge branch 'master' into max-ghc-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ulysses4ever authored Dec 23, 2024
2 parents fe71001 + e552957 commit 5d44962
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-sdist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
# release of a corresponding Cabal and friends. it can also be short since it's
# highly unlikely that we are releasing really old branches.
ghc:
["9.10.1", "9.8.1", "9.6.1"]
["9.12.1", "9.10.1", "9.8.1", "9.6.1"]

steps:

Expand Down
9 changes: 9 additions & 0 deletions Cabal/Cabal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ source-repository head
location: https://github.com/haskell/cabal/
subdir: Cabal

flag git-rev
description: include Git revision hash in version
default: False
manual: True

library
default-language: Haskell2010
hs-source-dirs: src
Expand All @@ -51,6 +56,10 @@ library
else
build-depends: unix >= 2.6.0.0 && < 2.9

if flag(git-rev)
build-depends: githash ^>= 0.1.7.0
cpp-options: -DGIT_REV

ghc-options:
-Wall
-fno-ignore-asserts
Expand Down
3 changes: 2 additions & 1 deletion Cabal/src/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ module Distribution.Simple.GHC
, getImplInfo
, GhcImplInfo (..)
) where

if arch(arm) || arch(i386)
constraints: unix >= 2.8.6.0
import Distribution.Compat.Prelude

Check failure on line 84 in Cabal/src/Distribution/Simple/GHC.hs

View workflow job for this annotation

GitHub Actions / hlint

Error: Parse error: on input `import' ▫︎ Found: " if arch(arm) || arch(i386)\n constraints: unix >= 2.8.6.0\n> import Distribution.Compat.Prelude\n import Prelude ()\n"
import Prelude ()

Expand Down
36 changes: 36 additions & 0 deletions Cabal/src/Distribution/Simple/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
#ifdef GIT_REV
{-# LANGUAGE TemplateHaskell #-}
#endif

-----------------------------------------------------------------------------

Expand All @@ -26,6 +29,7 @@
-- various directory and file functions that do extra logging.
module Distribution.Simple.Utils
( cabalVersion
, cabalGitInfo

-- * logging and errors
, dieNoVerbosity
Expand Down Expand Up @@ -285,6 +289,16 @@ import System.IO.Unsafe
import qualified System.Process as Process
import qualified Text.PrettyPrint as Disp

#ifdef GIT_REV
import Data.Either (isLeft)
import GitHash
( giHash
, giBranch
, giCommitDate
, tGitInfoCwdTry
)
#endif

-- We only get our own version number when we're building with ourselves
cabalVersion :: Version
#if defined(BOOTSTRAPPED_CABAL)
Expand All @@ -295,6 +309,28 @@ cabalVersion = mkVersion [CABAL_VERSION]
cabalVersion = mkVersion [3,0] --used when bootstrapping
#endif

-- |
-- `Cabal` Git information. Only filled in if built in a Git tree in
-- developmnent mode and Template Haskell is available.
cabalGitInfo :: String
#ifdef GIT_REV
cabalGitInfo = concat [ "(commit "
, giHash'
, branchInfo
, ", "
, either (const "") giCommitDate gi'
, ")"
]
where
gi' = $$tGitInfoCwdTry
giHash' = take 7 . either (const "") giHash $ gi'
branchInfo | isLeft gi' = ""
| either id giBranch gi' == "master" = ""
| otherwise = " on " <> either id giBranch gi'
#else
cabalGitInfo = ""
#endif

-- ----------------------------------------------------------------------------
-- Exception and logging utils

Expand Down
11 changes: 11 additions & 0 deletions cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ Flag lukko
default: True
manual: True

flag git-rev
description: include Git revision hash in version
default: False
manual: True

common warnings
ghc-options:
-Wall
Expand Down Expand Up @@ -269,6 +274,9 @@ library
if impl(ghc >=8.2)
build-depends: process >= 1.6.15.0

if flag(git-rev)
build-depends: githash ^>= 0.1.7.0
cpp-options: -DGIT_REV

executable cabal
import: warnings, base-dep
Expand All @@ -282,6 +290,9 @@ executable cabal
if os(aix)
extra-libraries: bsd

if flag(git-rev)
cpp-options: -DGIT_REV

build-depends:
cabal-install

Expand Down
13 changes: 11 additions & 2 deletions cabal-install/src/Distribution/Client/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ import Distribution.Client.Utils
, relaxEncodingErrors
)
import Distribution.Client.Version
( cabalInstallVersion
( cabalInstallGitInfo
, cabalInstallVersion
)

import Distribution.Package (packageId)
Expand Down Expand Up @@ -227,7 +228,8 @@ import Distribution.Simple.Program
import Distribution.Simple.Program.Db (reconfigurePrograms)
import qualified Distribution.Simple.Setup as Cabal
import Distribution.Simple.Utils
( cabalVersion
( cabalGitInfo
, cabalVersion
, createDirectoryIfMissingVerbose
, dieNoVerbosity
, dieWithException
Expand Down Expand Up @@ -414,9 +416,16 @@ mainWorker args = do
putStrLn $
"cabal-install version "
++ display cabalInstallVersion
++ " "
++ cabalInstallGitInfo
++ "\ncompiled using version "
++ display cabalVersion
++ " of the Cabal library "
++ cabalGitInfo'
where
cabalGitInfo'
| cabalGitInfo == cabalInstallGitInfo = "(in-tree)"
| otherwise = cabalGitInfo

commands = map commandFromSpec commandSpecs
commandSpecs =
Expand Down
38 changes: 38 additions & 0 deletions cabal-install/src/Distribution/Client/Version.hs
Original file line number Diff line number Diff line change
@@ -1,13 +1,51 @@
{-# LANGUAGE CPP #-}
#ifdef GIT_REV
{-# LANGUAGE TemplateHaskell #-}
#endif

-- | Provides the version number of @cabal-install@.
module Distribution.Client.Version
( cabalInstallVersion
, cabalInstallGitInfo
) where

import Distribution.Version

import qualified Paths_cabal_install as PackageInfo

#ifdef GIT_REV
import Data.Either (isLeft)
import GitHash
( giHash
, giBranch
, giCommitDate
, tGitInfoCwdTry
)
#endif

-- |
-- This value determines the output of `cabal-install --version`.
cabalInstallVersion :: Version
cabalInstallVersion = mkVersion' PackageInfo.version

-- |
-- `cabal-install` Git information. Only filled in if built in a Git tree in
-- developmnent mode and Template Haskell is available.
cabalInstallGitInfo :: String
#ifdef GIT_REV
cabalInstallGitInfo = concat [ "(commit "
, giHash'
, branchInfo
, ", "
, either (const "") giCommitDate gi'
, ")"
]
where
gi' = $$tGitInfoCwdTry
giHash' = take 7 . either (const "") giHash $ gi'
branchInfo | isLeft gi' = ""
| either id giBranch gi' == "master" = ""
| otherwise = " on " <> either id giBranch gi'
#else
cabalInstallGitInfo = ""
#endif
8 changes: 8 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ import: project-cabal/pkgs.config
import: project-cabal/constraints.config

tests: True

-- if you are developing on a system without TH, use a `cabal.project.local`
-- to disable this
package cabal-install
flags: +git-rev

package Cabal
flags: +git-rev
7 changes: 7 additions & 0 deletions cabal.release.project
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ import: project-cabal/pkgs/install.config
import: project-cabal/pkgs/tests.config

index-state: hackage.haskell.org 2024-09-06T14:16:40Z

-- never include this or its TH dependency in a release!
package cabal-install
flags: -git-rev

package Cabal
flags: -git-rev
5 changes: 5 additions & 0 deletions cabal.validate.project
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ tests: True
write-ghc-environment-files: never
program-options
ghc-options: -Werror

-- if you are developing on a system without TH, use a `cabal.validate.project.local`
-- to disable this
package cabal-install
flags: +git-rev
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
How to analyze Haskell performance
==================================
How to enable collection of performance statistics (profiling)
==============================================================

When a Haskell application is slow or uses too much memory,
Cabal and `GHC <https://downloads.haskell.org/ghc/latest/docs/users_guide/profiling.html>`__
Expand Down
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Welcome to the Cabal User Guide

how-to-package-haskell-code
how-to-source-packages
how-to-analyze-haskell-code-performance
how-to-enable-profiling
how-to-build-like-nix
how-to-run-in-windows
how-to-use-backpack
Expand Down

0 comments on commit 5d44962

Please sign in to comment.