avoid writing to Build/Version when it already contains the same version

This will hopefully avoid ghc unncessarily rebuilding everything that
depends on it due to the file's timestamp changing.
This commit is contained in:
Joey Hess 2019-01-22 16:54:17 -04:00
parent c94b3a3890
commit 5d58c54a8b
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -1,5 +1,6 @@
{- Package version determination. -}
{-# LANGUAGE LambdaCase #-}
{-# OPTIONS_GHC -fno-warn-tabs #-}
module Build.Version where
@ -54,9 +55,11 @@ getChangelogVersion = do
middle = drop 1 . init
writeVersion :: Version -> IO ()
writeVersion = writeFile "Build/Version" . body
writeVersion ver = catchMaybeIO (readFile f) >>= \case
Just s | s == body -> return ()
_ -> writeFile f body
where
body ver = unlines $ concat
body = unlines $ concat
[ header
, ["packageversion :: String"]
, ["packageversion = \"" ++ ver ++ "\""]
@ -67,3 +70,4 @@ writeVersion = writeFile "Build/Version" . body
, ""
]
footer = []
f = "Build/Version"