on master help sign in
Merge pull request #762 from david-christiansen/show-git-in-version-2
53f7525Edwin Brady
.gitignore+1
@@ -29,3 +29,4 @@ tutorial/*.fdb_latexmk
29tutorial/*.fls
29tutorial/*.fls
30tags
30tags
31TAGS
31TAGS
32+src/Version_idris.hs
Setup.hs+42−16
@@ -90,9 +90,30 @@ idrisClean _ flags _ _ = do
90-- -----------------------------------------------------------------------------
90-- -----------------------------------------------------------------------------
91-- Configure
91-- Configure
92
92
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+
93idrisConfigure _ flags _ local = do
114idrisConfigure _ flags _ local = do
94 configureRTS
115 configureRTS
95− generateVersionModule
116+ generateVersionModule verbosity (autogenModulesDir local) (isRelease (configFlags local))
96 where
117 where
97 verbosity = S.fromFlag $ S.configVerbosity flags
118 verbosity = S.fromFlag $ S.configVerbosity flags
98 version = pkgVersion . package $ localPkgDescr local
119 version = pkgVersion . package $ localPkgDescr local
@@ -103,26 +124,28 @@ idrisConfigure _ flags _ local = do
103 -- the file after configure.
124 -- the file after configure.
104 configureRTS = make verbosity ["-C", "rts", "clean"]
125 configureRTS = make verbosity ["-C", "rts", "clean"]
105
126
106− -- Put the Git hash into a module for use in the program
127+idrisPreSDist args flags = do
107− -- For release builds, just put the empty string in the module
128+ let dir = S.fromFlag (S.sDistDirectory flags)
108− generateVersionModule = do
129+ let verb = S.fromFlag (S.sDistVerbosity flags)
109− gitHash <- Control.Exception.catch (readProcess "git" ["rev-parse", "--short", "HEAD"] "")
130+ generateVersionModule verb ("src") True
110− (\e -> let e' = (e :: SomeException) in return "PRE")
131+ preSDist simpleUserHooks args flags
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
132
133+idrisPostSDist args flags desc lbi = do
134+ Control.Exception.catch (do let file = "src" </> "Version_idris" Px.<.> "hs"
135+ putStrLn $ "Removing generated module " ++ file
136+ removeFile file)
137+ (\e -> let e' = (e :: SomeException) in return ())
138+ postSDist simpleUserHooks args flags desc lbi
122
139
123-- -----------------------------------------------------------------------------
140-- -----------------------------------------------------------------------------
124-- Build
141-- Build
125
142
143+getVersion :: Args -> S.BuildFlags -> IO HookedBuildInfo
144+getVersion args flags = do
145+ hash <- gitHash
146+ let buildinfo = (emptyBuildInfo { cppOptions = ["-DVERSION="++hash] }) :: BuildInfo
147+ return (Just buildinfo, [])
148+
126idrisBuild _ flags _ local = do
149idrisBuild _ flags _ local = do
127 buildStdLib
150 buildStdLib
128 buildRTS
151 buildRTS
@@ -144,6 +167,7 @@ idrisBuild _ flags _ local = do
144 gmpflag False = []
167 gmpflag False = []
145 gmpflag True = ["GMP=-DIDRIS_GMP"]
168 gmpflag True = ["GMP=-DIDRIS_GMP"]
146
169
170+
147-- -----------------------------------------------------------------------------
171-- -----------------------------------------------------------------------------
148-- Copy/Install
172-- Copy/Install
149
173
@@ -186,4 +210,6 @@ main = defaultMainWithHooks $ simpleUserHooks
186 , postInst = \_ flags pkg local ->
210 , postInst = \_ flags pkg local ->
187 idrisInstall (S.fromFlag $ S.installVerbosity flags)
211 idrisInstall (S.fromFlag $ S.installVerbosity flags)
188 NoCopyDest pkg local
212 NoCopyDest pkg local
213+ , preSDist = idrisPreSDist --do { putStrLn (show args) ; putStrLn (show flags) ; return emptyHookedBuildInfo }
214+ , postSDist = idrisPostSDist
189 }
215 }
idris.cabal+1−1
@@ -409,7 +409,7 @@ Library
409
409
410 -- Auto Generated
410 -- Auto Generated
411 , Paths_idris
411 , Paths_idris
412−-- , Version_idris
412+ , Version_idris
413
413
414 Build-depends: base >=4 && <5
414 Build-depends: base >=4 && <5
415 , Cabal
415 , Cabal
src/Idris/REPL.hs+1−3
@@ -26,7 +26,7 @@ import Idris.CaseSplit
26import Idris.DeepSeq
26import Idris.DeepSeq
27
27
28import Paths_idris
28import Paths_idris
29−-- import Version_idris (gitHash)
29+import Version_idris (gitHash)
30import Util.System
30import Util.System
31import Util.DynamicLinker
31import Util.DynamicLinker
32import Util.Net (listenOnLocalhost)
32import Util.Net (listenOnLocalhost)
@@ -1355,8 +1355,6 @@ getColour _ = Nothing
1355opt :: (Opt -> Maybe a) -> [Opt] -> [a]
1355opt :: (Opt -> Maybe a) -> [Opt] -> [a]
1356opt = mapMaybe
1356opt = mapMaybe
1357
1357
1358−gitHash = "" -- TMP until we work out how to deal with this in the .cabal
1359−
1360ver = showVersion version ++ gitHash
1358ver = showVersion version ++ gitHash
1361
1359
1362banner = " ____ __ _ \n" ++
1360banner = " ____ __ _ \n" ++