on master help sign in
Properly handle generation of sdist Git hashes
e985815David Raymond Christiansen
Setup.hs+36−19
@@ -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,20 @@ 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 (dir </> "dist" </>"build" </> "autogen") 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−
122−
123-- -----------------------------------------------------------------------------
132-- -----------------------------------------------------------------------------
124-- Build
133-- Build
125
134
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+
126idrisBuild _ flags _ local = do
141idrisBuild _ flags _ local = do
127 buildStdLib
142 buildStdLib
128 buildRTS
143 buildRTS
@@ -144,6 +159,7 @@ idrisBuild _ flags _ local = do
144 gmpflag False = []
159 gmpflag False = []
145 gmpflag True = ["GMP=-DIDRIS_GMP"]
160 gmpflag True = ["GMP=-DIDRIS_GMP"]
146
161
162+
147-- -----------------------------------------------------------------------------
163-- -----------------------------------------------------------------------------
148-- Copy/Install
164-- Copy/Install
149
165
@@ -186,4 +202,5 @@ main = defaultMainWithHooks $ simpleUserHooks
186 , postInst = \_ flags pkg local ->
202 , postInst = \_ flags pkg local ->
187 idrisInstall (S.fromFlag $ S.installVerbosity flags)
203 idrisInstall (S.fromFlag $ S.installVerbosity flags)
188 NoCopyDest pkg local
204 NoCopyDest pkg local
205+ , preSDist = idrisPreSDist --do { putStrLn (show args) ; putStrLn (show flags) ; return emptyHookedBuildInfo }
189− }
206+ }
idris.cabal+2−2
@@ -331,7 +331,7 @@ Flag release
331 manual: True
331 manual: True
332
332
333Library
333Library
334− hs-source-dirs: src
334+ hs-source-dirs: src, dist/build/autogen
335 Exposed-modules:
335 Exposed-modules:
336 Idris.Core.CaseTree
336 Idris.Core.CaseTree
337 , Idris.Core.Constraints
337 , Idris.Core.Constraints
@@ -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" ++