-
Notifications
You must be signed in to change notification settings - Fork 0
/
haddock-gen-index.py
38 lines (30 loc) · 1.14 KB
/
haddock-gen-index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#! /usr/bin/env python
import os.path
import subprocess
# Change this to the appropriate version.
GHC_DIR = "C:\\ghc\\ghc-7.4.2"
LIB_DIR = GHC_DIR + "\\lib"
LIB_DOC_DIR = GHC_DIR + "\\doc\\html\\libraries"
def get_field(pkg, fld):
ret = subprocess.check_output(["ghc-pkg", "field", pkg, fld])
return ret.strip()[len(fld)+2:]
read_intf=""
pkgs = subprocess.check_output(["ghc-pkg", "list", "--simple-output"]).split()
for pkg in pkgs:
html = os.path.abspath(get_field(pkg, "haddock-html"))
html = html.replace(LIB_DIR, "..\\..\\..\\lib")
html = html.replace(LIB_DOC_DIR, ".")
intf = os.path.abspath(get_field(pkg, "haddock-interfaces"))
valid = True
if any(pkg.startswith(prefix) for prefix in ["ghc-", "rts-", "hoopl-"]):
valid = False
if pkg.startswith("ghc-prim-"):
valid = True
if not os.path.isfile(intf):
valid = False
print "Invalid interface: " + intf
if valid:
read_intf += (" --read-interface=" + html + ","+ intf)
cmd_line = ["haddock", "--gen-index",
"--gen-contents", "--title=Haskell Platform"] + read_intf.split()
subprocess.check_output(cmd_line)