-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2223 from phadej/deps-in-version
Print dependencies version in --version
- Loading branch information
Showing
4 changed files
with
57 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,51 @@ | ||
import Distribution.Simple | ||
main = defaultMain | ||
module Main (main) where | ||
|
||
import Data.List ( nub, sortBy ) | ||
import Data.Ord ( comparing ) | ||
import Data.Version ( showVersion ) | ||
import Distribution.Package ( PackageName(PackageName), PackageId, InstalledPackageId, packageVersion, packageName ) | ||
import Distribution.PackageDescription ( PackageDescription(), TestSuite(..), Executable(..) ) | ||
import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks ) | ||
import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose ) | ||
import Distribution.Simple.BuildPaths ( autogenModulesDir ) | ||
import Distribution.Simple.Setup ( BuildFlags(buildVerbosity), fromFlag ) | ||
import Distribution.Simple.LocalBuildInfo ( withLibLBI, withTestLBI, withExeLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps) ) | ||
import Distribution.Verbosity ( Verbosity ) | ||
import System.FilePath ( (</>) ) | ||
|
||
main :: IO () | ||
main = defaultMainWithHooks simpleUserHooks | ||
{ buildHook = \pkg lbi hooks flags -> do | ||
generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi | ||
buildHook simpleUserHooks pkg lbi hooks flags | ||
} | ||
|
||
generateBuildModule :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO () | ||
generateBuildModule verbosity pkg lbi = do | ||
let dir = autogenModulesDir lbi | ||
createDirectoryIfMissingVerbose verbosity True dir | ||
withLibLBI pkg lbi $ \_ libcfg -> do | ||
withTestLBI pkg lbi $ \suite clbi -> | ||
rewriteFile (dir </> "Build_" ++ testName suite ++ ".hs") $ unlines | ||
[ "module Build_" ++ testName suite ++ " where" | ||
, "" | ||
, "autogen_dir :: String" | ||
, "autogen_dir = " ++ show dir | ||
, "" | ||
, "deps :: [String]" | ||
, "deps = " ++ (show $ formatdeps (testDeps libcfg clbi)) | ||
] | ||
withExeLBI pkg lbi $ \exe clbi -> | ||
rewriteFile (dir </> "Build_" ++ exeName exe ++ ".hs") $ unlines | ||
[ "module Build_" ++ exeName exe ++ " where" | ||
, "" | ||
, "deps :: [String]" | ||
, "deps = " ++ (show $ formatdeps (testDeps libcfg clbi)) | ||
] | ||
where | ||
formatdeps = map formatone . sortBy (comparing unPackageName') . map snd | ||
formatone p = unPackageName' p ++ "-" ++ showVersion (packageVersion p) | ||
unPackageName' p = case packageName p of PackageName n -> n | ||
|
||
testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)] | ||
testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys |
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
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ license-file: LICENSE | |
author: Commercial Haskell SIG | ||
maintainer: [email protected] | ||
category: Development | ||
build-type: Simple | ||
build-type: Custom | ||
cabal-version: >=1.10 | ||
homepage: http://haskellstack.org | ||
extra-source-files: CONTRIBUTING.md | ||
|