Skip to content

Commit 4019d17

Browse files
committed
Only munge internal dependencies when printing when there is no explicit syntax
* In `postProcessInternalDeps` the shadowing logic which existed prior to cabal format 3.4 is implemented in a post processing step. The algorithm there replaces any references to internal sublibraries with an explicit qualifier. For example if you write.. ``` library build-depends: foo library foo ... ``` this is reinterpreted as ``` library build-depends: mylib:foo library foo ... ``` * In `preProcessInternalDeps` the inverse transformation takes place, the goal is to replace `mylib:foo` with just `foo`. * Things go wrong if you are using version 3.0 for your cabal file because - In 3.0 the qualifier syntax is introduced so you can be expliciit about sublibrary dependencies - The shadowing semantics of non-qualified dependencies still exists. So the situation is that the user is explicit about the sublibrary ``` library library qux build-depends: mylib:{mylib, foo} library foo ``` 1. Post-process leaves this alone, the user is already explicit about depending on a sublibrary. 2. Pre-processing then rewrites `mylib:{mylib, foo}` into two dependencies, `mylib` and `foo` (no qualifier). 3. When parsed these are two separate dependencies rather than treated as one dependency, roundtrip test fails. Solution: Only perform the reverse transformation when the cabal library version is <= 3.0 and doesn't support the explicit syntax. Now what happens in these two situations: 1. ``` library build-depends: foo library foo ... ``` this is reinterpreted as ``` library build-depends: mylib:foo library foo ... ``` then printed and parsed exactly the same way. 2. Explicit syntax is parsed and printed without being munged (when supported) Note: Mixins only supported sublibrary qualifiers from 3.4 whilst dependencies supported this from 3.0, hence the lack of guard on the mixins case. Fixes #10283
1 parent 54b4838 commit 4019d17

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

Cabal-syntax/src/Distribution/PackageDescription/PrettyPrint.hs

+5-2
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ preProcessInternalDeps specVer gpd
271271

272272
transformD :: Dependency -> [Dependency]
273273
transformD (Dependency pn vr ln)
274-
| pn == thisPn =
274+
| pn == thisPn && specVer < CabalSpecV3_0 =
275275
if LMainLibName `NES.member` ln
276276
then Dependency thisPn vr mainLibSet : sublibs
277277
else sublibs
@@ -282,9 +282,12 @@ preProcessInternalDeps specVer gpd
282282
]
283283
transformD d = [d]
284284

285+
-- Always perform transformation for mixins as syntax was only introduced in 3.4
286+
-- This guard is uncessary as no transformations take place when cabalSpec >= CabalSpecV3_4 but
287+
-- it more clearly signifies the intent. (See the specVer >= CabalSpecV3_4 line above).
285288
transformM :: Mixin -> Mixin
286289
transformM (Mixin pn (LSubLibName uqn) inc)
287-
| pn == thisPn =
290+
| pn == thisPn && specVer < CabalSpecV3_4 =
288291
mkMixin (unqualComponentNameToPackageName uqn) LMainLibName inc
289292
transformM m = m
290293

Cabal-tests/tests/ParserTests/regressions/issue-6083-b.format

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ library
66
default-language: Haskell2010
77
build-depends:
88
base,
9-
sublib
9+
issue:sublib
1010

1111
library sublib
1212
default-language: Haskell2010
@@ -15,10 +15,10 @@ executable demo-a
1515
main-is: Main.hs
1616
build-depends:
1717
issue,
18-
sublib
18+
issue:sublib
1919

2020
executable demo-b
2121
main-is: Main.hs
2222
build-depends:
2323
issue,
24-
sublib
24+
issue:sublib

cabal-validate/src/Main.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ runHackageTests opts
290290

291291
let
292292
-- See #10284 for why this value is pinned.
293-
hackageTestsIndexState = "--index-state=2024-08-25"
293+
hackageTestsIndexState = "--index-state=2025-01-12"
294294

295295
hackageTest args =
296296
timedWithCwd

0 commit comments

Comments
 (0)