Skip to content

Commit 8bdc331

Browse files
committed
Add build-info location to plan.json
1 parent 1bd42ee commit 8bdc331

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

cabal-install/src/Distribution/Client/ProjectPlanOutput.hs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ import Distribution.Simple.GHC
4545
, GhcEnvironmentFileEntry(..), simpleGhcEnvironmentFile
4646
, writeGhcEnvironmentFile )
4747
import Distribution.Simple.BuildPaths
48-
( dllExtension, exeExtension )
48+
( dllExtension, exeExtension, buildInfoPref )
4949
import qualified Distribution.Compat.Graph as Graph
5050
import Distribution.Compat.Graph (Graph, Node)
5151
import qualified Distribution.Compat.Binary as Binary
5252
import Distribution.Simple.Utils
53+
import Distribution.Types.Version
54+
( mkVersion )
5355
import Distribution.Verbosity
5456

5557
import Prelude ()
@@ -150,7 +152,7 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
150152
| Just hash <- [elabPkgSourceHash elab] ] ++
151153
(case elabBuildStyle elab of
152154
BuildInplaceOnly ->
153-
["dist-dir" J..= J.String dist_dir]
155+
["dist-dir" J..= J.String dist_dir] ++ maybeToList buildInfoFileLocation
154156
BuildAndInstall ->
155157
-- TODO: install dirs?
156158
[]
@@ -175,6 +177,20 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
175177
] ++
176178
bin_file (compSolverName comp)
177179
where
180+
-- | Only add build-info file location if the Setup.hs CLI
181+
-- is recent enough to be able to generate build info files.
182+
-- Otherwise, do not add the expected file location.
183+
--
184+
-- Consumers of `plan.json` can use the absence of this file location
185+
-- to indicate that the given component uses `build-type: Custom`
186+
-- with an old lib:Cabal version.
187+
buildInfoFileLocation ::Maybe J.Pair
188+
buildInfoFileLocation
189+
| elabSetupScriptCliVersion elab < mkVersion [3, 5, 0, 0]
190+
= Nothing
191+
| otherwise
192+
= Just ("build-info" J..= J.String (buildInfoPref dist_dir))
193+
178194
packageLocationToJ :: PackageLocation (Maybe FilePath) -> J.Value
179195
packageLocationToJ pkgloc =
180196
case pkgloc of
@@ -259,7 +275,6 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
259275
jdisplay :: Pretty a => a -> J.Value
260276
jdisplay = J.String . prettyShow
261277

262-
263278
-----------------------------------------------------------------------------
264279
-- Project status
265280
--

0 commit comments

Comments
 (0)