Skip to content

Commit 8a62993

Browse files
committed
Fixup AbiTag logic to deal with <build>_<host>-<abitag>.
1 parent f140135 commit 8a62993

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Cabal-syntax/src/Distribution/Compiler.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ instance Binary CompilerInfo
229229
instance Structured CompilerInfo
230230
instance NFData CompilerInfo where rnf = genericRnf
231231

232+
-- | AbiTag logic
232233
data AbiTag
233234
= NoAbiTag
234235
| AbiTag String

Cabal-syntax/src/Distribution/Types/UnitId.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Distribution.Types.UnitId
1616
, newSimpleUnitId
1717
, mkLegacyUnitId
1818
, getHSLibraryName
19+
, getAbiTag
1920
) where
2021

2122
import Distribution.Compat.Prelude
@@ -184,3 +185,17 @@ instance Parsec DefUnitId where
184185
-- is to ensure that the 'DefUnitId' invariant holds.
185186
unsafeMkDefUnitId :: UnitId -> DefUnitId
186187
unsafeMkDefUnitId = DefUnitId
188+
189+
-- | The ABI tag is the part of the unit id that comes after the
190+
-- last hyphen. It is used to distinguish between different
191+
-- versions of the same package that are ABI compatible.
192+
--
193+
-- FIXME: ideally this would be part of the proper structure of the
194+
-- datatype, instead of some heuristic of the string.
195+
getAbiTag :: HasCallStack => UnitId -> AbiTag
196+
getAbiTag (UnitId _c s _) = case takeWhile (/= '-') . reverse . fromShortText $ s of
197+
[] -> NoAbiTag
198+
xs -> AbiTag . reverse $ xs
199+
getAbiTag (PartialUnitId s) = case takeWhile (/= '-') . reverse . fromShortText $ s of
200+
[] -> NoAbiTag
201+
xs -> AbiTag . reverse $ xs

Cabal/src/Distribution/Simple/GHC.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ configure verbosity hcPath hcPkgPath conf0 = do
249249
compilerId = CompilerId GHC ghcVersion
250250

251251
compilerAbiTag :: AbiTag
252-
compilerAbiTag = maybe NoAbiTag AbiTag (Map.lookup "Project Unit Id" ghcInfoMap >>= stripPrefix (prettyShow compilerId <> "-"))
252+
compilerAbiTag = fromMaybe NoAbiTag (getAbiTag . fromString <$> Map.lookup "Project Unit Id" ghcInfoMap)
253253

254254
let comp =
255255
Compiler

0 commit comments

Comments
 (0)