Add server flag to pandoc-cli.

This allows the executable to be built without support for
"server mode."
This commit is contained in:
John MacFarlane
2022-09-26 09:25:54 -07:00
parent 06a2bd3e98
commit 13ee8b82da
3 changed files with 44 additions and 18 deletions
+3 -6
View File
@@ -215,8 +215,6 @@ The easiest way to build pandoc from source is to use [stack][stack]:
`pandoc` executable into `~/.local/bin`, which you should
add to your `PATH`. This process will take a while, and
will consume a considerable amount of disk space.
If you also want the `pandoc-server` executable, add
`--flag pandoc:server` to the above command.
### Quick cabal method
@@ -238,9 +236,6 @@ The easiest way to build pandoc from source is to use [stack][stack]:
on linux/unix/macOS and in `%APPDATA%\cabal\bin` on Windows.
Make sure this directory is in your path.
If you also want the `pandoc-server` executable, add
`-fserver` to the above command.
If you want to install a modified or development version
of pandoc instead, switch to the source directory and do
as above, but without the 'pandoc':
@@ -292,7 +287,9 @@ You will need cabal version 2.0 or higher.
- `lua53`: embed support for Lua 5.3 instead of 5.4.
- `server`: build the `pandoc-server` executable.
- `server`: compile in support for running in HTTP server
mode when the executable is renamed (or symlinked as)
`pandoc-server`.
3. Build:
+12 -7
View File
@@ -21,6 +21,10 @@ source-repository head
type: git
location: git://github.com/jgm/pandoc.git
flag server
Description: Include support for running pandoc as an HTTP server.
Default: True
common common-options
default-language: Haskell2010
build-depends: base >= 4.12 && < 5
@@ -33,7 +37,6 @@ common common-options
-Wpartial-fields
-Wmissing-signatures
-fhide-source-paths
-- -Wmissing-export-lists
if impl(ghc >= 8.10)
ghc-options: -Wunused-packages
@@ -54,9 +57,11 @@ executable pandoc
hs-source-dirs: src
main-is: pandoc.hs
buildable: True
build-depends: pandoc == 2.19.2,
pandoc-server >= 0.1 && < 0.2,
hslua-cli >= 1.0 && < 1.1,
wai-extra >= 3.0.24,
warp,
safe
build-depends: pandoc,
hslua-cli >= 1.0 && < 1.1
if flag(server)
build-depends: pandoc-server >= 0.1 && < 0.2,
wai-extra >= 3.0.24,
warp,
safe
cpp-options: -D_SERVER
+29 -5
View File
@@ -1,4 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE CPP #-}
{- |
Module : Main
Copyright : Copyright (C) 2006-2022 John MacFarlane
@@ -19,23 +20,38 @@ import Text.Pandoc.App (convertWithOpts, defaultOpts, options, parseOptions)
import Text.Pandoc.Class (runIOorExplode)
import Text.Pandoc.Error (handleError)
import Text.Pandoc.Lua (runLua)
import Text.Pandoc.Server (ServerOpts(..), parseServerOpts, app)
import Text.Pandoc.Shared (pandocVersion)
import Safe (readDef)
import System.Environment (getProgName, lookupEnv)
import System.Environment (getProgName)
#ifdef _SERVER
import qualified Network.Wai.Handler.CGI as CGI
import qualified Network.Wai.Handler.Warp as Warp
import Network.Wai.Middleware.Timeout (timeout)
import Text.Pandoc.Server (ServerOpts(..), parseServerOpts, app)
import Safe (readDef)
import System.Environment (lookupEnv)
#else
import System.IO (hPutStrLn, stderr)
import System.Exit (exitWith, ExitCode(ExitFailure))
#endif
main :: IO ()
main = E.handle (handleError . Left) $ do
prg <- getProgName
cgiTimeout <- maybe 2 (readDef 2) <$> lookupEnv "PANDOC_SERVER_TIMEOUT"
case prg of
"pandoc-server.cgi" -> CGI.run (timeout cgiTimeout app)
"pandoc-server.cgi" -> do
#ifdef _SERVER
cgiTimeout <- maybe 2 (readDef 2) <$> lookupEnv "PANDOC_SERVER_TIMEOUT"
CGI.run (timeout cgiTimeout app)
#else
serverUnsupported
#endif
"pandoc-server" -> do
#ifdef _SERVER
sopts <- parseServerOpts
Warp.run (serverPort sopts) (timeout (serverTimeout sopts) app)
#else
serverUnsupported
#endif
"pandoc-lua" -> do
let settings = Settings
{ settingsVersionInfo = "\nEmbedded in pandoc " <> pandocVersion
@@ -43,3 +59,11 @@ main = E.handle (handleError . Left) $ do
}
runStandalone settings
_ -> parseOptions options defaultOpts >>= convertWithOpts
#ifndef _SERVER
serverUnsupported :: IO ()
serverUnsupported = do
hPutStrLn stderr $ "Server mode unsupported.\n" <>
"Pandoc was not compiled with the 'server' flag."
exitWith $ ExitFailure 4
#endif