diff --git a/Cabal/src/Distribution/Simple/GHC.hs b/Cabal/src/Distribution/Simple/GHC.hs index 45fbee0fed1..62415e7ea8e 100644 --- a/Cabal/src/Distribution/Simple/GHC.hs +++ b/Cabal/src/Distribution/Simple/GHC.hs @@ -85,7 +85,6 @@ import Prelude () import Control.Arrow ((***)) import Control.Monad (forM_) -import Data.List (stripPrefix) import qualified Data.Map as Map import Distribution.CabalSpecVersion import Distribution.InstalledPackageInfo (InstalledPackageInfo) @@ -248,8 +247,14 @@ configure verbosity hcPath hcPkgPath conf0 = do compilerId :: CompilerId compilerId = CompilerId GHC ghcVersion + -- The @AbiTag@ is the @Project Unit Id@ but with redundant information from the compiler version removed. + -- For development versions of the compiler these look like: + -- @Project Unit Id@: "ghc-9.13-inplace" + -- @compilerId@: "ghc-9.13.20250413" + -- So, we need to be careful to only strip the /common/ prefix. + -- In this example, @AbiTag@ is "inplace". compilerAbiTag :: AbiTag - compilerAbiTag = maybe NoAbiTag AbiTag (Map.lookup "Project Unit Id" ghcInfoMap >>= stripPrefix (prettyShow compilerId <> "-")) + compilerAbiTag = maybe NoAbiTag AbiTag (dropWhile (== '-') . stripCommonPrefix (prettyShow compilerId) <$> Map.lookup "Project Unit Id" ghcInfoMap) let comp = Compiler diff --git a/Cabal/src/Distribution/Simple/Utils.hs b/Cabal/src/Distribution/Simple/Utils.hs index d9109ea162c..067735a8419 100644 --- a/Cabal/src/Distribution/Simple/Utils.hs +++ b/Cabal/src/Distribution/Simple/Utils.hs @@ -195,6 +195,7 @@ module Distribution.Simple.Utils , unintersperse , wrapText , wrapLine + , stripCommonPrefix -- * FilePath stuff , isAbsoluteOnAnyPlatform @@ -2062,3 +2063,10 @@ findHookedPackageDesc verbosity mbWorkDir dir = do buildInfoExt :: String buildInfoExt = ".buildinfo" + +-- | @stripCommonPrefix xs ys@ gives you @ys@ without the common prefix with @xs@. +stripCommonPrefix :: String -> String -> String +stripCommonPrefix (x : xs) (y : ys) + | x == y = stripCommonPrefix xs ys + | otherwise = y : ys +stripCommonPrefix _ ys = ys diff --git a/changelog.d/pr-10979 b/changelog.d/pr-10979 new file mode 100644 index 00000000000..7e3fb85502c --- /dev/null +++ b/changelog.d/pr-10979 @@ -0,0 +1,8 @@ +synopsis: Fix parsing the AbiTag with development versions of GHC +packages: Cabal +prs: #10979 +issues: #10170 + +description: { +- Allow parsing the AbiTag for developmement versions of GHC. +}