From 87b329e4515d7ddce828422cf196180d76afb2d1 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 26 Jun 2018 10:04:42 -0400 Subject: [PATCH 1/3] remove code to update version in cabal file I have not used this when making releases for a long time. --- Build/Configure.hs | 2 -- Build/Version.hs | 18 ------------------ 2 files changed, 20 deletions(-) diff --git a/Build/Configure.hs b/Build/Configure.hs index 31d7dcafa4..4907d976fb 100644 --- a/Build/Configure.hs +++ b/Build/Configure.hs @@ -121,8 +121,6 @@ run ts = do Just "Android" -> writeSysConfig $ androidConfig config _ -> writeSysConfig config cleanup - whenM isReleaseBuild $ - cabalSetup "git-annex.cabal" {- Hard codes some settings to cross-compile for Android. -} androidConfig :: [Config] -> [Config] diff --git a/Build/Version.hs b/Build/Version.hs index d39a0fe08b..57364948a2 100644 --- a/Build/Version.hs +++ b/Build/Version.hs @@ -51,21 +51,3 @@ getChangelogVersion = do return $ middle (words verline !! 1) where middle = drop 1 . init - -{- Set up cabal file with version. -} -cabalSetup :: FilePath -> IO () -cabalSetup cabalfile = do - version <- takeWhile (\c -> isDigit c || c == '.') - <$> getChangelogVersion - cabal <- readFile cabalfile - writeFile tmpcabalfile $ unlines $ - map (setfield "Version" version) $ - lines cabal - renameFile tmpcabalfile cabalfile - where - tmpcabalfile = cabalfile++".tmp" - setfield field value s - | fullfield `isPrefixOf` s = fullfield ++ value - | otherwise = s - where - fullfield = field ++ ": " From 7ecbb6bc20fa9dcc88fe652ca771b11373e21de7 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 26 Jun 2018 10:11:28 -0400 Subject: [PATCH 2/3] stop using git commit date as version This turns out to have been prolimatic because building from a git tag would make a git-annex that claimed a different version than the tag's version. The git rev is still included in the version, and people who want to know the exact tree that was built can just use that, so there's no real benefit to automatically advancing the date part of the version. --- .gitignore | 1 - Build/Version.hs | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 03cb059e6a..f841f39e6e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ Setup tmp test Build/SysConfig -Build/SysConfig.hs Build/InstallDesktopFile Build/EvilSplicer Build/Standalone diff --git a/Build/Version.hs b/Build/Version.hs index 57364948a2..1d827ff685 100644 --- a/Build/Version.hs +++ b/Build/Version.hs @@ -22,12 +22,11 @@ type Version = String isReleaseBuild :: IO Bool isReleaseBuild = (== Just "1") <$> catchMaybeIO (getEnv "RELEASE_BUILD") -{- 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. +{- Version comes from the CHANGELOG, plus the git rev of the last commit. - This works for autobuilds, ad-hoc builds, etc. - - If git or a git repo is not available, or something goes wrong, - - or this is a release build, just use the version from the changelog. -} + - or this is a release build, just use the version from the CHANGELOG. -} getVersion :: IO Version getVersion = do changelogversion <- getChangelogVersion @@ -35,13 +34,17 @@ getVersion = do ( return changelogversion , catchDefaultIO changelogversion $ do let major = takeWhile (/= '.') changelogversion - autoversion <- takeWhile (\c -> isAlphaNum c || c == '-') <$> readProcess "sh" + gitversion <- takeWhile (\c -> isAlphaNum c) <$> readProcess "sh" [ "-c" - , "git log -n 1 --format=format:'%ci %h'| sed -e 's/-//g' -e 's/ .* /-g/'" + , "git log -n 1 --format=format:'%h'" ] "" - if null autoversion - then return changelogversion - else return $ concat [ major, ".", autoversion ] + return $ if null gitversion + then changelogversion + else concat + [ changelogversion + , "-g" + , gitversion + ] ) getChangelogVersion :: IO Version From a1b55056fc9c75c6eb7b639b24cc05213ebca0e6 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 26 Jun 2018 10:33:28 -0400 Subject: [PATCH 3/3] 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. --- .gitignore | 1 + Build/BuildVersion.hs | 12 +++++++++--- Build/Configure.hs | 7 +++---- Build/Version.hs | 19 ++++++++++++++++--- BuildInfo.hs | 2 ++ Makefile | 2 +- standalone/windows/build.sh | 9 +++++---- 7 files changed, 37 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index f841f39e6e..16314abf76 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ Setup tmp test Build/SysConfig +Build/Version Build/InstallDesktopFile Build/EvilSplicer Build/Standalone diff --git a/Build/BuildVersion.hs b/Build/BuildVersion.hs index 0093f5b5b1..5ae1c4cef7 100644 --- a/Build/BuildVersion.hs +++ b/Build/BuildVersion.hs @@ -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 diff --git a/Build/Configure.hs b/Build/Configure.hs index 4907d976fb..c490148f50 100644 --- a/Build/Configure.hs +++ b/Build/Configure.hs @@ -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. -} diff --git a/Build/Version.hs b/Build/Version.hs index 1d827ff685..69752a0897 100644 --- a/Build/Version.hs +++ b/Build/Version.hs @@ -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 = [] diff --git a/BuildInfo.hs b/BuildInfo.hs index 40aa2fdfb4..465ac372ef 100644 --- a/BuildInfo.hs +++ b/BuildInfo.hs @@ -12,3 +12,5 @@ module BuildInfo where -- This file is generated by the configure program with the results of its -- probing. #include "Build/SysConfig" +-- This file is automatically generated from the CHANGELOG version +#include "Build/Version" diff --git a/Makefile b/Makefile index 9f4c122c3c..c5773c5c71 100644 --- a/Makefile +++ b/Makefile @@ -108,7 +108,7 @@ docs: mans clean: if [ "$(BUILDER)" != ./Setup ] && [ "$(BUILDER)" != cabal ]; then $(BUILDER) clean; fi rm -rf tmp dist git-annex $(mans) configure *.tix .hpc \ - doc/.ikiwiki html dist tags Build/SysConfig \ + doc/.ikiwiki html dist tags Build/SysConfig Build/Version \ Setup Build/InstallDesktopFile Build/EvilSplicer \ Build/Standalone Build/OSXMkLibs Build/LinuxMkLibs \ Build/DistributionUpdate Build/BuildVersion Build/MakeMans \ diff --git a/standalone/windows/build.sh b/standalone/windows/build.sh index b0e6bdd4ff..123dc7ddf9 100755 --- a/standalone/windows/build.sh +++ b/standalone/windows/build.sh @@ -63,6 +63,11 @@ getextra rsync.exe 85cb7a4d16d274fcf8069b39042965ad26abd6aa #stack upgrade --git stack --version +# Update version info for git rev being built. +mkdir -p dist +stack ghc --stack-yaml stack-windows.yaml --no-haddock Build/BuildVersion.hs +./Build/BuildVersion > dist/build-version + # Build git-annex stack setup --stack-yaml stack-windows.yaml stack install -j 1 --stack-yaml stack-windows.yaml --no-haddock \ @@ -73,10 +78,6 @@ withcygpreferred stack ghc --stack-yaml stack-windows.yaml --no-haddock \ --package nsis Build/NullSoftInstaller.hs ./Build/NullSoftInstaller -mkdir -p dist -stack ghc --stack-yaml stack-windows.yaml --no-haddock Build/BuildVersion.hs -./Build/BuildVersion > dist/build-version - # Test git-annex # The test is run in c:/WINDOWS/Temp, because running it in the autobuilder # directory runs afoul of Windows's short PATH_MAX.