summaryrefslogtreecommitdiff
path: root/Build/Configure.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-04-10 16:53:04 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-04-10 16:53:38 -0400
commit2badf04eeb1898d5b77c171a28a1b263cca16313 (patch)
tree87fb49ea99b69b609480e5f1436a3b9cea5b6759 /Build/Configure.hs
parente0aebe9cf31c3fd1e4e5b490f78c37deda857b3a (diff)
The version number is now derived from git, unless built with VERSION_FROM_CHANGELOG.
Diffstat (limited to 'Build/Configure.hs')
-rw-r--r--Build/Configure.hs33
1 files changed, 28 insertions, 5 deletions
diff --git a/Build/Configure.hs b/Build/Configure.hs
index b6f2b773d..ae51e2f9e 100644
--- a/Build/Configure.hs
+++ b/Build/Configure.hs
@@ -8,9 +8,12 @@ import System.Process
import Control.Applicative
import System.FilePath
import System.Environment
+import Data.Maybe
import Build.TestConfig
import Utility.SafeCommand
+import Utility.Monad
+import Utility.Exception
tests :: [TestCase]
tests =
@@ -70,14 +73,34 @@ testCp k option = TestCase cmd $ testCmd k cmdline
cmd = "cp " ++ option
cmdline = cmd ++ " " ++ testFile ++ " " ++ testFile ++ ".new"
-{- Pulls package version out of the changelog. -}
+{- Version is usually based on the major version from the changelog,
+ - plus the date of the last commit, plus the git rev of that commit.
+ - This works for autobuilds, ad-hoc builds, etc.
+ -
+ - For official builds, VERSION_FROM_CHANGELOG makes it use just the most
+ - recent version from the changelog.
+ -
+ - If git or a git repo is not available, or something goes wrong,
+ - just use the version from the changelog. -}
getVersion :: Test
getVersion = do
- version <- getVersionString
+ changelogversion <- getChangelogVersion
+ version <- ifM (isJust <$> catchMaybeIO (getEnv "VERSION_FROM_CHANGELOG"))
+ ( return changelogversion
+ , catchDefaultIO changelogversion $ do
+ let major = takeWhile (/= '.') changelogversion
+ autoversion <- readProcess "sh"
+ [ "-c"
+ , "git log -n 1 --format=format:'%ci %h'| sed -e 's/-//g' -e 's/ .* /-g/'"
+ ] ""
+ if null autoversion
+ then return changelogversion
+ else return $ concat [ major, ".", autoversion ]
+ )
return $ Config "packageversion" (StringConfig version)
-getVersionString :: IO String
-getVersionString = do
+getChangelogVersion :: IO String
+getChangelogVersion = do
changelog <- readFile "CHANGELOG"
let verline = head $ lines changelog
return $ middle (words verline !! 1)
@@ -97,7 +120,7 @@ getSshConnectionCaching = Config "sshconnectioncaching" . BoolConfig <$>
{- Set up cabal file with version. -}
cabalSetup :: IO ()
cabalSetup = do
- version <- getVersionString
+ version <- getChangelogVersion
cabal <- readFile cabalfile
writeFile tmpcabalfile $ unlines $
map (setfield "Version" version) $