Use file-embed instead of hsb2hs to embed data files.
I think template haskell is robust enough now across platforms that this will work. Motivation: file-embed gives us better dependency tracking: if a data file changes, ghc/stack/cabal know to recompile the Data module. This also removes hsb2hs as a build dependency.
This commit is contained in:
parent
604c824d38
commit
10d91c1479
6 changed files with 8 additions and 38 deletions
|
@ -226,9 +226,6 @@ assume that the pandoc source directory is your working directory.
|
|||
|
||||
- `embed_data_files`: embed all data files into the binary (default no).
|
||||
This is helpful if you want to create a relocatable binary.
|
||||
Note: if this option is selected, you need to install the
|
||||
`hsb2hs` preprocessor: `cabal install hsb2hs` (version 0.3.1 or
|
||||
higher is required).
|
||||
|
||||
- `https`: enable support for downloading resources over https
|
||||
(using the `http-client` and `http-client-tls` libraries).
|
||||
|
|
28
Setup.hs
28
Setup.hs
|
@ -20,41 +20,17 @@ import Distribution.Simple
|
|||
import Distribution.Simple.PreProcess
|
||||
import Distribution.Simple.Setup (ConfigFlags(..), CopyFlags(..), fromFlag)
|
||||
import Distribution.PackageDescription (PackageDescription(..), FlagName(..))
|
||||
import Distribution.Simple.Utils ( rawSystemExitCode, findProgramVersion )
|
||||
import System.Exit
|
||||
import Distribution.Simple.Utils (info, notice, installOrdinaryFiles)
|
||||
import Distribution.Simple.Utils (notice, installOrdinaryFiles)
|
||||
import Distribution.Simple.Program (simpleProgram, Program(..))
|
||||
import Distribution.Simple.LocalBuildInfo
|
||||
import Control.Monad (when)
|
||||
|
||||
main :: IO ()
|
||||
main = defaultMainWithHooks $ simpleUserHooks {
|
||||
-- enable hsb2hs preprocessor for .hsb files
|
||||
hookedPreProcessors = [ppBlobSuffixHandler]
|
||||
, hookedPrograms = [(simpleProgram "hsb2hs"){
|
||||
programFindVersion = \verbosity fp ->
|
||||
findProgramVersion "--version" id verbosity fp }]
|
||||
, postCopy = installManPage
|
||||
postCopy = installManPage
|
||||
}
|
||||
|
||||
ppBlobSuffixHandler :: PPSuffixHandler
|
||||
ppBlobSuffixHandler = ("hsb", \_ lbi ->
|
||||
PreProcessor {
|
||||
platformIndependent = True,
|
||||
runPreProcessor = mkSimplePreProcessor $ \infile outfile verbosity ->
|
||||
do let embedData = case lookup (FlagName "embed_data_files")
|
||||
(configConfigurationsFlags (configFlags lbi)) of
|
||||
Just True -> True
|
||||
_ -> False
|
||||
when embedData $
|
||||
do info verbosity $ "Preprocessing " ++ infile ++ " to " ++ outfile
|
||||
ec <- rawSystemExitCode verbosity "hsb2hs"
|
||||
[infile, infile, outfile]
|
||||
case ec of
|
||||
ExitSuccess -> return ()
|
||||
ExitFailure _ -> error "hsb2hs is needed to build this program"
|
||||
})
|
||||
|
||||
installManPage :: Args -> CopyFlags
|
||||
-> PackageDescription -> LocalBuildInfo -> IO ()
|
||||
installManPage _ flags pkg lbi = do
|
||||
|
|
|
@ -14,7 +14,6 @@ RUN mkdir -p /usr/src/
|
|||
WORKDIR /usr/src/
|
||||
RUN git clone https://github.com/jgm/pandoc
|
||||
WORKDIR /usr/src/pandoc
|
||||
RUN stack install --local-bin-path /usr/bin hsb2hs
|
||||
RUN stack install --stack-yaml stack.pkg.yaml --only-dependencies \
|
||||
--flag 'pandoc:embed_data_files' \
|
||||
--test --ghc-options '-O2 -optc-Os -optl-static -fPIC' \
|
||||
|
|
|
@ -14,8 +14,6 @@ PACKAGEMAKER=/Applications/PackageMaker.app/Contents/MacOS/PackageMaker
|
|||
DEVELOPER_ID_APPLICATION=${DEVELOPER_ID_APPLICATION:-Developer ID Application: John Macfarlane}
|
||||
DEVELOPER_ID_INSTALLER=${DEVELOPER_ID_INSTALLER:-Developer ID Installer: John Macfarlane}
|
||||
|
||||
# We need this for hsb2hs:
|
||||
PATH=$LOCALBIN:$PATH
|
||||
export MACMACOS_DEPLOYMENT_TARGET=10.7
|
||||
|
||||
# echo Removing old files...
|
||||
|
@ -23,7 +21,6 @@ rm -rf $DIST
|
|||
mkdir -p $DIST
|
||||
mkdir -p $RESOURCES
|
||||
stack setup
|
||||
which hsb2hs || stack install hsb2hs
|
||||
which cpphs || stack install cpphs
|
||||
|
||||
echo Building pandoc...
|
||||
|
|
|
@ -332,7 +332,7 @@ Library
|
|||
cpp-options: -DHTTP_CLIENT
|
||||
if flag(embed_data_files)
|
||||
cpp-options: -DEMBED_DATA_FILES
|
||||
Build-Tools: hsb2hs >= 0.3.1
|
||||
build-depends: file-embed >= 0.0 && < 0.1
|
||||
other-modules: Text.Pandoc.Data
|
||||
if os(darwin)
|
||||
Build-Tools: cpphs >= 1.19
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
-- to be processed using hsb2hs
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
|
||||
module Text.Pandoc.Data (dataFiles) where
|
||||
|
||||
import Data.FileEmbed
|
||||
import qualified Data.ByteString as B
|
||||
import System.FilePath (splitDirectories)
|
||||
import qualified System.FilePath.Posix as Posix
|
||||
|
@ -12,5 +14,4 @@ dataFiles = map (\(fp, contents) ->
|
|||
(Posix.joinPath (splitDirectories fp), contents)) dataFiles'
|
||||
|
||||
dataFiles' :: [(FilePath, B.ByteString)]
|
||||
dataFiles' = ("MANUAL.txt", %blob "MANUAL.txt") : %blobs "data"
|
||||
|
||||
dataFiles' = ("MANUAL.txt", $(embedFile "MANUAL.txt")) : $(embedDir "data")
|
Loading…
Reference in a new issue