Skip to content

Commit

Permalink
Merge pull request #2223 from phadej/deps-in-version
Browse files Browse the repository at this point in the history
Print dependencies version in --version
  • Loading branch information
mgsloan authored Aug 6, 2016
2 parents d9626de + 0370472 commit 1b22811
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
53 changes: 51 additions & 2 deletions Setup.hs
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
4 changes: 3 additions & 1 deletion src/Options/Applicative/Complicated.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ complicatedOptions
-> Maybe String
-- ^ version string
-> String
-- ^ dependencies list
-> String
-- ^ hpack numeric version, as string
-> String
-- ^ header
Expand All @@ -43,7 +45,7 @@ complicatedOptions
-> EitherT b (Writer (Mod CommandFields (b,a))) ()
-- ^ commands (use 'addCommand')
-> IO (a,b)
complicatedOptions numericVersion versionString numericHpackVersion h pd commonParser mOnFailure commandParser =
complicatedOptions numericVersion versionString depsString numericHpackVersion h pd commonParser mOnFailure commandParser =
do args <- getArgs
(a,(b,c)) <- case execParserPure (prefs noBacktrack) parser args of
Failure _ | null args -> withArgs ["--help"] (execParser parser)
Expand Down
2 changes: 2 additions & 0 deletions src/main/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

module Main (main) where

import qualified Build_stack
import Control.Exception
import Control.Monad hiding (mapM, forM)
import Control.Monad.IO.Class
Expand Down Expand Up @@ -176,6 +177,7 @@ commandLineHandler
commandLineHandler progName isInterpreter = complicatedOptions
Meta.version
(Just versionString')
("Compiled with:\n" ++ unlines (map ("- " ++) Build_stack.deps))
VERSION_hpack
"stack - The Haskell Tool Stack"
""
Expand Down
2 changes: 1 addition & 1 deletion stack.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1b22811

Please sign in to comment.