From b551da522ac590d1d3b81f1183cf7f3d1f8c48ad Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Mon, 30 Mar 2020 14:50:00 -0500 Subject: Read some additional options from the fpm.toml file --- app/Main.hs | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'app') diff --git a/app/Main.hs b/app/Main.hs index 3ad22d1..a6f3ea2 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -32,7 +32,13 @@ import qualified Toml newtype Arguments = Arguments { command' :: Command } -data Settings = Settings { compiler :: !Text } +data Settings = Settings { + settingsCompiler :: !Text + , settingsProjectName :: !Text + , settingsDebugOptions :: ![Text] + , settingsLibrary :: !Library } + +data Library = Library { librarySourceDir :: !Text } data Command = Run | Test | Build @@ -43,7 +49,8 @@ main = do let settings = Toml.decode settingsCodec fpmContents case settings of Left err -> print err - Right settings -> app args settings + Right settings -> do + app args settings app :: Arguments -> Settings -> IO () app args settings = case command' args of @@ -54,20 +61,25 @@ app args settings = case command' args of build :: Settings -> IO () build settings = do putStrLn "Building" - buildLibrary "src" + let compiler = unpack $ settingsCompiler settings + let projectName = unpack $ settingsProjectName settings + let flags = map unpack $ settingsDebugOptions settings + let librarySettings = settingsLibrary settings + let librarySourceDir' = unpack $ librarySourceDir librarySettings + buildLibrary librarySourceDir' [".f90", ".f", ".F", ".F90", ".f95", ".f03"] ("build" "library") - (unpack $ compiler settings) - ["-g", "-Wall", "-Wextra", "-Werror", "-pedantic"] - "library" + compiler + flags + projectName [] buildProgram "app" ["build" "library"] [".f90", ".f", ".F", ".F90", ".f95", ".f03"] ("build" "app") - (unpack $ compiler settings) - ["-g", "-Wall", "-Wextra", "-Werror", "-pedantic"] - "example_project" + compiler + flags + projectName "main.f90" getArguments :: IO Arguments @@ -102,4 +114,16 @@ getDirectoriesFiles dirs exts = getDirectoryFilesIO "" newPatterns appendExts dir = map ((dir "*") ++) exts settingsCodec :: TomlCodec Settings -settingsCodec = Settings <$> Toml.text "compiler" .= compiler +settingsCodec = + Settings + <$> Toml.text "compiler" + .= settingsCompiler + <*> Toml.text "name" + .= settingsProjectName + <*> Toml.arrayOf Toml._Text "debug-options" + .= settingsDebugOptions + <*> Toml.table libraryCodec "library" + .= settingsLibrary + +libraryCodec :: TomlCodec Library +libraryCodec = Library <$> Toml.text "source-dir" .= librarySourceDir -- cgit v1.2.3