From 4b3571a6955c3a817f9b4ef7bcc273b916879a93 Mon Sep 17 00:00:00 2001 From: Daniel Gröber Date: Tue, 26 Sep 2017 14:07:59 +0200 Subject: Refactor CH.C.Data to use 'unix' instead of 'time' --- CabalHelper/Compiletime/Data.hs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'CabalHelper/Compiletime/Data.hs') diff --git a/CabalHelper/Compiletime/Data.hs b/CabalHelper/Compiletime/Data.hs index 6b096d7..346c2a5 100644 --- a/CabalHelper/Compiletime/Data.hs +++ b/CabalHelper/Compiletime/Data.hs @@ -14,21 +14,22 @@ -- You should have received a copy of the GNU Affero General Public License -- along with this program. If not, see . -{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TemplateHaskell, ScopedTypeVariables #-} {-# OPTIONS_GHC -fforce-recomp #-} module CabalHelper.Compiletime.Data where import Control.Monad import Control.Monad.IO.Class import Data.Functor -import Data.Time.Clock -import Data.Time.Clock.POSIX import qualified Data.ByteString as BS import qualified Data.ByteString.UTF8 as UTF8 import Language.Haskell.TH import System.Directory import System.FilePath import System.IO.Temp +import System.Posix.Files +import System.Posix.Time +import System.Posix.Types import Prelude import CabalHelper.Compiletime.Compat.Environment @@ -49,20 +50,19 @@ withHelperSources mdir action = withDir mdir $ \dir -> do createDirectoryIfMissing True $ chdir "Runtime" createDirectoryIfMissing True $ chdir "Shared" - let modtime = read + let modtime :: EpochTime + modtime = fromIntegral $ (read :: String -> Integer) -- See https://reproducible-builds.org/specs/source-date-epoch/ $(runIO $ do - msde <- lookupEnv "SOURCE_DATE_EPOCH" - let parse :: String -> POSIXTime - parse = fromInteger . read - utctime <- getCurrentTime - return $ LitE . StringL $ show $ - maybe utctime (posixSecondsToUTCTime . parse) msde) + msde :: Maybe Integer + <- fmap read <$> lookupEnv "SOURCE_DATE_EPOCH" + (current_time :: Integer) <- round . toRational <$> epochTime + return $ LitE . StringL $ show $ maybe current_time id msde) liftIO $ forM_ sourceFiles $ \(fn, src) -> do let path = chdir fn BS.writeFile path $ UTF8.fromString src - setModificationTime path modtime + setFileTimes path modtime modtime action dir where -- cgit v1.2.3