Skip to content

Commit dea2490

Browse files
Tim McGilchristnhibberd
Tim McGilchrist
authored andcommitted
Update deps and fixup main executable.
1 parent e3c59e7 commit dea2490

File tree

6 files changed

+41
-7
lines changed

6 files changed

+41
-7
lines changed

Setup.hs

100644100755
+30-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import Data.List (intercalate)
55
import Data.Monoid ((<>))
66
import Data.Version (showVersion)
77

8+
import Distribution.InstalledPackageInfo
89
import Distribution.PackageDescription
9-
import Distribution.Verbosity
1010
import Distribution.Simple
1111
import Distribution.Simple.Setup (BuildFlags(..), ReplFlags(..), TestFlags(..), fromFlag)
1212
import Distribution.Simple.LocalBuildInfo
13+
import Distribution.Simple.PackageIndex
1314
import Distribution.Simple.BuildPaths (autogenModulesDir)
1415
import Distribution.Simple.Utils (createDirectoryIfMissingVerbose, rewriteFile, rawSystemStdout)
16+
import Distribution.Verbosity
1517

1618
main :: IO ()
1719
main =
@@ -25,12 +27,15 @@ main =
2527
(sDistHook hooks) pd mlbi uh flags
2628
, buildHook = \pd lbi uh flags -> do
2729
genBuildInfo (fromFlag $ buildVerbosity flags) pd
30+
genDependencyInfo (fromFlag $ buildVerbosity flags) pd lbi
2831
(buildHook hooks) pd lbi uh flags
2932
, replHook = \pd lbi uh flags args -> do
3033
genBuildInfo (fromFlag $ replVerbosity flags) pd
34+
genDependencyInfo (fromFlag $ replVerbosity flags) pd lbi
3135
(replHook hooks) pd lbi uh flags args
3236
, testHook = \args pd lbi uh flags -> do
3337
genBuildInfo (fromFlag $ testVerbosity flags) pd
38+
genDependencyInfo (fromFlag $ testVerbosity flags) pd lbi
3439
(testHook hooks) args pd lbi uh flags
3540
}
3641

@@ -57,6 +62,30 @@ genBuildInfo verbosity pkg = do
5762
]
5863
rewriteFile targetText buildVersion
5964

65+
genDependencyInfo :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO ()
66+
genDependencyInfo verbosity pkg info = do
67+
let
68+
(PackageName pname) = pkgName . package $ pkg
69+
name = "DependencyInfo_" ++ (map (\c -> if c == '-' then '_' else c) pname)
70+
targetHs = autogenModulesDir info ++ "/" ++ name ++ ".hs"
71+
render p =
72+
let
73+
n = unPackageName $ pkgName p
74+
v = intercalate "." . fmap show . versionBranch $ pkgVersion p
75+
in
76+
n ++ "-" ++ v
77+
deps = fmap (render . sourcePackageId) . allPackages $ installedPkgs info
78+
strs = flip fmap deps $ \d -> "\"" ++ d ++ "\""
79+
80+
createDirectoryIfMissingVerbose verbosity True (autogenModulesDir info)
81+
82+
rewriteFile targetHs $ unlines [
83+
"module " ++ name ++ " where"
84+
, "import Prelude"
85+
, "dependencyInfo :: [String]"
86+
, "dependencyInfo = [\n " ++ intercalate "\n , " strs ++ "\n ]"
87+
]
88+
6089
gitVersion :: Verbosity -> IO String
6190
gitVersion verbosity = do
6291
ver <- rawSystemStdout verbosity "git" ["log", "--pretty=format:%h", "-n", "1"]

lib/disorder

lib/p

Submodule p updated from 57c3bca to 4cc1313

lib/x

Submodule x updated from b6c68fc to 17391c4

main/project.hs

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{-# LANGUAGE OverloadedStrings #-}
33

44
import BuildInfo_ambiata_project
5+
import DependencyInfo_ambiata_project
56

67
import Options.Applicative
78

@@ -19,6 +20,8 @@ main = do
1920
case sc of
2021
VersionCommand ->
2122
putStrLn buildInfoVersion >> exitSuccess
23+
DependencyCommand ->
24+
mapM_ putStrLn dependencyInfo
2225
RunCommand DryRun c ->
2326
print c >> exitSuccess
2427
RunCommand RealRun c ->

project.cabal

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@ library
2121
-Wall
2222

2323
hs-source-dirs:
24-
src gen
24+
src
2525

2626
exposed-modules:
2727
Paths_ambiata_project
28-
BuildInfo_ambiata_project
2928
Project
3029

3130
executable project
3231
ghc-options:
3332
-Wall -threaded -O2
3433

34+
hs-source-dirs:
35+
gen
36+
3537
main-is:
36-
main/project.hs
38+
../main/project.hs
3739

3840
build-depends:
3941
base

0 commit comments

Comments
 (0)