From 43b28f9559cb4cb3affb1bee7063bf27399c7b31 Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Tue, 31 Mar 2020 15:12:50 -0500 Subject: Add default for library settings --- app/Main.hs | 13 ++++++++++++- example_project/fpm.toml | 3 --- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 974c7a6..8d07c40 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -25,6 +25,7 @@ import Options.Applicative ( Parser , progDesc , subparser ) +import System.Directory ( doesDirectoryExist ) import Toml ( TomlCodec , (.=) ) @@ -147,9 +148,19 @@ libraryCodec = Library <$> Toml.text "source-dir" .= librarySourceDir toml2AppSettings :: TomlSettings -> IO AppSettings toml2AppSettings tomlSettings = do + librarySettings <- getLibrarySettings $ tomlSettingsLibrary tomlSettings return AppSettings { appSettingsCompiler = tomlSettingsCompiler tomlSettings , appSettingsProjectName = tomlSettingsProjectName tomlSettings , appSettingsDebugOptions = tomlSettingsDebugOptions tomlSettings - , appSettingsLibrary = tomlSettingsLibrary tomlSettings + , appSettingsLibrary = librarySettings } + +getLibrarySettings :: Maybe Library -> IO (Maybe Library) +getLibrarySettings maybeSettings = case maybeSettings of + Just settings -> return maybeSettings + Nothing -> do + defaultExists <- doesDirectoryExist "src" + if defaultExists + then return (Just (Library { librarySourceDir = "src" })) + else return Nothing diff --git a/example_project/fpm.toml b/example_project/fpm.toml index a8bded7..fae3512 100644 --- a/example_project/fpm.toml +++ b/example_project/fpm.toml @@ -9,9 +9,6 @@ compiler = "gfortran" debug-options = ["-g", "-Wall", "-Wextra", "-Werror", "-pedantic"] release-options = ["-O3"] -[library] - source-dir = "src" - [executables.example_project] main = "main.f90" source-dir = "app" -- cgit v1.2.3