-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Provides the SHA1 hash of the program executable
--   
--   See README.md
@package executable-hash
@version 0.2.0.4


-- | Internals related to reading and writing an injected executable hash.
module System.Executable.Hash.Internal

-- | This generates an expression which yields the injected SHA1 hash.
--   
--   The generated expression yields a <a>Just</a> value when the injected
--   SHA1 hash is present in the executable. This hash is usually injected
--   due to a usage of <a>injectExecutableHash</a> /
--   <a>maybeInjectExecutableHash</a>.
injectedExecutableHash :: Q Exp

-- | Given the path to an executable, computes its hash and injects it into
--   the binary, such that when that program demands the value of
--   <a>injectedExecutableHash</a>, it yields a <a>Just</a> value.
--   
--   See the documentation in <a>System.Executable.Hash</a> for an example
--   of how to use this with a cabal <tt>postBuild</tt> hook
injectExecutableHash :: FilePath -> IO ()

-- | Injects an executable hash into the specified binary. If it doesn't
--   exist, then this prints a message to stdout indicating that it failed
--   to inject the hash.
maybeInjectExecutableHash :: FilePath -> IO ()


-- | This module provides functions for accessing or computing a SHA1 hash
--   of the program's executable. Most users are expected to use the
--   <a>executableHash</a> function.
--   
--   To inject the hash into the executable, you can use the
--   <tt>inject-executable-hash</tt> program installed along with this
--   package. Alternatively, to do this automatically with cabal, place
--   this in your <tt>Setup.hs</tt>:
--   
--   <pre>
--   import Distribution.Simple (defaultMainWithHooks, simpleUserHooks, postBuild)
--   import Distribution.Simple.LocalBuildInfo (buildDir)
--   import System.Executable.Hash.Internal (maybeInjectExecutableHash)
--   import System.FilePath ((&lt;/&gt;))
--   
--   main :: IO ()
--   main = defaultMainWithHooks $ simpleUserHooks
--       { postBuild = _ _ _ buildInfo -&gt;
--           maybeInjectExecutableHash (buildDir buildInfo &lt;/&gt; "exeName/exeName")
--       }
--   </pre>
--   
--   (Note: you'll need to change the executable path)
module System.Executable.Hash

-- | This generates an expression which yields a SHA1 hash. The generated
--   expression has the type <tt>IO (Maybe ByteString)</tt>, just like
--   <a>computeExecutableHash</a>.
--   
--   If a SHA1 hash of the executable has been injected into it, then it's
--   directly yielded by this expression. Otherwise, a hash is computed
--   with <a>computeExecutableHash</a>.
--   
--   Note that you shouldn't rely on the result being the actual SHA1 hash
--   of the executable, because injecting the hash modifies the binary, and
--   so changes the result of <a>computeExecutableHash</a>. Instead, this
--   should only be used as a way to uniquely identify the contents of the
--   executable.
--   
--   This yields <a>Nothing</a> when run with <tt>runhaskell</tt> or
--   <tt>ghci</tt>.
executableHash :: Q Exp

-- | Computes the SHA1 hash of the program executable.
--   
--   This yields <a>Nothing</a> when run with <tt>runhaskell</tt> or
--   <tt>ghci</tt>.
computeExecutableHash :: IO (Maybe ByteString)
