Make Build/BuildVersion update embedded version number

This way, autobuilders can run it before building, in a tree where
git-annex was already built, and get the current git rev embedded in the
build.

Before, the version number only updated when the setup program was run,
which was up to cabal and not on every build.
This commit is contained in:
Joey Hess 2018-06-26 10:33:28 -04:00
parent 7ecbb6bc20
commit a1b55056fc
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
7 changed files with 37 additions and 15 deletions

View file

@ -1,6 +1,12 @@
{- Outputs the version of git-annex that was built, for use by
- autobuilders. Note that this includes the git rev. -}
{- For use by autobuilders, this outputs the version of git-annex that
- is being built, and also updates the Build/Version file so the build
- will report the right version, including the current git rev. -}
{-# OPTIONS_GHC -fno-warn-tabs #-}
import Build.Version
main = putStr =<< getVersion
main = do
ver <- getVersion
writeVersion ver
putStr ver

View file

@ -1,4 +1,4 @@
{- Checks system configuration and generates SysConfig. -}
{- Checks system configuration and generates Build/SysConfig and Build/Version. -}
{-# OPTIONS_GHC -fno-warn-tabs #-}
@ -12,15 +12,13 @@ import Utility.Env.Basic
import qualified Git.Version
import Utility.Directory
import Control.Monad.IfElse
import Control.Monad
import Control.Applicative
import Prelude
tests :: [TestCase]
tests =
[ TestCase "version" (Config "packageversion" . StringConfig <$> getVersion)
, TestCase "UPGRADE_LOCATION" getUpgradeLocation
[ TestCase "UPGRADE_LOCATION" getUpgradeLocation
, TestCase "git" $ testCmd "git" "git --version >/dev/null"
, TestCase "git version" getGitVersion
, testCp "cp_a" "-a"
@ -120,6 +118,7 @@ run ts = do
case v of
Just "Android" -> writeSysConfig $ androidConfig config
_ -> writeSysConfig config
writeVersion =<< getVersion
cleanup
{- Hard codes some settings to cross-compile for Android. -}

View file

@ -1,4 +1,4 @@
{- Package version determination, for configure script. -}
{- Package version determination. -}
{-# OPTIONS_GHC -fno-warn-tabs #-}
@ -13,7 +13,6 @@ import Prelude
import Utility.Monad
import Utility.Exception
import Utility.Directory
type Version = String
@ -33,7 +32,6 @@ getVersion = do
ifM (isReleaseBuild)
( return changelogversion
, catchDefaultIO changelogversion $ do
let major = takeWhile (/= '.') changelogversion
gitversion <- takeWhile (\c -> isAlphaNum c) <$> readProcess "sh"
[ "-c"
, "git log -n 1 --format=format:'%h'"
@ -54,3 +52,18 @@ getChangelogVersion = do
return $ middle (words verline !! 1)
where
middle = drop 1 . init
writeVersion :: Version -> IO ()
writeVersion = writeFile "Build/Version" . body
where
body ver = unlines $ concat
[ header
, ["packageversion :: String"]
, ["packageversion = \"" ++ ver ++ "\""]
, footer
]
header = [
"{- Automatically generated. -}"
, ""
]
footer = []