From 0b16009b59539147755ed626786d22a821b2fd24 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 14 Aug 2023 12:29:06 -0400 Subject: merge from git-annex and simplify configure --- Build/Configure.hs | 28 +++++++++++---------- Build/TestConfig.hs | 2 +- Build/Version.hs | 71 ----------------------------------------------------- 3 files changed, 16 insertions(+), 85 deletions(-) delete mode 100644 Build/Version.hs (limited to 'Build') diff --git a/Build/Configure.hs b/Build/Configure.hs index 3460f04..5682e8f 100644 --- a/Build/Configure.hs +++ b/Build/Configure.hs @@ -1,31 +1,33 @@ -{- Checks system configuration and generates SysConfig. -} +{- Checks system configuration and generates Build/SysConfig. -} {-# OPTIONS_GHC -fno-warn-tabs #-} module Build.Configure where -import Control.Monad.IfElse -import Control.Applicative -import Prelude - import Build.TestConfig -import Build.Version -import Git.Version +import Utility.Env.Basic +import qualified Git.Version + +import Control.Monad tests :: [TestCase] tests = - [ TestCase "version" (Config "packageversion" . StringConfig <$> getVersion) - , TestCase "git" $ testCmd "git" "git --version >/dev/null" + [ TestCase "git" $ testCmd "git" "git --version >/dev/null" , TestCase "git version" getGitVersion ] getGitVersion :: Test -getGitVersion = Config "gitversion" . StringConfig . show - <$> Git.Version.installed +getGitVersion = go =<< getEnv "FORCE_GIT_VERSION" + where + go (Just s) = return $ Config "gitversion" $ StringConfig s + go Nothing = do + v <- Git.Version.installed + let oldestallowed = Git.Version.normalize "2.1" + when (v < oldestallowed) $ + error $ "installed git version " ++ show v ++ " is too old! (Need " ++ show oldestallowed ++ " or newer)" + return $ Config "gitversion" $ StringConfig $ show v run :: [TestCase] -> IO () run ts = do config <- runTests ts writeSysConfig config - whenM (isReleaseBuild) $ - cabalSetup "git-repair.cabal" diff --git a/Build/TestConfig.hs b/Build/TestConfig.hs index 988db58..5458612 100644 --- a/Build/TestConfig.hs +++ b/Build/TestConfig.hs @@ -7,7 +7,7 @@ module Build.TestConfig where import Utility.Path import Utility.Monad import Utility.SafeCommand -import Utility.Directory +import Utility.SystemDirectory import System.IO import System.FilePath diff --git a/Build/Version.hs b/Build/Version.hs deleted file mode 100644 index d39a0fe..0000000 --- a/Build/Version.hs +++ /dev/null @@ -1,71 +0,0 @@ -{- Package version determination, for configure script. -} - -{-# OPTIONS_GHC -fno-warn-tabs #-} - -module Build.Version where - -import Data.List -import System.Environment -import Data.Char -import System.Process -import Control.Applicative -import Prelude - -import Utility.Monad -import Utility.Exception -import Utility.Directory - -type Version = String - -{- Set when making an official release. (Distribution vendors should set - - this too.) -} -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. - - 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. -} -getVersion :: IO Version -getVersion = do - changelogversion <- getChangelogVersion - ifM (isReleaseBuild) - ( return changelogversion - , catchDefaultIO changelogversion $ do - let major = takeWhile (/= '.') changelogversion - autoversion <- takeWhile (\c -> isAlphaNum c || c == '-') <$> 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 ] - ) - -getChangelogVersion :: IO Version -getChangelogVersion = do - changelog <- readFile "CHANGELOG" - let verline = takeWhile (/= '\n') changelog - 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 ++ ": " -- cgit v1.2.3