2018-06-26 14:33:28 +00:00
|
|
|
{- Checks system configuration and generates Build/SysConfig and Build/Version. -}
|
2012-03-10 18:00:26 +00:00
|
|
|
|
2015-05-10 20:38:49 +00:00
|
|
|
{-# OPTIONS_GHC -fno-warn-tabs #-}
|
|
|
|
|
2013-04-17 15:57:46 +00:00
|
|
|
module Build.Configure where
|
|
|
|
|
2012-03-10 18:00:26 +00:00
|
|
|
import Build.TestConfig
|
2013-10-06 21:48:38 +00:00
|
|
|
import Build.Version
|
2012-03-10 18:00:26 +00:00
|
|
|
import Utility.SafeCommand
|
2017-12-31 20:08:31 +00:00
|
|
|
import Utility.Env.Basic
|
2013-08-02 22:31:01 +00:00
|
|
|
import qualified Git.Version
|
2017-11-14 18:59:51 +00:00
|
|
|
import Utility.Directory
|
2012-03-10 18:00:26 +00:00
|
|
|
|
2017-12-31 20:08:31 +00:00
|
|
|
import Control.Monad
|
|
|
|
import Control.Applicative
|
|
|
|
import Prelude
|
|
|
|
|
2012-03-22 21:09:54 +00:00
|
|
|
tests :: [TestCase]
|
|
|
|
tests =
|
2018-06-26 14:33:28 +00:00
|
|
|
[ TestCase "UPGRADE_LOCATION" getUpgradeLocation
|
2017-10-25 21:24:03 +00:00
|
|
|
, TestCase "git" $ testCmd "git" "git --version >/dev/null"
|
2012-03-10 18:00:26 +00:00
|
|
|
, TestCase "git version" getGitVersion
|
|
|
|
, testCp "cp_a" "-a"
|
|
|
|
, testCp "cp_p" "-p"
|
2014-08-27 00:06:43 +00:00
|
|
|
, testCp "cp_preserve_timestamps" "--preserve=timestamps"
|
2019-07-17 18:19:00 +00:00
|
|
|
, testCp "cp_reflink_supported" "--reflink=auto"
|
2017-10-25 21:24:03 +00:00
|
|
|
, TestCase "xargs -0" $ testCmd "xargs_0" "xargs -0 </dev/null"
|
|
|
|
, TestCase "rsync" $ testCmd "rsync" "rsync --version >/dev/null"
|
2012-03-10 18:00:26 +00:00
|
|
|
, TestCase "curl" $ testCmd "curl" "curl --version >/dev/null"
|
|
|
|
, TestCase "bup" $ testCmd "bup" "bup --version >/dev/null"
|
2013-10-08 22:01:03 +00:00
|
|
|
, TestCase "nice" $ testCmd "nice" "nice true >/dev/null"
|
2013-06-21 17:43:04 +00:00
|
|
|
, TestCase "ionice" $ testCmd "ionice" "ionice -c3 true >/dev/null"
|
2013-12-01 19:12:32 +00:00
|
|
|
, TestCase "nocache" $ testCmd "nocache" "nocache true >/dev/null"
|
2013-05-19 21:59:58 +00:00
|
|
|
, TestCase "gpg" $ maybeSelectCmd "gpg"
|
|
|
|
[ ("gpg", "--version >/dev/null")
|
|
|
|
, ("gpg2", "--version >/dev/null") ]
|
2012-12-14 19:52:44 +00:00
|
|
|
, TestCase "lsof" $ findCmdPath "lsof" "lsof"
|
2013-10-21 22:45:19 +00:00
|
|
|
, TestCase "git-remote-gcrypt" $ findCmdPath "gcrypt" "git-remote-gcrypt"
|
2012-03-10 18:00:26 +00:00
|
|
|
, TestCase "ssh connection caching" getSshConnectionCaching
|
configure: Check that checksum programs produce correct checksums. + bitter rant
So, it might be called sha1sum, or on some other OS, it might be called
sha1. It might be hidden away off of PATH on that OS. That's just expected
insanity; UNIX has been this way since 1980's. And these days, nobody even
gives the flying flip about standards that we briefly did in the 90's
after the first round of unix wars.
But it's the 2010's now, and we've certainly learned something.
So, let's make it so sometimes sha1 is a crazy program that wants to run as
root so it can lock memory while prompting for a passphrase, and outputting
binary garbage. Yes, that'd be wise. Let's package that in major Linux
distros, too, so users can stumble over it.
2012-10-25 04:05:12 +00:00
|
|
|
]
|
2012-03-10 18:00:26 +00:00
|
|
|
|
|
|
|
tmpDir :: String
|
|
|
|
tmpDir = "tmp"
|
|
|
|
|
|
|
|
testFile :: String
|
|
|
|
testFile = tmpDir ++ "/testfile"
|
|
|
|
|
|
|
|
testCp :: ConfigKey -> String -> TestCase
|
|
|
|
testCp k option = TestCase cmd $ testCmd k cmdline
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
|
|
|
cmd = "cp " ++ option
|
|
|
|
cmdline = cmd ++ " " ++ testFile ++ " " ++ testFile ++ ".new"
|
2012-03-10 18:00:26 +00:00
|
|
|
|
2013-11-21 21:49:56 +00:00
|
|
|
getUpgradeLocation :: Test
|
|
|
|
getUpgradeLocation = do
|
|
|
|
e <- getEnv "UPGRADE_LOCATION"
|
|
|
|
return $ Config "upgradelocation" $ MaybeStringConfig e
|
|
|
|
|
2012-03-10 18:00:26 +00:00
|
|
|
getGitVersion :: Test
|
2015-04-14 18:44:19 +00:00
|
|
|
getGitVersion = go =<< getEnv "FORCE_GIT_VERSION"
|
|
|
|
where
|
|
|
|
go (Just s) = return $ Config "gitversion" $ StringConfig s
|
|
|
|
go Nothing = do
|
|
|
|
v <- Git.Version.installed
|
2019-09-11 20:10:25 +00:00
|
|
|
let oldestallowed = Git.Version.normalize "2.1"
|
2015-04-14 18:44:19 +00:00
|
|
|
when (v < oldestallowed) $
|
|
|
|
error $ "installed git version " ++ show v ++ " is too old! (Need " ++ show oldestallowed ++ " or newer)"
|
|
|
|
return $ Config "gitversion" $ StringConfig $ show v
|
2012-03-10 18:00:26 +00:00
|
|
|
|
|
|
|
getSshConnectionCaching :: Test
|
|
|
|
getSshConnectionCaching = Config "sshconnectioncaching" . BoolConfig <$>
|
|
|
|
boolSystem "sh" [Param "-c", Param "ssh -o ControlPersist=yes -V >/dev/null 2>/dev/null"]
|
|
|
|
|
|
|
|
setup :: IO ()
|
|
|
|
setup = do
|
|
|
|
createDirectoryIfMissing True tmpDir
|
|
|
|
writeFile testFile "test file contents"
|
|
|
|
|
|
|
|
cleanup :: IO ()
|
|
|
|
cleanup = removeDirectoryRecursive tmpDir
|
|
|
|
|
|
|
|
run :: [TestCase] -> IO ()
|
|
|
|
run ts = do
|
|
|
|
setup
|
|
|
|
config <- runTests ts
|
2019-07-17 17:31:37 +00:00
|
|
|
writeSysConfig config
|
2018-06-26 14:33:28 +00:00
|
|
|
writeVersion =<< getVersion
|
2012-03-10 18:00:26 +00:00
|
|
|
cleanup
|