Skip to content

Commit fecbefb

Browse files
authored
Merge pull request #10979 from haskell/wip/abi-dev-compiler
Fix parsing AbiTag for development compilers
2 parents e6a70eb + 633c83e commit fecbefb

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

Cabal/src/Distribution/Simple/GHC.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ import Prelude ()
8585

8686
import Control.Arrow ((***))
8787
import Control.Monad (forM_)
88-
import Data.List (stripPrefix)
8988
import qualified Data.Map as Map
9089
import Distribution.CabalSpecVersion
9190
import Distribution.InstalledPackageInfo (InstalledPackageInfo)
@@ -248,8 +247,14 @@ configure verbosity hcPath hcPkgPath conf0 = do
248247
compilerId :: CompilerId
249248
compilerId = CompilerId GHC ghcVersion
250249

250+
-- The @AbiTag@ is the @Project Unit Id@ but with redundant information from the compiler version removed.
251+
-- For development versions of the compiler these look like:
252+
-- @Project Unit Id@: "ghc-9.13-inplace"
253+
-- @compilerId@: "ghc-9.13.20250413"
254+
-- So, we need to be careful to only strip the /common/ prefix.
255+
-- In this example, @AbiTag@ is "inplace".
251256
compilerAbiTag :: AbiTag
252-
compilerAbiTag = maybe NoAbiTag AbiTag (Map.lookup "Project Unit Id" ghcInfoMap >>= stripPrefix (prettyShow compilerId <> "-"))
257+
compilerAbiTag = maybe NoAbiTag AbiTag (dropWhile (== '-') . stripCommonPrefix (prettyShow compilerId) <$> Map.lookup "Project Unit Id" ghcInfoMap)
253258

254259
let comp =
255260
Compiler

Cabal/src/Distribution/Simple/Utils.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ module Distribution.Simple.Utils
195195
, unintersperse
196196
, wrapText
197197
, wrapLine
198+
, stripCommonPrefix
198199

199200
-- * FilePath stuff
200201
, isAbsoluteOnAnyPlatform
@@ -2062,3 +2063,10 @@ findHookedPackageDesc verbosity mbWorkDir dir = do
20622063

20632064
buildInfoExt :: String
20642065
buildInfoExt = ".buildinfo"
2066+
2067+
-- | @stripCommonPrefix xs ys@ gives you @ys@ without the common prefix with @xs@.
2068+
stripCommonPrefix :: String -> String -> String
2069+
stripCommonPrefix (x : xs) (y : ys)
2070+
| x == y = stripCommonPrefix xs ys
2071+
| otherwise = y : ys
2072+
stripCommonPrefix _ ys = ys

changelog.d/pr-10979

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
synopsis: Fix parsing the AbiTag with development versions of GHC
2+
packages: Cabal
3+
prs: #10979
4+
issues: #10170
5+
6+
description: {
7+
- Allow parsing the AbiTag for developmement versions of GHC.
8+
}

0 commit comments

Comments
 (0)