From fde13b66701956a53282f558d79a8ddbfca0c905 Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Sat, 11 Apr 2020 15:26:40 -0500 Subject: Enable default settings for executables --- app/Main.hs | 29 +++++++++++++++++++++++------ example_project/fpm.toml | 6 ------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index b951ad8..66dedb8 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -28,7 +28,9 @@ import Options.Applicative ( Parser , subparser , switch ) -import System.Directory ( doesDirectoryExist ) +import System.Directory ( doesDirectoryExist + , doesFileExist + ) import Toml ( TomlCodec , (.=) ) @@ -177,12 +179,14 @@ executableCodec = toml2AppSettings :: TomlSettings -> Bool -> IO AppSettings toml2AppSettings tomlSettings release = do + let projectName = tomlSettingsProjectName tomlSettings librarySettings <- getLibrarySettings $ tomlSettingsLibrary tomlSettings executableSettings <- getExecutableSettings - $ tomlSettingsExecutables tomlSettings + (tomlSettingsExecutables tomlSettings) + projectName return AppSettings { appSettingsCompiler = tomlSettingsCompiler tomlSettings - , appSettingsProjectName = tomlSettingsProjectName tomlSettings + , appSettingsProjectName = projectName , appSettingsFlags = if release then [ "-Wall" @@ -221,6 +225,19 @@ getLibrarySettings maybeSettings = case maybeSettings of then return (Just (Library { librarySourceDir = "src" })) else return Nothing -getExecutableSettings :: [Executable] -> IO [Executable] -getExecutableSettings [] = undefined -getExecutableSettings executables = return executables +getExecutableSettings :: [Executable] -> Text -> IO [Executable] +getExecutableSettings [] projectName = do + defaultDirectoryExists <- doesDirectoryExist "app" + if defaultDirectoryExists + then do + defaultMainExists <- doesFileExist ("app" "main.f90") + if defaultMainExists + then return + [ Executable { executableSourceDir = "app" + , executableMainFile = "main.f90" + , executableName = projectName + } + ] + else return [] + else return [] +getExecutableSettings executables _ = return executables diff --git a/example_project/fpm.toml b/example_project/fpm.toml index f6c6e1d..38cc3b7 100644 --- a/example_project/fpm.toml +++ b/example_project/fpm.toml @@ -6,9 +6,3 @@ maintainer = "example@example.com" copyright = "2020 Author" dependencies = [] compiler = "gfortran" - -[[executable]] -name = "example_project" -source-dir = "app" -main = "main.f90" -dependencies = [] -- cgit v1.2.3