Skip to content

Commit f94e8cc

Browse files
committed
Extract 'dumpBuildInfo' function
1 parent 81fc0b9 commit f94e8cc

File tree

1 file changed

+40
-21
lines changed

1 file changed

+40
-21
lines changed

Cabal/src/Distribution/Simple/Build.hs

+40-21
Original file line numberDiff line numberDiff line change
@@ -117,26 +117,7 @@ build pkg_descr lbi flags suffixes = do
117117
-- Before the actual building, dump out build-information.
118118
-- This way, if the actual compilation failed, the options have still been
119119
-- dumped.
120-
when shouldDumpBuildInfo $ do
121-
-- Changing this line might break consumers of the dumped build info.
122-
-- Announce changes on mailing lists!
123-
let activeTargets = allTargetsInBuildOrder' pkg_descr lbi
124-
info verbosity $ "Dump build information for: "
125-
++ intercalate ", "
126-
(map (showComponentName . componentLocalName . targetCLBI)
127-
activeTargets)
128-
pwd <- getCurrentDirectory
129-
let (warns, json) = mkBuildInfo pwd pkg_descr lbi flags activeTargets
130-
buildInfoText = renderJson json
131-
unless (null warns) $
132-
warn verbosity $ "Encountered warnings while dumping build-info:\n"
133-
++ unlines warns
134-
LBS.writeFile (buildInfoPref distPref) buildInfoText
135-
136-
when (not shouldDumpBuildInfo) $ do
137-
-- Remove existing build-info.json as it might be outdated now.
138-
exists <- doesFileExist (buildInfoPref distPref)
139-
when exists $ removeFile (buildInfoPref distPref)
120+
dumpBuildInfo verbosity distPref (configDumpBuildInfo (configFlags lbi)) pkg_descr lbi flags
140121

141122
-- Now do the actual building
142123
(\f -> foldM_ f (installedPkgs lbi) componentsToBuild) $ \index target -> do
@@ -158,7 +139,45 @@ build pkg_descr lbi flags suffixes = do
158139
where
159140
distPref = fromFlag (buildDistPref flags)
160141
verbosity = fromFlag (buildVerbosity flags)
161-
shouldDumpBuildInfo = fromFlagOrDefault NoDumpBuildInfo (configDumpBuildInfo (configFlags lbi)) == DumpBuildInfo
142+
143+
144+
-- | Write available build information for 'LocalBuildInfo' to disk.
145+
--
146+
-- Dumps detailed build information 'build-info.json' to the given directory.
147+
-- Build information contains basics such as compiler details, but also
148+
-- lists what modules a component contains and how to compile the component, assuming
149+
-- lib:Cabal made sure that dependencies are up-to-date.
150+
dumpBuildInfo :: Verbosity
151+
-> FilePath -- ^ To which directory should the build-info be dumped?
152+
-> Flag DumpBuildInfo -- ^ Should we dump detailed build information for this component?
153+
-> PackageDescription -- ^ Mostly information from the .cabal file
154+
-> LocalBuildInfo -- ^ Configuration information
155+
-> BuildFlags -- ^ Flags that the user passed to build
156+
-> IO ()
157+
dumpBuildInfo verbosity distPref dumpBuildInfoFlag pkg_descr lbi flags = do
158+
when shouldDumpBuildInfo $ do
159+
-- Changing this line might break consumers of the dumped build info.
160+
-- Announce changes on mailing lists!
161+
let activeTargets = allTargetsInBuildOrder' pkg_descr lbi
162+
info verbosity $ "Dump build information for: "
163+
++ intercalate ", "
164+
(map (showComponentName . componentLocalName . targetCLBI)
165+
activeTargets)
166+
pwd <- getCurrentDirectory
167+
let (warns, json) = mkBuildInfo pwd pkg_descr lbi flags activeTargets
168+
buildInfoText = renderJson json
169+
unless (null warns) $
170+
warn verbosity $ "Encountered warnings while dumping build-info:\n"
171+
++ unlines warns
172+
LBS.writeFile (buildInfoPref distPref) buildInfoText
173+
174+
when (not shouldDumpBuildInfo) $ do
175+
-- Remove existing build-info.json as it might be outdated now.
176+
exists <- doesFileExist (buildInfoPref distPref)
177+
when exists $ removeFile (buildInfoPref distPref)
178+
where
179+
shouldDumpBuildInfo = fromFlagOrDefault NoDumpBuildInfo dumpBuildInfoFlag == DumpBuildInfo
180+
162181

163182
repl :: PackageDescription -- ^ Mostly information from the .cabal file
164183
-> LocalBuildInfo -- ^ Configuration information

0 commit comments

Comments
 (0)