Skip to content

Commit

Permalink
Merge dev branch
Browse files Browse the repository at this point in the history
  • Loading branch information
arendsee committed Nov 4, 2024
2 parents 83c24f7 + 745f8df commit 20b7078
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ jobs:
run: |
sudo apt-get install -y python3
- name: Set up C++ environment
run: |
# clone the morloc C++ headers for shared type definitions
mkdir -p $HOME/.morloc/include
git clone https://github.com/morloclib/mlccpptypes $HOME/.morloc/include/mlccpptypes
- uses: r-lib/actions/setup-r@v2

- name: "Set up R caching"
Expand Down
Empty file added data/misc/mlccpptypes.hpp
Empty file.
45 changes: 39 additions & 6 deletions library/Morloc/CodeGenerator/SystemConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import Morloc.DataFiles (rSocketLib, pympack, msgpackSource, rmpack, cppmpack)
import qualified Morloc.Data.Text as MT
import qualified Data.Text.IO as TIO

import System.Process (callCommand, callProcess)
import System.Directory (doesFileExist, removeFile, doesDirectoryExist, createDirectory)
import System.Process (callCommand, callProcess, readCreateProcessWithExitCode, shell)
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 All @@ -50,6 +51,11 @@ configureAll verbose force config = do
createDirectoryWithDescription "morloc opt directory" optDir
createDirectoryWithDescription "morloc module directory" srcLibrary

say "Installing C++ extra types"
let mlccpptypesRepoUrl = "https://github.com/morloclib/mlccpptypes"
cmd = unwords ["git clone", mlccpptypesRepoUrl, includeDir </> "mlccpptypes"]
runCommand "installing mlccpptypes" cmd

say "Configuring R socket library"
let srcpath = configHome config </> "lib" </> "socketr.c"
objpath = configHome config </> "lib" </> "socketr.o"
Expand Down Expand Up @@ -92,11 +98,22 @@ configureAll verbose force config = do
(includeDir </> "mpackr.o")
where

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

say :: String -> IO ()
say message =
if verbose
then do
hPutStrLn stderr ("\ESC[32m" <> message <> "\ESC[0m")
hPutStrLn stderr (ok message)
else
return ()

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

Expand All @@ -105,11 +122,11 @@ configureAll verbose force config = do
exists <- doesDirectoryExist path
if exists
then when verbose $
say $ "Checking " ++ description ++ " ... using existing path " ++ path
putStrLn $ "Checking " ++ description ++ " ... using existing path " ++ path
else do
createDirectory path
createDirectoryIfMissing True path
when verbose $
say $ "Checking " ++ description ++ " ... missing, creating at " ++ path
putStrLn $ "Checking " ++ description ++ " ... missing, creating at " ++ path

compileCCodeIfNeeded :: MT.Text -> Path -> Path -> Path -> IO ()
compileCCodeIfNeeded codeText sourcePath libPath objPath = do
Expand All @@ -134,3 +151,19 @@ 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 20b7078

Please sign in to comment.