Skip to content

Commit 7a9f973

Browse files
committed
Make compiler path not nullable in dumped build-info
Refactor the API slightly s.t. a ConfiguredProgram for the Compiler is passed to build-info generation directly.
1 parent a500675 commit 7a9f973

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

Cabal/src/Distribution/Simple/Build.hs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import Distribution.Simple.BuildTarget
6969
import Distribution.Simple.BuildToolDepends
7070
import Distribution.Simple.PreProcess
7171
import Distribution.Simple.LocalBuildInfo
72+
import Distribution.Simple.Program.Builtin (ghcProgram, ghcjsProgram, uhcProgram, jhcProgram, haskellSuiteProgram)
7273
import Distribution.Simple.Program.Types
7374
import Distribution.Simple.Program.Db
7475
import Distribution.Simple.ShowBuildInfo
@@ -164,7 +165,13 @@ dumpBuildInfo verbosity distPref dumpBuildInfoFlag pkg_descr lbi flags = do
164165
(map (showComponentName . componentLocalName . targetCLBI)
165166
activeTargets)
166167
pwd <- getCurrentDirectory
167-
let (warns, json) = mkBuildInfo pwd pkg_descr lbi flags activeTargets
168+
169+
(compilerProg, _) <- case flavorToProgram (compilerFlavor (compiler lbi)) of
170+
Nothing -> die' verbosity $ "dumpBuildInfo: Unknown compiler flavor: "
171+
++ show (compilerFlavor (compiler lbi))
172+
Just program -> requireProgram verbosity program (withPrograms lbi)
173+
174+
let (warns, json) = mkBuildInfo pwd pkg_descr lbi flags (compilerProg, compiler lbi) activeTargets
168175
buildInfoText = renderJson json
169176
unless (null warns) $
170177
warn verbosity $ "Encountered warnings while dumping build-info:\n"
@@ -178,6 +185,16 @@ dumpBuildInfo verbosity distPref dumpBuildInfoFlag pkg_descr lbi flags = do
178185
where
179186
shouldDumpBuildInfo = fromFlagOrDefault NoDumpBuildInfo dumpBuildInfoFlag == DumpBuildInfo
180187

188+
-- | Given the flavor of the compiler, try to find out
189+
-- which program we need.
190+
flavorToProgram :: CompilerFlavor -> Maybe Program
191+
flavorToProgram GHC = Just ghcProgram
192+
flavorToProgram GHCJS = Just ghcjsProgram
193+
flavorToProgram UHC = Just uhcProgram
194+
flavorToProgram JHC = Just jhcProgram
195+
flavorToProgram HaskellSuite {} = Just haskellSuiteProgram
196+
flavorToProgram _ = Nothing
197+
181198

182199
repl :: PackageDescription -- ^ Mostly information from the .cabal file
183200
-> LocalBuildInfo -- ^ Configuration information

Cabal/src/Distribution/Simple/ShowBuildInfo.hs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,15 @@ mkBuildInfo
9090
-> PackageDescription -- ^ Mostly information from the .cabal file
9191
-> LocalBuildInfo -- ^ Configuration information
9292
-> BuildFlags -- ^ Flags that the user passed to build
93+
-> (ConfiguredProgram, Compiler)
94+
-- ^ Compiler information.
95+
-- Needs to be passed explicitly, as we can't extract that information here
96+
-- without some partial function.
9397
-> [TargetInfo]
9498
-> ([String], Json) -- ^ Json representation of buildinfo alongside generated warnings
95-
mkBuildInfo wdir pkg_descr lbi _flags targetsToBuild = (warnings, JsonObject buildInfoFields)
99+
mkBuildInfo wdir pkg_descr lbi _flags compilerInfo targetsToBuild = (warnings, JsonObject buildInfoFields)
96100
where
97-
buildInfoFields = mkBuildInfo' (mkCompilerInfo (withPrograms lbi) (compiler lbi)) componentInfos
101+
buildInfoFields = mkBuildInfo' (uncurry mkCompilerInfo compilerInfo) componentInfos
98102
componentInfosWithWarnings = map (mkComponentInfo wdir pkg_descr lbi . targetCLBI) targetsToBuild
99103
componentInfos = map snd componentInfosWithWarnings
100104
warnings = concatMap fst componentInfosWithWarnings
@@ -111,23 +115,12 @@ mkBuildInfo' compilerInfo componentInfos =
111115
, "components" .= JsonArray componentInfos
112116
]
113117

114-
mkCompilerInfo :: ProgramDb -> Compiler -> Json
115-
mkCompilerInfo programDb compilerInfo = JsonObject
118+
mkCompilerInfo :: ConfiguredProgram -> Compiler -> Json
119+
mkCompilerInfo compilerProgram compilerInfo = JsonObject
116120
[ "flavour" .= JsonString (prettyShow $ compilerFlavor compilerInfo)
117121
, "compiler-id" .= JsonString (showCompilerId compilerInfo)
118-
, "path" .= path
122+
, "path" .= JsonString (programPath compilerProgram)
119123
]
120-
where
121-
path = maybe JsonNull (JsonString . programPath)
122-
$ (flavorToProgram . compilerFlavor $ compilerInfo)
123-
>>= flip lookupProgram programDb
124-
125-
flavorToProgram :: CompilerFlavor -> Maybe Program
126-
flavorToProgram GHC = Just ghcProgram
127-
flavorToProgram GHCJS = Just ghcjsProgram
128-
flavorToProgram UHC = Just uhcProgram
129-
flavorToProgram JHC = Just jhcProgram
130-
flavorToProgram _ = Nothing
131124

132125
mkComponentInfo :: FilePath -> PackageDescription -> LocalBuildInfo -> ComponentLocalBuildInfo -> ([String], Json)
133126
mkComponentInfo wdir pkg_descr lbi clbi = (warnings, JsonObject $

0 commit comments

Comments
 (0)