Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cabal format is not listed in --help message #2460

Open
osa1 opened this issue Mar 9, 2015 · 4 comments
Open

cabal format is not listed in --help message #2460

osa1 opened this issue Mar 9, 2015 · 4 comments

Comments

@osa1
Copy link

osa1 commented Mar 9, 2015

Any ideas why this command is hidden? I recently discovered this and I think it's very useful.

@23Skidoo
Copy link
Member

23Skidoo commented Mar 9, 2015

There are some bugs, e.g. #2353.

@23Skidoo
Copy link
Member

Fixing this is trivial, but we'll need to fix #2661 and #2681 first before making this feature public. See discussion in #2607, specifically #2607 (comment).

@gbaz
Copy link
Collaborator

gbaz commented Mar 17, 2018

It looks like both the referenced bugs were fixed. Are there any further blockers?

@gbaz
Copy link
Collaborator

gbaz commented Mar 17, 2018

Here's a script I bodged together from the one in the other ticket, but updated for the latest cabal.

module Main (main) where

import Control.Monad
import Control.Applicative
import Distribution.Verbosity
import Distribution.Client.IndexUtils
import qualified Distribution.PackageDescription.Parsec as PackageDesc.Parse
import Distribution.PackageDescription.PrettyPrint
import Distribution.ParseUtils
import qualified Data.ByteString.Char8 as BS
import Data.List

check :: FilePath -> IO ()
check cabal = do
  print cabal
  cabalfile <- BS.readFile cabal
  let desc1 = parsePackageDescription  cabalfile
  case desc1 of
    Nothing -> print "failparse"
    Just desc -> do
      let desc' = parsePackageDescription $ BS.pack (showGenericPackageDescription desc)
      when (Just desc /= desc') $ do
        print $  Just desc
        print $  desc'
        fail cabal

parsePackageDescription content = either (const Nothing) Just $ snd $ PackageDesc.Parse.runParseResult $ PackageDesc.Parse.parseGenericPackageDescription $ content

myFilter x  = not $ "lambdaBase" `isInfixOf` x || "wiringPi" `isInfixOf` x || "constrained-monads" `isInfixOf` x

main :: IO ()
main = do
  -- Generate listing with
  -- find . -type f -name '*.cabal' > cabal-files
  cabalFiles <- Prelude.filter myFilter . Prelude.lines <$> Prelude.readFile "cabal-files"
  mapM_ check cabalFiles

The errors it seems to run into are all about round-trips with character encodings.

E.g. in the original you have something like copyright = "2016 Donnacha Ois\237n Kidney", and in the processed file you have copyright = "2016 Donnacha Ois\65533 Kidney"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants