haddock suggestion -- %{FILE}

I pre-process my source code before handing to haddock. The %{FILE} directive for --source-comments etc uses the actual preprocessed file name rather than the the original, which is not what I want. Is this just an oversight? - Conal

(oops, I meant to reply to the list as well as to Conal) On Mon, 2007-01-08 at 22:26 -0800, Conal Elliott wrote:
I pre-process my source code before handing to haddock. The %{FILE} directive for --source-comments etc uses the actual preprocessed file name rather than the the original, which is not what I want. Is this just an oversight?
If your pre-processor uses the C or Haskell line pragmas then haddock (as of version 0.8) will know the original file name and the links to source will work (I've tested it). So the question is, what pre-processor are you using, and how can we persuade it to emit C or Haskell line pragmas. cpp can do it, as can cpphs, hsc2hs, c2hs, alex, happy etc. It may be that they don't all do it by default at the moment, or that Cabal doesn't instruct them to do it by default. Previous versions of haddock didn't cope with C style line pragmas iirc so I think they used to be disabled for cpp/cpphs. Duncan

The only pre-processing is what's caused by using the cabal directive
"Extensions: CPP". Using "./setup haddock --verbose ...", I get lines like
c:\ghc\ghc-6.6\bin\ghc.exe -E -cpp -optP-P -o
dist\build\tmp\src\Graphics\UI\TV\Input.hs src\Graphics\UI\TV\Input.hs
-Dmingw32_BUILD_OS -Dmingw32_HOST_OS -Di386_BUILD_ARCH -Di386_HOST_ARCH
-D__GLASGOW_HASKELL__=606 -D__HADDOCK__
When I try this preprocessing myself, I find that I *do not* get the Haskell
line pragma:
bash-3.2$ ghc -E -cpp -optP-P -o z src/Graphics/UI/TV/Input.hs
-Dmingw32_BUILD_OS -Dmingw32_HOST_OS -Di386_BUILD_ARCH -Di386_HOST_ARCH
-D__GLASGOW_HASKELL__=606 -D__HADDOCK__; head -3 z
{-# OPTIONS -fglasgow-exts -cpp #-}
----------------------------------------------------------------------
Fiddling with flags, I see that -optP-P is the culprit. Removing it:
bash-3.2$ ghc -E -cpp -o z src/Graphics/UI/TV/Input.hs -Dmingw32_BUILD_OS
-Dmingw32_HOST_OS -Di386_BUILD_ARCH -Di386_HOST_ARCH
-D__GLASGOW_HASKELL__=606 -D__HADDOCK__; head -3 z
# 1 "src/Graphics/UI/TV/Input.hs"
# 1 "<built-in>"
# 1 "<command line>"
bash-3.2$
Any ideas? - Conal
On 1/9/07, Duncan Coutts
(oops, I meant to reply to the list as well as to Conal)
On Mon, 2007-01-08 at 22:26 -0800, Conal Elliott wrote:
I pre-process my source code before handing to haddock. The %{FILE} directive for --source-comments etc uses the actual preprocessed file name rather than the the original, which is not what I want. Is this just an oversight?
If your pre-processor uses the C or Haskell line pragmas then haddock (as of version 0.8) will know the original file name and the links to source will work (I've tested it).
So the question is, what pre-processor are you using, and how can we persuade it to emit C or Haskell line pragmas. cpp can do it, as can cpphs, hsc2hs, c2hs, alex, happy etc.
It may be that they don't all do it by default at the moment, or that Cabal doesn't instruct them to do it by default. Previous versions of haddock didn't cope with C style line pragmas iirc so I think they used to be disabled for cpp/cpphs.
Duncan
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

"Conal Elliott"
Fiddling with flags, I see that -optP-P is the culprit. Removing it:
bash-3.2$ ghc -E -cpp -o z src/Graphics/UI/TV/Input.hs -Dmingw32_BUILD_OS -Dmingw32_HOST_OS -Di386_BUILD_ARCH -Di386_HOST_ARCH -D__GLASGOW_HASKELL__=606 -D__HADDOCK__; head -3 z # 1 "src/Graphics/UI/TV/Input.hs" # 1 "<built-in>" # 1 "<command line>"
This may not answer your question, but assuming you want to get rid of the last two lines, keeping only the first, have you tried using the options -pgmPcpphs -optP-cpp (with a recent version of cpphs)? Regards, Malcolm

I don't know what -optP-P or these other flags are. Do you know where
they're documented? In any case, the context here is that cabal is
controlling the preprocessing. So whatever the solution is, I'd like it to
come from or through cabal.
Cheers, - Conal
On 1/9/07, Malcolm Wallace
"Conal Elliott"
wrote: Fiddling with flags, I see that -optP-P is the culprit. Removing it:
bash-3.2$ ghc -E -cpp -o z src/Graphics/UI/TV/Input.hs -Dmingw32_BUILD_OS -Dmingw32_HOST_OS -Di386_BUILD_ARCH -Di386_HOST_ARCH -D__GLASGOW_HASKELL__=606 -D__HADDOCK__; head -3 z # 1 "src/Graphics/UI/TV/Input.hs" # 1 "<built-in>" # 1 "<command line>"
This may not answer your question, but assuming you want to get rid of the last two lines, keeping only the first, have you tried using the options -pgmPcpphs -optP-cpp (with a recent version of cpphs)?
Regards, Malcolm _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

"Conal Elliott"
I don't know what -optP-P or these other flags are. Do you know where they're documented?
-optP is a GHC flag, which says to pass the remainder of the string as an argument to the preprocessor. (The preprocessor itself can be specified with GHC's -pgmP flag.) The -P flag to the standard C preprocessor says to omit #line droppings. Regards, Malcolm

On Tue, 2007-01-09 at 09:32 -0800, Conal Elliott wrote:
The only pre-processing is what's caused by using the cabal directive "Extensions: CPP".
Fiddling with flags, I see that -optP-P is the culprit. Removing it:
bash-3.2$ ghc -E -cpp -o z src/Graphics/UI/TV/Input.hs -Dmingw32_BUILD_OS -Dmingw32_HOST_OS -Di386_BUILD_ARCH -Di386_HOST_ARCH -D__GLASGOW_HASKELL__=606 -D__HADDOCK__; head -3 z # 1 "src/Graphics/UI/TV/Input.hs" # 1 "<built-in>" # 1 "<command line>" bash-3.2$
Any ideas? - Conal
So for a quick hack, modify Cabal to unconditionally omit -optP-P and see if that makes all your links come out right. Probably the right thing to do however is to have Cabal use the -optP-P option only when we're using haddock-0.7 or older (otherwise haddock-0.7 users will get a lexical error when haddock encounters the C line pragmas). I think at the moment Cabal doesn't check haddock's version number at all. So that's something to look at if you or anyone else want to come up with a patch for this. Duncan

Commenting out the -optP-P in Haddock's PreProcess.hs fixes the problem.
Thanks.
Any takers for Duncan's suggested fix?
- Conal
On 1/9/07, Duncan Coutts
On Tue, 2007-01-09 at 09:32 -0800, Conal Elliott wrote:
The only pre-processing is what's caused by using the cabal directive "Extensions: CPP".
Fiddling with flags, I see that -optP-P is the culprit. Removing it:
bash-3.2$ ghc -E -cpp -o z src/Graphics/UI/TV/Input.hs -Dmingw32_BUILD_OS -Dmingw32_HOST_OS -Di386_BUILD_ARCH -Di386_HOST_ARCH -D__GLASGOW_HASKELL__=606 -D__HADDOCK__; head -3 z # 1 "src/Graphics/UI/TV/Input.hs" # 1 "<built-in>" # 1 "<command line>" bash-3.2$
Any ideas? - Conal
So for a quick hack, modify Cabal to unconditionally omit -optP-P and see if that makes all your links come out right.
Probably the right thing to do however is to have Cabal use the -optP-P option only when we're using haddock-0.7 or older (otherwise haddock-0.7 users will get a lexical error when haddock encounters the C line pragmas).
I think at the moment Cabal doesn't check haddock's version number at all. So that's something to look at if you or anyone else want to come up with a patch for this.
Duncan

I did get working again by commenting out the "-optP-P" that gets passed to
Haddock. Now I want to eliminate my local mod. I could easily add a
another Cabal Haddock flag that says to omit the -optP-P, but I prefer the
solution of checking the Haddock version number, since it would always do
the right thing with no intervention. Can anyone give me hints about how to
do the version check?
- Conal
On 1/9/07, Duncan Coutts
On Tue, 2007-01-09 at 09:32 -0800, Conal Elliott wrote:
The only pre-processing is what's caused by using the cabal directive "Extensions: CPP".
Fiddling with flags, I see that -optP-P is the culprit. Removing it:
bash-3.2$ ghc -E -cpp -o z src/Graphics/UI/TV/Input.hs -Dmingw32_BUILD_OS -Dmingw32_HOST_OS -Di386_BUILD_ARCH -Di386_HOST_ARCH -D__GLASGOW_HASKELL__=606 -D__HADDOCK__; head -3 z # 1 "src/Graphics/UI/TV/Input.hs" # 1 "<built-in>" # 1 "<command line>" bash-3.2$
Any ideas? - Conal
So for a quick hack, modify Cabal to unconditionally omit -optP-P and see if that makes all your links come out right.
Probably the right thing to do however is to have Cabal use the -optP-P option only when we're using haddock-0.7 or older (otherwise haddock-0.7 users will get a lexical error when haddock encounters the C line pragmas).
I think at the moment Cabal doesn't check haddock's version number at all. So that's something to look at if you or anyone else want to come up with a patch for this.
Duncan

Conal Elliott wrote:
I did get working again by commenting out the "-optP-P" that gets passed to Haddock. Now I want to eliminate my local mod. I could easily add a another Cabal Haddock flag that says to omit the -optP-P, but I prefer the solution of checking the Haddock version number, since it would always do the right thing with no intervention. Can anyone give me hints about how to do the version check?
Take a look at how the GHC version check is done - it should be pretty similar. Cheers, Simon
participants (4)
-
Conal Elliott
-
Duncan Coutts
-
Malcolm Wallace
-
Simon Marlow