@@ -11,12 +11,16 @@ import Distribution.Client.CmdErrorMessages
11
11
import Distribution.Client.CmdInstall.ClientInstallFlags
12
12
13
13
import Distribution.Client.Setup
14
- ( GlobalFlags , ConfigFlags (.. ), ConfigExFlags , InstallFlags )
14
+ ( GlobalFlags , ConfigFlags (.. ), ConfigExFlags , InstallFlags
15
+ )
15
16
import qualified Distribution.Client.Setup as Client
16
17
import Distribution.Simple.Setup
17
- ( HaddockFlags , fromFlagOrDefault , TestFlags )
18
+ ( HaddockFlags , TestFlags
19
+ , fromFlagOrDefault
20
+ )
18
21
import Distribution.Simple.Command
19
- ( CommandUI (.. ), usageAlternatives )
22
+ ( CommandUI (.. ), option , reqArg' , usageAlternatives
23
+ )
20
24
import Distribution.Verbosity
21
25
( Verbosity , silent )
22
26
import Distribution.Simple.Utils
@@ -38,10 +42,12 @@ import Distribution.Client.DistDirLayout (distBuildDirectory)
38
42
import Distribution.Client.Types ( PackageLocation (.. ), GenericReadyPackage (.. ) )
39
43
import Distribution.Client.JobControl (newLock , Lock )
40
44
import Distribution.Simple.Configure (tryGetPersistBuildConfig )
45
+ import qualified Distribution.Client.CmdInstall as CmdInstall
41
46
import Data.List (find )
47
+ import Data.Maybe (fromMaybe )
42
48
43
- showBuildInfoCommand :: CommandUI ( ConfigFlags , ConfigExFlags , InstallFlags , HaddockFlags , TestFlags )
44
- showBuildInfoCommand = Client . installCommand {
49
+ showBuildInfoCommand :: CommandUI ShowBuildInfoFlags
50
+ showBuildInfoCommand = CmdInstall . installCommand {
45
51
commandName = " new-show-build-info" ,
46
52
commandSynopsis = " Show project build information" ,
47
53
commandUsage = usageAlternatives " new-show-build-info" [ " [TARGETS] [FLAGS]" ],
@@ -56,9 +62,35 @@ showBuildInfoCommand = Client.installCommand {
56
62
++ " Shows build information about the current package\n "
57
63
++ " " ++ pname ++ " new-show-build-info ./pkgname \n "
58
64
++ " Shows build information about the package located in './pkgname'\n "
59
- ++ cmdCommonHelpTextNewBuildBeta
65
+ ++ cmdCommonHelpTextNewBuildBeta,
66
+ commandOptions = \ showOrParseArgs ->
67
+ Client. liftOptions buildInfoInstallCommandFlags (\ pf flags -> flags { buildInfoInstallCommandFlags = pf }) (commandOptions CmdInstall. installCommand showOrParseArgs)
68
+ ++
69
+ [ option [] [" buildinfo-json-output" ]
70
+ " Write the result to the given file instead of stdout"
71
+ buildInfoOutputFile (\ pf flags -> flags { buildInfoOutputFile = pf })
72
+ (reqArg' " FILE" Just (maybe [] pure )),
73
+ option [] [" unit-ids-json" ]
74
+ " Show build-info only for selected unit-id's."
75
+ buildInfoUnitIds (\ pf flags -> flags { buildInfoUnitIds = pf })
76
+ (reqArg' " UNIT-ID" (Just . words ) (fromMaybe [] ))
77
+ ],
78
+ commandDefaultFlags = defaultShowBuildInfoFlags
79
+
60
80
}
61
81
82
+ data ShowBuildInfoFlags = ShowBuildInfoFlags
83
+ { buildInfoInstallCommandFlags :: (ConfigFlags , ConfigExFlags , InstallFlags , HaddockFlags , TestFlags , ClientInstallFlags )
84
+ , buildInfoOutputFile :: Maybe FilePath
85
+ , buildInfoUnitIds :: Maybe [String ]
86
+ }
87
+
88
+ defaultShowBuildInfoFlags :: ShowBuildInfoFlags
89
+ defaultShowBuildInfoFlags = ShowBuildInfoFlags
90
+ { buildInfoInstallCommandFlags = (mempty , mempty , mempty , mempty , mempty , mempty )
91
+ , buildInfoOutputFile = Nothing
92
+ , buildInfoUnitIds = Nothing
93
+ }
62
94
63
95
-- | The @show-build-info@ command does a lot. It brings the install plan up to date,
64
96
-- selects that part of the plan needed by the given or implicit targets and
@@ -67,11 +99,10 @@ showBuildInfoCommand = Client.installCommand {
67
99
-- For more details on how this works, see the module
68
100
-- "Distribution.Client.ProjectOrchestration"
69
101
--
70
- showBuildInfoAction :: ( ConfigFlags , ConfigExFlags , InstallFlags , HaddockFlags , TestFlags )
102
+ showBuildInfoAction :: ShowBuildInfoFlags
71
103
-> [String ] -> GlobalFlags -> IO ()
72
- showBuildInfoAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags)
104
+ showBuildInfoAction (ShowBuildInfoFlags ( configFlags, configExFlags, installFlags, haddockFlags, testFlags, clientInstallFlags) fileOutput unitIds )
73
105
targetStrings globalFlags = do
74
-
75
106
baseCtx <- establishProjectBaseContext verbosity cliConfig
76
107
let baseCtx' = baseCtx {
77
108
buildSettings = (buildSettings baseCtx) {
@@ -99,32 +130,36 @@ showBuildInfoAction (configFlags, configExFlags, installFlags, haddockFlags, tes
99
130
return (elaboratedPlan, targets)
100
131
101
132
scriptLock <- newLock
102
- showTargets verbosity baseCtx' buildCtx scriptLock
133
+ showTargets fileOutput unitIds verbosity baseCtx' buildCtx scriptLock
103
134
104
135
where
105
136
-- Default to silent verbosity otherwise it will pollute our json output
106
137
verbosity = fromFlagOrDefault silent (configVerbosity configFlags)
107
138
cliConfig = commandLineFlagsToProjectConfig
108
139
globalFlags configFlags configExFlags
109
- installFlags mempty -- Not needed here
140
+ installFlags clientInstallFlags
110
141
haddockFlags
111
142
testFlags
112
143
113
144
-- Pretty nasty piecemeal out of json, but I can't see a way to retrieve output of the setupWrapper'd tasks
114
- showTargets :: Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> IO ()
115
- showTargets verbosity baseCtx buildCtx lock = do
116
- putStr " ["
117
- mapM_ showSeparated (zip [0 .. ] targets)
118
- putStrLn " ]"
145
+ showTargets :: Maybe FilePath -> Maybe [String ] -> Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> IO ()
146
+ showTargets fileOutput unitIds verbosity baseCtx buildCtx lock = do
147
+ case fileOutput of
148
+ Nothing -> do
149
+ putStr " ["
150
+ mapM_ doShowInfo targets
151
+ putStrLn " ]"
152
+ Just fp -> do
153
+ writeFile fp " ["
154
+ mapM_ doShowInfo targets
155
+ appendFile fp " ]"
156
+
119
157
where configured = [p | InstallPlan. Configured p <- InstallPlan. toList (elaboratedPlanOriginal buildCtx)]
120
158
targets = fst <$> (Map. toList . targetsMap $ buildCtx)
121
- doShowInfo unitId = showInfo verbosity baseCtx buildCtx lock configured unitId
122
- showSeparated (idx, unitId)
123
- | idx == length targets - 1 = doShowInfo unitId
124
- | otherwise = doShowInfo unitId >> putStrLn " ,"
159
+ doShowInfo unitId = showInfo fileOutput unitIds verbosity baseCtx buildCtx lock configured unitId
125
160
126
- showInfo :: Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> [ElaboratedConfiguredPackage ] -> UnitId -> IO ()
127
- showInfo verbosity baseCtx buildCtx lock pkgs targetUnitId
161
+ showInfo :: Maybe FilePath -> Maybe [ String ] -> Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> [ElaboratedConfiguredPackage ] -> UnitId -> IO ()
162
+ showInfo fileOutput unitIds verbosity baseCtx buildCtx lock pkgs targetUnitId
128
163
| Nothing <- mbPkg = die' verbosity $ " No unit " ++ show targetUnitId
129
164
| Just pkg <- mbPkg = do
130
165
let shared = elaboratedShared buildCtx
@@ -155,15 +190,22 @@ showInfo verbosity baseCtx buildCtx lock pkgs targetUnitId
155
190
scriptOptions
156
191
(Just $ elabPkgDescription pkg)
157
192
(Cabal. configureCommand defaultProgramDb)
158
- (const $ configureFlags)
193
+ (const configureFlags)
159
194
(const configureArgs)
160
195
Right _ -> pure ()
196
+
161
197
setupWrapper
162
198
verbosity
163
199
scriptOptions
164
200
(Just $ elabPkgDescription pkg)
165
201
(Cabal. showBuildInfoCommand defaultProgramDb)
166
- (const flags)
202
+ (const (Cabal. ShowBuildInfoFlags
203
+ { Cabal. buildInfoBuildFlags = flags
204
+ , Cabal. buildInfoOutputFile = fileOutput
205
+ , Cabal. buildInfoUnitIds = unitIds
206
+ }
207
+ )
208
+ )
167
209
(const args)
168
210
where mbPkg = find ((targetUnitId == ) . elabUnitId) pkgs
169
211
0 commit comments