-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add autogenerated build config module with an easily usable format. S…
…tay DRY!
- Loading branch information
1 parent
968f087
commit 2e9b2cc
Showing
3 changed files
with
49 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,38 @@ | ||
import Distribution.Simple | ||
main = defaultMain | ||
import Distribution.PackageDescription (PackageDescription(..)) | ||
import Distribution.Simple (defaultMainWithHooks, simpleUserHooks, UserHooks(..), Args) | ||
import Distribution.Simple.BuildPaths (autogenModulesDir) | ||
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo) | ||
import Distribution.Simple.Setup (BuildFlags(..), fromFlag) | ||
import Distribution.Simple.Utils (createDirectoryIfMissingVerbose, rewriteFile) | ||
import System.FilePath ((</>), (<.>)) | ||
|
||
main = defaultMainWithHooks packageInfoUserHooks | ||
|
||
packageInfoUserHooks :: UserHooks | ||
packageInfoUserHooks = | ||
simpleUserHooks { | ||
buildHook = genPackageInfoHook | ||
} | ||
|
||
genPackageInfoHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> BuildFlags -> IO () | ||
genPackageInfoHook pkg lbi uhs bfs= do | ||
createDirectoryIfMissingVerbose (fromFlag $ buildVerbosity bfs) True (autogenModulesDir lbi) | ||
let packageInfoModulePath = autogenModulesDir lbi </> cfg_name <.> "hs" | ||
rewriteFile packageInfoModulePath (generate pkg) | ||
buildHook simpleUserHooks pkg lbi uhs bfs | ||
where cfg_name = "PackageInfo" | ||
generate pkg = "module " ++ cfg_name ++ " where\n" ++ | ||
"\n" ++ | ||
"import Distribution.Package (PackageIdentifier(..), PackageName(..))\n" ++ | ||
"import Distribution.Version (Version(..))\n" ++ | ||
"\n" ++ | ||
"packageInfo = " ++ (show $ package pkg) ++ "\n" ++ | ||
"copyright = " ++ (show $ copyright pkg) ++ "\n" ++ | ||
"maintainer = " ++ (show $ maintainer pkg) ++ "\n" ++ | ||
"author = " ++ (show $ author pkg) ++ "\n" ++ | ||
"stability = " ++ (show $ stability pkg) ++ "\n" ++ | ||
"homepage = " ++ (show $ homepage pkg) ++ "\n" ++ | ||
"pkgUrl = " ++ (show $ pkgUrl pkg) ++ "\n" ++ | ||
"bugReports = " ++ (show $ bugReports pkg) ++ "\n" ++ | ||
"synopsis = " ++ (show $ synopsis pkg) ++ "\n" ++ | ||
"description = " ++ (show $ description pkg) ++ "\n" |
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 |
---|---|---|
|
@@ -33,7 +33,7 @@ Maintainer: [email protected] | |
|
||
Category: Language | ||
|
||
Build-type: Simple | ||
Build-type: Custom | ||
|
||
-- Extra files to be distributed with the package, such as examples or | ||
-- a README. | ||
|
@@ -48,7 +48,7 @@ Executable smudge | |
Main-is: Main.hs | ||
|
||
-- Packages needed in order to build this package. | ||
Build-depends: base, containers, filepath, fgl, parsec, text, graphviz <= 2999.15.0.1 | ||
Build-depends: base, Cabal, containers, filepath, fgl, parsec, text, graphviz <= 2999.15.0.1 | ||
|
||
-- Modules not exported by this package. | ||
Other-modules: Grammar Backends.Backend Backends.GraphViz | ||
|