Using ghc-8.2.1, with the bundled Cabal-2.0.0.2:
I would expect the following program to produce a new cabal file semantically the same as the one it is passed:
import Distribution.PackageDescription.PrettyPrint
import Distribution.PackageDescription.Parse
import Distribution.Verbosity
import System.Environment
main :: IO ()
main = do
cabal_file : _ <- getArgs
gpd <- readGenericPackageDescription normal cabal_file
writeGenericPackageDescription (cabal_file ++ ".new") gpd
However, when run on doctest.cabal (from doctest-0.11.4), note that (at least) most of the fields from the executable doctest stanza are lost:
https://gist.github.com/duog/0576bf37434fb372bcafb9cbc053d3c1
Yeah, that's a known issue, writeGenericPackageDescription has been incomplete as long as I can rememeber. readGenericPackageDescription >>= writeGenericPackageDescription is basically what the hidden command cabal format does, and I think @phadej has been starting to pay attention (see e.g. #4697).
I think that this is basically a duplicate of #2607. Maybe we should open a single ticket for "cabal format doesn't work" with links to all relevant issues.
Should writeGenericPackageDescription be unexported until it is fixed? I think it's broken state should at least be mentioned in the haddocks.
@duog, maybe for 2.0 branch: it cannot be hidden, as that will be breaking change. Documentation can always be improved.
The issue will be soon fixed in master.
Most helpful comment
@duog, maybe for 2.0 branch: it cannot be hidden, as that will be breaking change. Documentation can always be improved.
The issue will be soon fixed in
master.