git.iko.soy/typeable/pandoc
on master help sign in
Use hsb2hs preprocessor instead of TH for embed_data_files.

This should work on Windows, unlike the TH solution with file-embed.

commitfe337b07f7c0a15ac792275ed8fb88d3fa5247a3 authorJohn MacFarlane <fiddlosopher@gmail.com> dateWed 23 Jan 2013, 08:33 (14 years ago) parentdaeb52d
4 files changed+23−9
INSTALL+1 Setup.hs+17−1 pandoc.cabal+2−5 src/Text/Pandoc/Data.hs → src/Text/Pandoc/Data.hsb+3−3
INSTALL+1
@@ -94,6 +94,7 @@ It is possible to compile pandoc such that the data files
9494pandoc uses are embedded in the binary. The resulting binary
9595can be run from any directory and is completely self-contained.
9696
97+ cabal install hsb2hs # a required build tool
9798 cabal install --flags="embed_data_files" citeproc-hs
9899 cabal configure --flags="embed_data_files"
99100 cabal build
Setup.hs+17−1
@@ -1,6 +1,7 @@
11{-# LANGUAGE CPP #-}
22
33import Distribution.Simple
4+import Distribution.Simple.PreProcess
45import Distribution.Simple.Setup
56 (copyDest, copyVerbosity, fromFlag, installVerbosity, BuildFlags(..))
67import Distribution.PackageDescription (PackageDescription(..), Executable(..))
@@ -8,10 +9,11 @@ import Distribution.Simple.LocalBuildInfo
89 (LocalBuildInfo(..), absoluteInstallDirs)
910import Distribution.Verbosity ( Verbosity, silent )
1011import Distribution.Simple.InstallDirs (mandir, CopyDest (NoCopyDest))
11−import Distribution.Simple.Utils (installOrdinaryFiles)
12+import Distribution.Simple.Utils (installOrdinaryFiles, info)
1213import Prelude hiding (catch)
1314import System.Process ( rawSystem )
1415import System.FilePath ( (</>) )
16+import System.Directory ( findExecutable )
1517import System.Exit
1618
1719main :: IO ()
@@ -29,6 +31,7 @@ main = do
2931 , instHook = \pkgdescr ->
3032 (instHook simpleUserHooks) pkgdescr{ executables =
3133 [x | x <- executables pkgdescr, exeName x /= "make-pandoc-man-pages"] }
34+ , hookedPreProcessors = [ppBlobSuffixHandler]
3235 }
3336 exitWith ExitSuccess
3437
@@ -53,3 +56,16 @@ installManpages pkg lbi verbosity copy =
5356 installOrdinaryFiles verbosity (mandir (absoluteInstallDirs pkg lbi copy))
5457 (zip (repeat manDir) manpages)
5558
59+ppBlobSuffixHandler :: PPSuffixHandler
60+ppBlobSuffixHandler = ("hsb", \_ _ ->
61+ PreProcessor {
62+ platformIndependent = True,
63+ runPreProcessor = mkSimplePreProcessor $ \infile outfile verbosity ->
64+ do info verbosity $ "Preprocessing " ++ infile ++ " to " ++ outfile
65+ hsb2hsPath <- findExecutable "hsb2hs"
66+ case hsb2hsPath of
67+ Just p -> rawSystem p [infile, infile, outfile]
68+ Nothing -> error "hsb2hs is needed to build this program: cabal install hsb2hs"
69+ return ()
70+
71+ })
pandoc.cabal+2−5
@@ -246,9 +246,9 @@ Library
246246 build-depends:
247247 blaze-html >= 0.4.3.0 && < 0.5
248248 if flag(embed_data_files)
249− build-depends: file-embed >= 0.0.4.7 && < 0.1,
250− template-haskell >= 2.4 && < 2.9
251249 cpp-options: -DEMBED_DATA_FILES
250+ -- build-tools: hsb2hs
251+ other-modules: Text.Pandoc.Data
252252 if impl(ghc >= 7.0.1)
253253 Ghc-Options: -rtsopts -Wall -fno-warn-unused-do-bind
254254 else
@@ -314,9 +314,6 @@ Library
314314 Text.Pandoc.Slides,
315315 Paths_pandoc
316316
317− if flag(embed_data_files)
318− Other-Modules: Text.Pandoc.Data
319−
320317 Buildable: True
321318
322319Executable pandoc
src/Text/Pandoc/Data.hs → src/Text/Pandoc/Data.hsbrenamed+3−3
@@ -1,7 +1,7 @@
1−{-# LANGUAGE TemplateHaskell #-}
1+{-# LANGUAGE OverloadedStrings #-}
2+-- to be processed using hsb2hs
23module Text.Pandoc.Data (dataFiles) where
3−import Data.FileEmbed
44import qualified Data.ByteString as B
55
66dataFiles :: [(FilePath, B.ByteString)]
7−dataFiles = $(embedDir "data")
7+dataFiles = %blobs "data"