Skip to content

Commit

Permalink
Simplify morloc init
Browse files Browse the repository at this point in the history
It was crashing previously in my vanilla Ubuntu container.
readCreateProcessWithExitCode failed in this container, complaining the
hGetContents couldn't parse one of its inupts. hGetContents is used
inside the readCreateProcessWithExitCode function to read STDOUT and
STDERR. One of those, for reasons I cann't fathom, is receiving
non-textual data. When I run the command myself STDERR is empty and
STDOUT is plain old ASCII. Not sure what is wrong. But I can replace the
readCreateProcessWithExitCode function with a simple callCommand
function. This does not intercept errors and doesn't allow me to make
pretty colors for failing cases, but at least it passes in the
container.
  • Loading branch information
arendsee committed Jan 4, 2025
1 parent 492f856 commit 635334e
Showing 1 changed file with 6 additions and 30 deletions.
36 changes: 6 additions & 30 deletions library/Morloc/CodeGenerator/SystemConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ import qualified Morloc.DataFiles as Files
import qualified Morloc.Data.Text as MT
import qualified Data.Text.IO as TIO

import System.Process (callCommand, callProcess, readCreateProcessWithExitCode, shell)
import System.Process (callCommand, callProcess)
import System.Directory (doesFileExist, removeFile, doesDirectoryExist, createDirectoryIfMissing)
import System.IO (withFile, IOMode(WriteMode), hPutStrLn, stderr)

import System.Exit (ExitCode(..), exitWith)

configure :: [AnnoS (Indexed Type) One (Indexed Lang)] -> MorlocMonad ()
configure _ = return ()

Expand Down Expand Up @@ -57,7 +55,9 @@ configureAll verbose force config = do
unless mlccpptypesExists $ do
let mlccpptypesRepoUrl = "https://github.com/morloclib/mlccpptypes"
cmd = unwords ["git clone", mlccpptypesRepoUrl, mlccpptypesPath]
runCommand "installing mlccpptypes" cmd

say "installing mlccpptypes"
callCommand cmd

say "Configuring R socket library"
let srcpath = configHome config </> "lib" </> "socketr.c"
Expand Down Expand Up @@ -94,7 +94,8 @@ configureAll verbose force config = do
TIO.writeFile libpySetupPath libpySetupCode
TIO.writeFile libpyMakePath libpyMakefileCode

runCommand "Generating libpymorloc.so" ("make -C " <> optDir <> " -f " <> libpyMakePath)
say "Generating libpymorloc.so"
callCommand ("make -C " <> optDir <> " -f " <> libpyMakePath)


say "Configuring R morloc API libraries"
Expand All @@ -106,7 +107,6 @@ configureAll verbose force config = do
where

ok msg = "\ESC[32m" <> msg <> "\ESC[0m"
bad msg = "\ESC[31m" <> msg <> "\ESC[0m"

say :: String -> IO ()
say message =
Expand All @@ -116,14 +116,6 @@ configureAll verbose force config = do
else
return ()

warn :: String -> IO ()
warn message =
if verbose
then do
hPutStrLn stderr (bad message)
else
return ()

createDirectoryWithDescription :: String -> FilePath -> IO ()
createDirectoryWithDescription description path = do
exists <- doesDirectoryExist path
Expand Down Expand Up @@ -158,19 +150,3 @@ configureAll verbose force config = do
-- Delete the source .o file
objPathExists <- doesFileExist objPath
when (objPathExists) (removeFile objPath)

runCommand ::
String -- description of action
-> String -- system command
-> IO ()
runCommand runMsg cmd = do
say runMsg
putStrLn $ cmd
(exitCode, _, err') <-
readCreateProcessWithExitCode (shell cmd) []
case exitCode of
ExitSuccess -> return ()
ExitFailure code -> do
warn " command failed - exiting"
putStrLn err'
exitWith (ExitFailure code)

0 comments on commit 635334e

Please sign in to comment.