on master help sign in
a unixFilter for non Posix (well windows)

Conflicts: src/Hakyll/Core/UnixFilter.hs

commitf0e474ceb9ee3d9f2e5355f88ad1c73187c68e88 authorRobin Windels <rwindelz@gmail.com> dateSat 12 Jan 2013, 21:14 (14 years ago) parent3ae0c08
3 files changed+10−42
hakyll.cabal+2−15 src/Hakyll.hs−4 src/Hakyll/Core/UnixFilter.hs+8−23
hakyll.cabal+2−15
@@ -75,10 +75,6 @@ Flag previewServer
7575 Description: Include the preview server
7676 Default: True
7777
78−Flag unixFilter
79− Description: Include the UnixFilter module
80− Default: True
81−
8278Library
8379 Ghc-Options: -Wall
8480 Ghc-Prof-Options: -auto-all -caf-all
@@ -125,6 +121,7 @@ Library
125121 Hakyll.Core.Metadata
126122 Hakyll.Core.Routes
127123 Hakyll.Core.Rules
124+ Hakyll.Core.UnixFilter
128125 Hakyll.Core.Util.String
129126 Hakyll.Core.Writable
130127 Hakyll.Main
@@ -170,14 +167,6 @@ Library
170167 Hakyll.Preview.Poll
171168 Hakyll.Preview.Server
172169
173− If flag(unixFilter)
174− Build-depends:
175− unix >= 2.4 && < 2.7
176− Cpp-options:
177− -DUNIX_FILTER
178− Exposed-modules:
179− Hakyll.Core.UnixFilter
180−
181170Test-suite hakyll-tests
182171 Type: exitcode-stdio-1.0
183172 Hs-source-dirs: src tests
@@ -217,9 +206,7 @@ Test-suite hakyll-tests
217206 regex-tdfa >= 1.1 && < 1.2,
218207 tagsoup >= 0.12.6 && < 0.13,
219208 text >= 0.11 && < 1.12,
220− time >= 1.1 && < 1.5,
221− -- Bonus copypasta
222− unix >= 2.4 && < 2.7
209+ time >= 1.1 && < 1.5
223210
224211 Other-modules:
225212 Hakyll.Core.Dependencies.Tests
src/Hakyll.hs−4
@@ -11,9 +11,7 @@ module Hakyll
1111 , module Hakyll.Core.Metadata
1212 , module Hakyll.Core.Routes
1313 , module Hakyll.Core.Rules
14−#ifdef UNIX_FILTER
1514 , module Hakyll.Core.UnixFilter
16−#endif
1715 , module Hakyll.Core.Util.File
1816 , module Hakyll.Core.Util.String
1917 , module Hakyll.Core.Writable
@@ -43,9 +41,7 @@ import Hakyll.Core.Item
4341import Hakyll.Core.Metadata
4442import Hakyll.Core.Routes
4543import Hakyll.Core.Rules
46−#ifdef UNIX_FILTER
4744import Hakyll.Core.UnixFilter
48−#endif
4945import Hakyll.Core.Util.File
5046import Hakyll.Core.Util.String
5147import Hakyll.Core.Writable
src/Hakyll/Core/UnixFilter.hs+8−23
@@ -12,9 +12,7 @@ import Data.ByteString.Lazy (ByteString)
1212import qualified Data.ByteString.Lazy as LB
1313import System.IO (Handle, hClose, hGetContents, hPutStr,
1414 hSetEncoding, localeEncoding)
15−import System.Posix.IO (closeFd, createPipe, dupTo, fdToHandle,
16− stdInput, stdOutput)
17−import System.Posix.Process (executeFile, forkProcess)
15+import System.Process
1816
1917
2018--------------------------------------------------------------------------------
@@ -89,32 +87,19 @@ unixFilterIO :: (Handle -> i -> IO ())
8987 -> i
9088 -> IO o
9189unixFilterIO writer reader programName args input = do
92− -- Create pipes
93− (stdinRead, stdinWrite) <- createPipe
94− (stdoutRead, stdoutWrite) <- createPipe
90+ let process = (proc programName args)
91+ { std_in = CreatePipe
92+ , std_out = CreatePipe
93+ , close_fds = True
94+ }
9595
96− -- Fork the child
97− _ <- forkProcess $ do
98− -- Copy our pipes over the regular stdin/stdout
99− _ <- dupTo stdinRead stdInput
100− _ <- dupTo stdoutWrite stdOutput
101−
102− -- Close the now unneeded file descriptors in the child
103− mapM_ closeFd [stdinWrite, stdoutRead, stdinRead, stdoutWrite]
104−
105− -- Execute the program
106− _ <- executeFile programName True args Nothing
107− return ()
108−
109− -- On the parent side, close the client-side FDs.
110− mapM_ closeFd [stdinRead, stdoutWrite]
96+ (Just stdinWriteHandle, Just stdoutReadHandle, _, _) <-
97+ createProcess process
11198
11299 -- Write the input to the child pipe
113100 _ <- forkIO $ do
114− stdinWriteHandle <- fdToHandle stdinWrite
115101 writer stdinWriteHandle input
116102 hClose stdinWriteHandle
117103
118104 -- Receive the output from the child
119− stdoutReadHandle <- fdToHandle stdoutRead
120105 reader stdoutReadHandle