Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

can't install with haddock 2.13.1 #1

Closed
osa1 opened this Issue · 20 comments

3 participants

Ömer Sinan Ağacan Chris Done Alexander Vershilov
Ömer Sinan Ağacan
➜  haskell-docs git:(master) haddock --version
Haddock version 2.13.1, (c) Simon Marlow 2006
Ported to use the GHC API by David Waern 2006-2008

➜  haskell-docs git:(master) ghc-pkg list | grep haddock
    haddock-2.13.1

➜  haskell-docs git:(master) cabal install --constraint haddock==2.13.1
Resolving dependencies...
Configuring haskell-docs-0.1.1.0...
Building haskell-docs-0.1.1.0...
Preprocessing executable 'haskell-docs' for haskell-docs-0.1.1.0...
[1 of 1] Compiling Main             ( src/Main.hs, dist/build/haskell-docs/haskell-docs-tmp/Main.o )

src/Main.hs:177:7: Not in scope: data constructor `DocURL'
Failed to install haskell-docs-0.1.1.0
cabal: Error: some packages failed to install:
haskell-docs-0.1.1.0 failed during the building phase. The exception was:
ExitFailure 1
ghci> :m + Documentation.Haddock 
ghci> :info Doc
data Doc id
  = DocEmpty
  | DocAppend (Doc id) (Doc id)
  | DocString String
  | DocParagraph (Doc id)
  | DocIdentifier id
  | DocIdentifierUnchecked (ghc-7.6.1:Module.ModuleName,
                            ghc-7.6.1:OccName.OccName)
  | DocModule String
  | DocWarning (Doc id)
  | DocEmphasis (Doc id)
  | DocMonospaced (Doc id)
  | DocUnorderedList [Doc id]
  | DocOrderedList [Doc id]
  | DocDefList [(Doc id, Doc id)]
  | DocCodeBlock (Doc id)
  | DocHyperlink Hyperlink
  | DocPic String
  | DocAName String
  | DocProperty String
  | DocExamples [Example]
        -- Defined in `haddock-2.13.1:Haddock.Types'
instance Functor Doc -- Defined in `haddock-2.13.1:Haddock.Types'

Looks like it's removed in a release between 2.10 and 2.13. I couldn't specify the exact version number because most versions don't have documentation on hackage.

Chris Done
Owner

Seems like it's been replaced with DocHyperlink.

Ömer Sinan Ağacan

Yep, unfortunately, changing that line with go (DocHyperlink url) = hyperlinkUrl url throws other unrelated problems, seems like there are other API changes too:

[1 of 1] Compiling Main             ( src/Main.hs, dist/build/haskell-docs/haskell-docs-tmp/Main.o )

src/Main.hs:226:13:
    Couldn't match expected type `IO DynFlags'
                with actual type `m0 a0 -> m0 a0'
    In a stmt of a 'do' block:
      dflags <- defaultErrorHandler defaultLogAction
                $ runGhc (Just libdir)
                  $ do { dflags <- getSessionDynFlags;
                         setSessionDynFlags dflags;
                         return dflags }
    In the expression:
      do { dflags <- defaultErrorHandler defaultLogAction
                     $ runGhc (Just libdir)
                       $ do { dflags <- getSessionDynFlags;
                              setSessionDynFlags dflags;
                              .... };
           (dflags, packageids) <- initPackages dflags;
           cont dflags }
    In an equation for `withInitializedPackages':
        withInitializedPackages cont
          = do { dflags <- defaultErrorHandler defaultLogAction
                           $ runGhc (Just libdir)
                             $ do { dflags <- getSessionDynFlags;
                                    .... };
                 (dflags, packageids) <- initPackages dflags;
                 cont dflags }

src/Main.hs:226:33:
    Couldn't match type `DynFlags' with `[Char]'
    Expected type: DynFlags.FatalMessager
      Actual type: DynFlags.LogAction
    In the first argument of `defaultErrorHandler', namely
      `defaultLogAction'
    In the expression: defaultErrorHandler defaultLogAction
    In a stmt of a 'do' block:
      dflags <- defaultErrorHandler defaultLogAction
                $ runGhc (Just libdir)
                  $ do { dflags <- getSessionDynFlags;
                         setSessionDynFlags dflags;
                         return dflags }

src/Main.hs:226:52:
    Couldn't match expected type `DynFlags.FlushOut'
                with actual type `IO DynFlags'
    In the second argument of `($)', namely
      `runGhc (Just libdir)
       $ do { dflags <- getSessionDynFlags;
              setSessionDynFlags dflags;
              return dflags }'
    In a stmt of a 'do' block:
      dflags <- defaultErrorHandler defaultLogAction
                $ runGhc (Just libdir)
                  $ do { dflags <- getSessionDynFlags;
                         setSessionDynFlags dflags;
                         return dflags }
    In the expression:
      do { dflags <- defaultErrorHandler defaultLogAction
                     $ runGhc (Just libdir)
                       $ do { dflags <- getSessionDynFlags;
                              setSessionDynFlags dflags;
                              .... };
           (dflags, packageids) <- initPackages dflags;
           cont dflags }
Failed to install haskell-docs-0.1.1.0

Maybe I can investigate this further and suggest a fix later.

Ömer Sinan Ağacan

Yay, I made it work. defaultErrorHandler is changed too, and now it takes one more parameter. I have no idea how we can make it work under both versions. hmm..

Edit: Here are the changes that make it work under GHC 7.6.1 and Haddock 2.13.1 (generated with git format-patch):

From ff1cb5216b35a08d107d9660d89ec6f683a38e39 Mon Sep 17 00:00:00 2001
From: osa1 <omeragacan@gmail.com>
Date: Thu, 27 Dec 2012 18:03:38 +0200
Subject: [PATCH 1/2] fix for haddock 2.13.1

---
 src/Main.hs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Main.hs b/src/Main.hs
index 697ba8f..b7f9faf 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -174,7 +174,7 @@ formatDoc = trim . go where
   go (DocOrderedList i) = unlines (zipWith (\i x -> show i ++ ". " ++ go x) [1..] i)
   go (DocDefList xs) = unlines (map (\(i,x) -> go i ++ ". " ++ go x) xs)
   go (DocCodeBlock block) = unlines (map ("    " ++) (lines (go block))) ++ "\n"
-  go (DocURL url) = url
+  go (DocHyperlink url) = hyperlinkUrl url
   go (DocPic pic) = pic
   go (DocAName name) = name
   go (DocExamples exs) = unlines (map formatExample exs)
-- 
1.8.0.1


From 18265bb3b9bd6130d71966a34d8beaa8a96ddf05 Mon Sep 17 00:00:00 2001
From: osa1 <omeragacan@gmail.com>
Date: Thu, 27 Dec 2012 18:04:05 +0200
Subject: [PATCH 2/2] fix for ghc 7.6.1

---
 src/Main.hs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/Main.hs b/src/Main.hs
index b7f9faf..4966db5 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -40,7 +40,7 @@ import           Data.List
 import           Data.Map (Map)
 import qualified Data.Map as M
 import           Documentation.Haddock
-import           DynFlags (defaultLogAction)
+import           DynFlags (defaultFlushOut, defaultFatalMessager)
 import           GHC hiding (flags, verbosity)
 import           GHC.Paths (libdir)
 import           Module
@@ -223,7 +223,7 @@ getHaddockInterfacesByPackage = mapM (readInterfaceFile freshNameCache) . haddoc
 -- | Run an action with an initialized GHC package set.
 withInitializedPackages :: (DynFlags -> IO a) -> IO a
 withInitializedPackages cont = do
-  dflags <- defaultErrorHandler defaultLogAction $ runGhc (Just libdir) $ do
+  dflags <- defaultErrorHandler defaultFatalMessager defaultFlushOut $ runGhc (Just libdir) $ do
     dflags <- getSessionDynFlags
     setSessionDynFlags dflags
     return dflags
-- 
1.8.0.1
Chris Done
Owner

Can you please send a pull request with the diff or send the diff here? We can use the CPP #ifdef for GHC version, I think.

Ömer Sinan Ağacan

Aha, I added the patch before seeing your comment, see my last comment above :)

edit: first commit fixes for haddock, and second commit fixes for ghc.

Alexander Vershilov

Full patch thank is will be used in gentoo:

diff --git a/src/Main.hs b/src/Main.hs
index 697ba8f..5d2b257 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -1,6 +1,7 @@
 {-# OPTIONS -Wall -fno-warn-orphans #-}
 {-# LANGUAGE FlexibleInstances #-}
 {-# LANGUAGE StandaloneDeriving #-}
+{-# LANGUAGE CPP #-}

 -- | Lookup the documentation of a name in a module (and in a specific
 -- package in the case of ambiguity).
@@ -40,7 +41,7 @@ import           Data.List
 import           Data.Map (Map)
 import qualified Data.Map as M
 import           Documentation.Haddock
-import           DynFlags (defaultLogAction)
+import           DynFlags (defaultFlushOut, defaultFatalMessager)
 import           GHC hiding (flags, verbosity)
 import           GHC.Paths (libdir)
 import           Module
@@ -174,7 +175,11 @@ formatDoc = trim . go where
   go (DocOrderedList i) = unlines (zipWith (\i x -> show i ++ ". " ++ go x) [1..] i)
   go (DocDefList xs) = unlines (map (\(i,x) -> go i ++ ". " ++ go x) xs)
   go (DocCodeBlock block) = unlines (map ("    " ++) (lines (go block))) ++ "\n"
+#if MIN_VERSION_haddock(2,13,1)
+  go (DocHyperlink (Hyperlink url label)) = maybe url (\l -> l ++ "[" ++ url ++ "]") label
+#else
   go (DocURL url) = url
+#endif
   go (DocPic pic) = pic
   go (DocAName name) = name
   go (DocExamples exs) = unlines (map formatExample exs)
@@ -223,7 +228,7 @@ getHaddockInterfacesByPackage = mapM (readInterfaceFile freshNameCache) . haddoc
 -- | Run an action with an initialized GHC package set.
 withInitializedPackages :: (DynFlags -> IO a) -> IO a
 withInitializedPackages cont = do
-  dflags <- defaultErrorHandler defaultLogAction $ runGhc (Just libdir) $ do
+  dflags <- defaultErrorHandler defaultFatalMessager defaultFlushOut $ runGhc (Just libdir) $ do
     dflags <- getSessionDynFlags
     setSessionDynFlags dflags
     return dflags
Chris Done
Owner

Ahh, cool, thanks!

Chris Done
Owner

@qnikst I pushed a patch which includes this #if and also for GHC 7.6.1. Does it compile on your machine?

Alexander Vershilov

on GHC 7.6.1 it fails with

    Couldn't match type `DynFlags' with `[Char]'
    Expected type: DynFlags.FatalMessager
      Actual type: DynFlags.LogAction

you need for ghc-7.6 #if __GLASGOW_HASKELL__ < 706

Chris Done
Owner

Ah, okay.

Chris Done
Owner

How about now?

Alexander Vershilov

<= doesn't work for ghc 7.6.1 and I have no ghc-7.6.0 to check it.

Ömer Sinan Ağacan

doesn't work for me too. macros are being expanded to else part. strange.

Chris Done
Owner

Ah, my bad, I'll change to <.

Chris Done
Owner

Updated with GHC < 706.

Ömer Sinan Ağacan

now it works. thanks.

Alexander Vershilov

works for me, thanks. I'll check ghc-7.4 box as soon as I will prepared and report if there will be any problems.

Chris Done
Owner

Yay!

Chris Done
Owner

@qnikst I'm working locally with 7.4.1, fwiw.

Chris Done
Owner

Released a hackage version.

Chris Done chrisdone closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.