Uh oh!
There was an error while loading. Please reload this page.
forked from commercialhaskell/stack
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSetup.hs
More file actions
Latest commit
58 lines (54 loc) · 2.98 KB
/
Copy pathSetup.hs
File metadata and controls
58 lines (54 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
moduleMain (main) where
importData.List ( nub, sortBy )
importData.Ord ( comparing )
importDistribution.Package ( PackageId, InstalledPackageId, packageVersion, packageName )
importDistribution.PackageDescription ( PackageDescription(), Executable(..) )
importDistribution.InstalledPackageInfo (sourcePackageId, installedPackageId)
importDistribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks )
importDistribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose )
importDistribution.Simple.BuildPaths ( autogenModulesDir )
importDistribution.Simple.PackageIndex (allPackages, dependencyClosure)
importDistribution.Simple.Setup ( BuildFlags(buildVerbosity), fromFlag )
importDistribution.Simple.LocalBuildInfo ( installedPkgs, withLibLBI, withExeLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps) )
importDistribution.Types.PackageName (PackageName, unPackageName)
importDistribution.Types.UnqualComponentName (unUnqualComponentName)
importDistribution.Verbosity ( Verbosity )
importDistribution.Version ( showVersion )
importSystem.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
withExeLBI pkg lbi $\exe clbi ->
rewriteFile (dir </>"Build_"++ exeName' exe ++".hs") $unlines
[ "module Build_"++ exeName' exe ++" where"
, ""
, "deps :: [String]"
, "deps = "++ (show$ formatdeps (transDeps libcfg clbi))
]
where
exeName' = unUnqualComponentName . exeName
formatdeps =map formatone . sortBy (comparing unPackageName')
formatone p = unPackageName' p ++"-"++ showVersion (packageVersion p)
unPackageName' = unPackageName . packageName
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 dependency hence is missing from allInstPkgsIdx. Filter that out.
availInstPkgIds =filter (`elem` allInstPkgIds) $ testDeps xs ys
handleDepClosureFailure unsatisfied =
error$
"Computation of transitive dependencies failed."++
ifnull unsatisfied then""else" Unresolved dependencies: "++show unsatisfied
testDeps::ComponentLocalBuildInfo->ComponentLocalBuildInfo-> [InstalledPackageId]
testDeps xs ys =mapfst$ nub $ componentPackageDeps xs ++ componentPackageDeps ys