-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
44 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{-# LANGUAGE BlockArguments, GeneralizedNewtypeDeriving, TypeFamilies #-} | ||
|
||
-- | Compute a truncated hash of a file, useful for computing cache-busters | ||
-- (or other unique ids) for a file. | ||
module Shake.Digest (digestRules, getFileDigest) where | ||
|
||
import qualified Data.ByteString.Lazy as LazyBS | ||
import Data.Digest.Pure.SHA | ||
import Data.Typeable | ||
|
||
import Development.Shake.Classes (Hashable, Binary, NFData) | ||
import Development.Shake | ||
|
||
newtype FileDigest = FileDigest FilePath | ||
deriving (Show, Typeable, Eq, Hashable, Binary, NFData) | ||
|
||
type instance RuleResult FileDigest = String | ||
|
||
-- | Shake rules required for computing file digest. | ||
digestRules :: Rules () | ||
digestRules = versioned 1 do | ||
_ <- addOracle \(FileDigest f) -> do | ||
need [f] | ||
take 8 . showDigest . sha256 <$> liftIO (LazyBS.readFile f) | ||
pure () | ||
|
||
-- | Compute a short digest of a file. | ||
getFileDigest :: FilePath -> Action String | ||
getFileDigest = askOracle . FileDigest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters