Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

included files via CPP break haddock source links #1440

Open
hasufell opened this issue Dec 2, 2021 · 4 comments
Open

included files via CPP break haddock source links #1440

hasufell opened this issue Dec 2, 2021 · 4 comments

Comments

@hasufell
Copy link
Member

hasufell commented Dec 2, 2021

Prominent example is filepath: https://hackage.haskell.org/package/filepath-1.4.2.1/docs/src/System.FilePath.Posix.html#pathSeparator

Also reported here: haskell/filepath#81

@hasufell
Copy link
Member Author

hasufell commented Dec 2, 2021

The only workaround I found is running cpphs manually to expand the files during development: haskell/filepath#95

@hasufell
Copy link
Member Author

hasufell commented Dec 2, 2021

@gbaz found out in #hackage that another workaround is this:

  1. rename System/FilePath/Posix.hs to System.FilePath/Posix.cpphs and delete CPP pragma
  2. run cabal haddock

This however, will add some junk to the beginning of the file, such as:

{-# LINE 1 "System/FilePath/Posix.cpphs" #-}
# 0 "System/FilePath/Posix.cpphs"
# 0 "<built-in>"
# 0 "<command-line>"
# 12 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4

# 17 "/usr/include/stdc-predef.h" 3 4

... lots of newlines before the actual code...

This seems to break the link destinations... you'll always end up at the top of the source file.

@hasufell
Copy link
Member Author

hasufell commented Dec 2, 2021

Forcing cabal to use cpphs doesn't seem possible: haskell/cabal#4278

@hasufell
Copy link
Member Author

This seems to (somewhat) work:

flag cpphs
  Description: Use cpphs (fixes haddock source links)
  Default:     True
  Manual:      False

library
  ...

  if flag(cpphs)
    ghc-options:        -pgmPcpphs -optP--cpp
    build-tool-depends: cpphs:cpphs

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

No branches or pull requests

1 participant