@@ -90,9 +90,30 @@ idrisClean _ flags _ _ = do
9090-- -----------------------------------------------------------------------------
9191-- Configure
9292
93+gitHash :: IO String
94+gitHash = do h <- Control.Exception.catch (readProcess "git" ["rev-parse", "--short", "HEAD"] "")
95+ (\e -> let e' = (e :: SomeException) in return "PRE")
96+ return $ takeWhile (/= '\n') h
97+
98+-- Put the Git hash into a module for use in the program
99+-- For release builds, just put the empty string in the module
100+generateVersionModule verbosity dir release = do
101+ hash <- gitHash
102+ let versionModulePath = dir </> "Version_idris" Px.<.> "hs"
103+ putStrLn $ "Generating " ++ versionModulePath ++
104+ if release then " for release" else (" for prerelease " ++ hash)
105+ createDirectoryIfMissingVerbose verbosity True dir
106+ rewriteFile versionModulePath (versionModuleContents hash)
107+
108+ where versionModuleContents h = "module Version_idris where\n\n" ++
109+ "gitHash :: String\n" ++
110+ if release
111+ then "gitHash = \"\"\n"
112+ else "gitHash = \"-git:" ++ h ++ "\"\n"
113+
93114idrisConfigure _ flags _ local = do
94115 configureRTS
95− generateVersionModule
116+ generateVersionModule verbosity (autogenModulesDir local) (isRelease (configFlags local))
96117 where
97118 verbosity = S.fromFlag $ S.configVerbosity flags
98119 version = pkgVersion . package $ localPkgDescr local
@@ -103,26 +124,20 @@ idrisConfigure _ flags _ local = do
103124 -- the file after configure.
104125 configureRTS = make verbosity ["-C", "rts", "clean"]
105126
106− -- Put the Git hash into a module for use in the program
107− -- For release builds, just put the empty string in the module
108− generateVersionModule = do
109− gitHash <- Control.Exception.catch (readProcess "git" ["rev-parse", "--short", "HEAD"] "")
110− (\e -> let e' = (e :: SomeException) in return "PRE")
111− let hash = takeWhile (/= '\n') gitHash
112− let versionModulePath = autogenModulesDir local </> "Version_idris" Px.<.> "hs"
113− createDirectoryIfMissingVerbose verbosity True (autogenModulesDir local)
114− rewriteFile versionModulePath (versionModuleContents hash)
115−
116− versionModuleContents h = "module Version_idris where\n\n" ++
117− "gitHash :: String\n" ++
118− if isRelease (configFlags local)
119− then "gitHash = \"\"\n"
120− else "gitHash = \"-git:" ++ h ++ "\"\n"
121−
122−
127+idrisPreSDist args flags = do
128+ let dir = S.fromFlag (S.sDistDirectory flags)
129+ let verb = S.fromFlag (S.sDistVerbosity flags)
130+ generateVersionModule verb (dir </> "dist" </>"build" </> "autogen") True
131+ preSDist simpleUserHooks args flags
123132-- -----------------------------------------------------------------------------
124133-- Build
125134
135+getVersion :: Args -> S.BuildFlags -> IO HookedBuildInfo
136+getVersion args flags = do
137+ hash <- gitHash
138+ let buildinfo = (emptyBuildInfo { cppOptions = ["-DVERSION="++hash] }) :: BuildInfo
139+ return (Just buildinfo, [])
140+
126141idrisBuild _ flags _ local = do
127142 buildStdLib
128143 buildRTS
@@ -144,6 +159,7 @@ idrisBuild _ flags _ local = do
144159 gmpflag False = []
145160 gmpflag True = ["GMP=-DIDRIS_GMP"]
146161
162+
147163-- -----------------------------------------------------------------------------
148164-- Copy/Install
149165
@@ -186,4 +202,5 @@ main = defaultMainWithHooks $ simpleUserHooks
186202 , postInst = \_ flags pkg local ->
187203 idrisInstall (S.fromFlag $ S.installVerbosity flags)
188204 NoCopyDest pkg local
189− }
205+ , preSDist = idrisPreSDist --do { putStrLn (show args) ; putStrLn (show flags) ; return emptyHookedBuildInfo }
206+ }