aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorBrad Richardson <everythingfunctional@protonmail.com>2020-04-12 21:57:26 -0500
committerGitHub <noreply@github.com>2020-04-12 21:57:26 -0500
commite8c5eb593fafdced419ade6312c17e04ff0328f9 (patch)
tree552fa86f1a33cc94dc6dbdb4f2e94b2cca5d16bc /app
parent3a5e426e3103dae2f71732e2a830bd38ffe2c96b (diff)
parent69a430f65069596e88f121c62d3161a8b4856bad (diff)
downloadfpm-e8c5eb593fafdced419ade6312c17e04ff0328f9.tar.gz
fpm-e8c5eb593fafdced419ade6312c17e04ff0328f9.zip
Merge pull request #53 from everythingfunctional/finishCommands
Finish commands
Diffstat (limited to 'app')
-rw-r--r--app/Main.hs63
1 files changed, 60 insertions, 3 deletions
diff --git a/app/Main.hs b/app/Main.hs
index 9438eb2..b75d02f 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -28,6 +28,7 @@ import Options.Applicative ( Parser
import System.Directory ( doesDirectoryExist
, doesFileExist
)
+import System.Process ( runCommand )
import Toml ( TomlCodec
, (.=)
)
@@ -40,6 +41,7 @@ data TomlSettings = TomlSettings {
, tomlSettingsProjectName :: String
, tomlSettingsLibrary :: (Maybe Library)
, tomlSettingsExecutables :: [Executable]
+ , tomlSettingsTests :: [Executable]
}
data AppSettings = AppSettings {
@@ -49,6 +51,7 @@ data AppSettings = AppSettings {
, appSettingsFlags :: [String]
, appSettingsLibrary :: (Maybe Library)
, appSettingsExecutables :: [Executable]
+ , appSettingsTests :: [Executable]
}
data Library = Library { librarySourceDir :: String }
@@ -74,18 +77,38 @@ main = do
app :: Arguments -> AppSettings -> IO ()
app args settings = case command' args of
- Run -> putStrLn "Run"
- Test -> putStrLn "Test"
Build -> build settings
+ Run -> do
+ build settings
+ let buildPrefix = appSettingsBuildPrefix settings
+ let
+ executableNames = map
+ (\Executable { executableSourceDir = sourceDir, executableMainFile = mainFile, executableName = name } ->
+ sourceDir </> name
+ )
+ (appSettingsExecutables settings)
+ let executables = map (buildPrefix </>) executableNames
+ mapM_ runCommand executables
+ Test -> do
+ build settings
+ let buildPrefix = appSettingsBuildPrefix settings
+ let
+ executableNames = map
+ (\Executable { executableSourceDir = sourceDir, executableMainFile = mainFile, executableName = name } ->
+ sourceDir </> name
+ )
+ (appSettingsTests settings)
+ let executables = map (buildPrefix </>) executableNames
+ mapM_ runCommand executables
build :: AppSettings -> IO ()
build settings = do
- putStrLn "Building"
let compiler = appSettingsCompiler settings
let projectName = appSettingsProjectName settings
let buildPrefix = appSettingsBuildPrefix settings
let flags = appSettingsFlags settings
let executables = appSettingsExecutables settings
+ let tests = appSettingsTests settings
executableDepends <- case appSettingsLibrary settings of
Just librarySettings -> do
let librarySourceDir' = librarySourceDir librarySettings
@@ -112,6 +135,19 @@ build settings = do
mainFile
)
executables
+ mapM_
+ (\Executable { executableSourceDir = sourceDir, executableMainFile = mainFile, executableName = name } ->
+ do
+ buildProgram sourceDir
+ executableDepends
+ [".f90", ".f", ".F", ".F90", ".f95", ".f03"]
+ (buildPrefix </> sourceDir)
+ compiler
+ flags
+ name
+ mainFile
+ )
+ tests
getArguments :: IO Arguments
getArguments = execParser
@@ -159,6 +195,8 @@ settingsCodec =
.= tomlSettingsLibrary
<*> Toml.list executableCodec "executable"
.= tomlSettingsExecutables
+ <*> Toml.list executableCodec "test"
+ .= tomlSettingsTests
libraryCodec :: TomlCodec Library
libraryCodec = Library <$> Toml.string "source-dir" .= librarySourceDir
@@ -180,6 +218,7 @@ toml2AppSettings tomlSettings release = do
executableSettings <- getExecutableSettings
(tomlSettingsExecutables tomlSettings)
projectName
+ testSettings <- getTestSettings $ tomlSettingsTests tomlSettings
return AppSettings
{ appSettingsCompiler = tomlSettingsCompiler tomlSettings
, appSettingsProjectName = projectName
@@ -212,6 +251,7 @@ toml2AppSettings tomlSettings release = do
]
, appSettingsLibrary = librarySettings
, appSettingsExecutables = executableSettings
+ , appSettingsTests = testSettings
}
getLibrarySettings :: Maybe Library -> IO (Maybe Library)
@@ -239,3 +279,20 @@ getExecutableSettings [] projectName = do
else return []
else return []
getExecutableSettings executables _ = return executables
+
+getTestSettings :: [Executable] -> IO [Executable]
+getTestSettings [] = do
+ defaultDirectoryExists <- doesDirectoryExist "test"
+ if defaultDirectoryExists
+ then do
+ defaultMainExists <- doesFileExist ("test" </> "main.f90")
+ if defaultMainExists
+ then return
+ [ Executable { executableSourceDir = "test"
+ , executableMainFile = "main.f90"
+ , executableName = "runTests"
+ }
+ ]
+ else return []
+ else return []
+getTestSettings tests = return tests