Skip to content

Commit

Permalink
[ #5742 ] One can now specify what encoding callCompiler should use.
Browse files Browse the repository at this point in the history
  • Loading branch information
nad authored and andreasabel committed Mar 14, 2022
1 parent 4f015eb commit 67942d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/full/Agda/Compiler/CallCompiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ callCompiler
-- ^ The path to the compiler
-> [String]
-- ^ Command-line arguments.
-> Maybe TextEncoding
-- ^ Use the given text encoding, if any, when reading the output
-- from the process (stdout and stderr).
-> TCM ()
callCompiler doCall cmd args =
callCompiler doCall cmd args enc =
if doCall then do
merrors <- callCompiler' cmd args
merrors <- callCompiler' cmd args enc
case merrors of
Nothing -> return ()
Just errors -> typeError (CompilationError errors)
Expand All @@ -49,8 +52,11 @@ callCompiler'
-- ^ The path to the compiler
-> [String]
-- ^ Command-line arguments.
-> Maybe TextEncoding
-- ^ Use the given text encoding, if any, when reading the output
-- from the process (stdout and stderr).
-> TCM (Maybe String)
callCompiler' cmd args = do
callCompiler' cmd args enc = do
reportSLn "compile.cmd" 1 $ "Calling: " ++ unwords (cmd : args)
(_, out, err, p) <-
liftIO $ createProcess
Expand All @@ -65,6 +71,9 @@ callCompiler' cmd args = do
Just out -> forkTCM $ do
-- The handle should be in text mode.
liftIO $ hSetBinaryMode out False
case enc of
Nothing -> return ()
Just enc -> liftIO $ hSetEncoding out enc
progressInfo <- liftIO $ hGetContents out
mapM_ (reportSLn "compile.output" 1) $ lines progressInfo

Expand All @@ -73,6 +82,9 @@ callCompiler' cmd args = do
Just err -> do
-- The handle should be in text mode.
hSetBinaryMode err False
case enc of
Nothing -> return ()
Just enc -> liftIO $ hSetEncoding err enc
hGetContents err

exitcode <- liftIO $ do
Expand Down
2 changes: 1 addition & 1 deletion src/full/Agda/Compiler/MAlonzo/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,4 +1292,4 @@ callGHC = do
-- those versions of GHC we don't print any progress information
-- unless an error is encountered.
let doCall = optGhcCallGhc opts
liftTCM $ callCompiler doCall ghcBin args
liftTCM $ callCompiler doCall ghcBin args Nothing

0 comments on commit 67942d4

Please sign in to comment.