Skip to content

Commit

Permalink
Merge pull request #2458 from commercialhaskell/2450-list-transitive-…
Browse files Browse the repository at this point in the history
…deps

List transitive deps in --version (#2450)
  • Loading branch information
mgsloan authored Aug 9, 2016
2 parents 7249721 + 439377b commit 708e675
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ 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.PackageDescription ( PackageDescription(), Executable(..) )
import Distribution.InstalledPackageInfo (sourcePackageId, installedPackageId)
import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks )
import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose )
import Distribution.Simple.BuildPaths ( autogenModulesDir )
import Distribution.Simple.PackageIndex (allPackages, dependencyClosure)
import Distribution.Simple.Setup ( BuildFlags(buildVerbosity), fromFlag )
import Distribution.Simple.LocalBuildInfo ( withLibLBI, withTestLBI, withExeLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps) )
import Distribution.Simple.LocalBuildInfo ( installedPkgs, withLibLBI, withExeLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps) )
import Distribution.Verbosity ( Verbosity )
import System.FilePath ( (</>) )

Expand All @@ -26,27 +28,28 @@ 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))
, "deps = " ++ (show $ formatdeps (transDeps libcfg clbi))
]
where
formatdeps = map formatone . sortBy (comparing unPackageName') . map snd
formatdeps = map formatone . sortBy (comparing unPackageName')
formatone p = unPackageName' p ++ "-" ++ showVersion (packageVersion p)
unPackageName' p = case packageName p of PackageName n -> n
transDeps xs ys =
either (map sourcePackageId . allPackages) handleDepClosureFailure $ dependencyClosure allInstPkgsIdx availInstPkgIds
where
allInstPkgsIdx = installedPkgs lbi
allInstPkgIds = map installedPackageId $ allPackages allInstPkgsIdx
-- instPkgIds includes `stack-X.X.X`, which is not a depedency hence is missing from allInstPkgsIdx. Filter that out.
availInstPkgIds = filter (`elem` allInstPkgIds) . map fst $ testDeps xs ys
handleDepClosureFailure unsatisfied =
error $
"Computation of transitive dependencies failed." ++
if null unsatisfied then "" else " Unresolved dependencies: " ++ show unsatisfied

testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)]
testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys

0 comments on commit 708e675

Please sign in to comment.