diff options
| author | John MacFarlane <[email protected]> | 2022-09-26 09:25:54 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2022-09-26 09:25:54 -0700 |
| commit | 13ee8b82dad599a76fd384a7d2d278b56587fefe (patch) | |
| tree | 33c57425d6700d8bcb50e5282ef72811623fa31f | |
| parent | 06a2bd3e98e16fe456f57eb660819a1303650ab0 (diff) | |
Add server flag to pandoc-cli.
This allows the executable to be built without support for
"server mode."
| -rw-r--r-- | INSTALL.md | 9 | ||||
| -rw-r--r-- | pandoc-cli/pandoc-cli.cabal | 19 | ||||
| -rw-r--r-- | pandoc-cli/src/pandoc.hs | 34 |
3 files changed, 44 insertions, 18 deletions
diff --git a/INSTALL.md b/INSTALL.md index 88687f034..d52afaf2a 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -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: diff --git a/pandoc-cli/pandoc-cli.cabal b/pandoc-cli/pandoc-cli.cabal index ab4484946..5e0cf4fed 100644 --- a/pandoc-cli/pandoc-cli.cabal +++ b/pandoc-cli/pandoc-cli.cabal @@ -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 diff --git a/pandoc-cli/src/pandoc.hs b/pandoc-cli/src/pandoc.hs index bcbc0ba46..9e9fd4b76 100644 --- a/pandoc-cli/src/pandoc.hs +++ b/pandoc-cli/src/pandoc.hs @@ -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 |
