aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gröber <dxld@darkboxed.org>2018-10-10 21:45:34 +0200
committerDaniel Gröber <dxld@darkboxed.org>2018-10-26 04:33:05 +0200
commit2968c76b2c4bf60a273f2da161b1552cb1e15fe9 (patch)
tree4fe5b95059891ffaca1248157cc7f0d31a548adf
parent12e1be31c09161dec1fa70f15ede84ba9965a365 (diff)
Support hashing runtime sources
-rw-r--r--cabal-helper.cabal3
-rw-r--r--src/CabalHelper/Compiletime/Data.hs36
2 files changed, 33 insertions, 6 deletions
diff --git a/cabal-helper.cabal b/cabal-helper.cabal
index b7b5f73..19aa890 100644
--- a/cabal-helper.cabal
+++ b/cabal-helper.cabal
@@ -115,6 +115,7 @@ library
, process < 1.7 && >= 1.1.0.1
, pretty-show < 1.9 && >= 1.8.1
, semigroupoids < 5.3 && >= 5.2
+ , SHA < 1.7 && >= 1.6.4.4
, text < 1.3 && >= 1.0.0.0
, template-haskell < 2.14 && >= 2.7.0.0
, temporary < 1.3 && >= 1.2.1
@@ -164,6 +165,7 @@ test-suite compile-test
, mtl < 2.3 && >= 2.0
, process < 1.7 && >= 1.1.0.1
, pretty-show < 1.9 && >= 1.8.1
+ , SHA < 1.7 && >= 1.6.4.4
, text < 1.3 && >= 1.0.0.0
, template-haskell < 2.14 && >= 2.7.0.0
, temporary < 1.3 && >= 1.2.1
@@ -214,6 +216,7 @@ test-suite ghc-session
, mtl < 2.3 && >= 2.0
, process < 1.7 && >= 1.1.0.1
, pretty-show < 1.9 && >= 1.8.1
+ , SHA < 1.7 && >= 1.6.4.4
, text < 1.3 && >= 1.0.0.0
, template-haskell < 2.14 && >= 2.7.0.0
, temporary < 1.3 && >= 1.2.1
diff --git a/src/CabalHelper/Compiletime/Data.hs b/src/CabalHelper/Compiletime/Data.hs
index 80df962..76019fa 100644
--- a/src/CabalHelper/Compiletime/Data.hs
+++ b/src/CabalHelper/Compiletime/Data.hs
@@ -27,9 +27,13 @@ module CabalHelper.Compiletime.Data where
import Control.Monad
import Control.Monad.IO.Class
+import Data.Digest.Pure.SHA
import Data.Functor
+import Data.List
import qualified Data.ByteString as BS
import qualified Data.ByteString.UTF8 as UTF8
+import qualified Data.ByteString.Lazy as LBS
+import qualified Data.ByteString.Lazy.UTF8 as LUTF8
import Language.Haskell.TH
import System.Directory
import System.FilePath
@@ -71,11 +75,31 @@ createHelperSources dir = do
BS.writeFile path $ UTF8.fromString src
setFileTimes path modtime modtime
+sourceHash :: String
+sourceHash = fst runtimeSources
sourceFiles :: [(FilePath, String)]
-sourceFiles =
- [ ("Runtime/Main.hs", $(LitE . StringL <$> runIO (UTF8.toString <$> BS.readFile "src/CabalHelper/Runtime/Main.hs")))
- , ("Shared/Common.hs", $(LitE . StringL <$> runIO (UTF8.toString <$> BS.readFile "src/CabalHelper/Shared/Common.hs")))
- , ("Shared/Sandbox.hs", $(LitE . StringL <$> runIO (UTF8.toString <$> BS.readFile "src/CabalHelper/Shared/Sandbox.hs")))
- , ("Shared/InterfaceTypes.hs", $(LitE . StringL <$> runIO (UTF8.toString <$> BS.readFile "src/CabalHelper/Shared/InterfaceTypes.hs")))
- ]
+sourceFiles = snd runtimeSources
+
+runtimeSources :: (String, [(FilePath, FilePath)])
+runtimeSources = $(
+ let files = map (\f -> (f, ("src/CabalHelper" </> f))) $ sort $
+ [ ("Runtime/Main.hs")
+ , ("Shared/Common.hs")
+ , ("Shared/Sandbox.hs")
+ , ("Shared/InterfaceTypes.hs")
+ ]
+ in do
+ contents <- mapM (\lf -> runIO (LBS.readFile lf)) $ map snd files
+ let hashes = map (bytestringDigest . sha256) contents
+ let top_hash = showDigest $ sha256 $ LBS.concat hashes
+
+ thfiles <- forM (map fst files `zip` contents) $ \(f, xs) -> do
+ return $ TupE [LitE (StringL f), LitE (StringL (LUTF8.toString xs))]
+
+
+ return $ TupE [LitE (StringL top_hash), ListE thfiles]
+
+ )
+
+-- - $(LitE . StringL <$> runIO (UTF8.toString <$> BS.readFile