[commit: haddock] ghc-head, ghc-head1, master, wip/T14529, wip/revert-ttg-2017-11-20, wip/ttg-2017-11-06, wip/ttg2-2017-11-10, wip/ttg3-2017-11-12, wip/ttg4-constraints-2017-11-13, wip/ttg6-unrevert-2017-11-22: Write meta.json when generating html output (#676) (f506a35)

git at git.haskell.org git at git.haskell.org
Tue Nov 28 11:54:44 UTC 2017


Repository : ssh://git@git.haskell.org/haddock

On branches: ghc-head,ghc-head1,master,wip/T14529,wip/revert-ttg-2017-11-20,wip/ttg-2017-11-06,wip/ttg2-2017-11-10,wip/ttg3-2017-11-12,wip/ttg4-constraints-2017-11-13,wip/ttg6-unrevert-2017-11-22
Link       : http://git.haskell.org/haddock.git/commitdiff/f506a356cec79336d516a4b5b0d1948bbce8c78b

>---------------------------------------------------------------

commit f506a356cec79336d516a4b5b0d1948bbce8c78b
Author: Alexander Biehl <alexbiehl at gmail.com>
Date:   Wed Aug 30 09:24:56 2017 +0200

    Write meta.json when generating html output (#676)


>---------------------------------------------------------------

f506a356cec79336d516a4b5b0d1948bbce8c78b
 CHANGES.md                               |  2 ++
 haddock-api/haddock-api.cabal            |  1 +
 haddock-api/src/Haddock.hs               |  2 ++
 haddock-api/src/Haddock/Backends/Meta.hs | 22 ++++++++++++++++++++++
 haddock.cabal                            |  1 +
 5 files changed, 28 insertions(+)

diff --git a/CHANGES.md b/CHANGES.md
index f96ac32..3e3498c 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -2,6 +2,8 @@
 
  * to be released
 
+ * Haddock now writes additional information about the documentation to `meta.json`
+
  * Fix renaming of type variables after specializing instance method signatures (#613)
 
  * Move markup related data types to haddock-library
diff --git a/haddock-api/haddock-api.cabal b/haddock-api/haddock-api.cabal
index d4132ce..9d83f54 100644
--- a/haddock-api/haddock-api.cabal
+++ b/haddock-api/haddock-api.cabal
@@ -89,6 +89,7 @@ library
     Haddock.Backends.Xhtml.Types
     Haddock.Backends.Xhtml.Utils
     Haddock.Backends.LaTeX
+    Haddock.Backends.Meta
     Haddock.Backends.HaddockDB
     Haddock.Backends.Hoogle
     Haddock.Backends.Hyperlinker
diff --git a/haddock-api/src/Haddock.hs b/haddock-api/src/Haddock.hs
index 554cb41..1795106 100644
--- a/haddock-api/src/Haddock.hs
+++ b/haddock-api/src/Haddock.hs
@@ -29,6 +29,7 @@ import Data.Version
 import Haddock.Backends.Xhtml
 import Haddock.Backends.Xhtml.Themes (getThemes)
 import Haddock.Backends.LaTeX
+import Haddock.Backends.Meta
 import Haddock.Backends.Hoogle
 import Haddock.Backends.Hyperlinker
 import Haddock.Interface
@@ -319,6 +320,7 @@ render dflags flags qual ifaces installedIfaces extSrcMap = do
                 opt_contents_url opt_index_url unicode qual
                 pretty
     copyHtmlBits odir libDir themes
+    writeHaddockMeta odir
 
   -- TODO: we throw away Meta for both Hoogle and LaTeX right now,
   -- might want to fix that if/when these two get some work on them
diff --git a/haddock-api/src/Haddock/Backends/Meta.hs b/haddock-api/src/Haddock/Backends/Meta.hs
new file mode 100644
index 0000000..c62c1ae
--- /dev/null
+++ b/haddock-api/src/Haddock/Backends/Meta.hs
@@ -0,0 +1,22 @@
+module Haddock.Backends.Meta where
+
+import Haddock.Utils.Json
+import Haddock.Version
+
+import Data.ByteString.Builder (hPutBuilder)
+import System.FilePath ((</>))
+import System.IO (withFile, IOMode (WriteMode))
+
+-- | Writes a json encoded file containing additional
+-- information about the generated documentation. This
+-- is useful for external tools (e.g. hackage).
+writeHaddockMeta :: FilePath -> IO ()
+writeHaddockMeta odir = do
+  let
+    meta_json :: Value
+    meta_json = object [
+        "haddock_version" .= String projectVersion
+      ]
+
+  withFile (odir </> "meta.json") WriteMode $ \h ->
+    hPutBuilder h (encodeToBuilder meta_json)
\ No newline at end of file
diff --git a/haddock.cabal b/haddock.cabal
index e6c6709..51f7127 100644
--- a/haddock.cabal
+++ b/haddock.cabal
@@ -125,6 +125,7 @@ executable haddock
       Haddock.Backends.Xhtml.Types
       Haddock.Backends.Xhtml.Utils
       Haddock.Backends.LaTeX
+      Haddock.Backends.Meta
       Haddock.Backends.HaddockDB
       Haddock.Backends.Hoogle
       Haddock.Backends.Hyperlinker



More information about the ghc-commits mailing list