Skip to content

Commit

Permalink
[#484] Generated source files improvements (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
vrom911 authored Jul 28, 2020
1 parent 915ad37 commit 06f47a7
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 78 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ The changelog is available [on GitHub][2].
Add README link in the `.cabal` file's description field.
* [#453](https://github.com/kowainik/summoner/issues/453):
Drop support of `GHC-7.10` in the generated projects.
* [#484](https://github.com/kowainik/summoner/issues/484):
Improve generated files content.

## 2.0.1.1 — May 29, 2020

Expand Down
4 changes: 2 additions & 2 deletions summoner-cli/examples/cabal-full/app/Main.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Main (main) where

import CabalFull (someFunc)
import CabalFull (projectName)


main :: IO ()
main = someFunc
main = putStrLn ("Executable for " ++ projectName)
4 changes: 2 additions & 2 deletions summoner-cli/examples/cabal-full/benchmark/Main.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Main (main) where

import Gauge.Main
import CabalFull (projectName)


main :: IO ()
main = defaultMain [bench "const" (whnf const ())]
main = putStrLn ("Benchmarks for " ++ projectName)
3 changes: 1 addition & 2 deletions summoner-cli/examples/cabal-full/cabal-full.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ benchmark cabal-full-benchmark
type: exitcode-stdio-1.0
hs-source-dirs: benchmark
main-is: Main.hs
build-depends: gauge
, cabal-full
build-depends: cabal-full
ghc-options: -threaded
-rtsopts
-with-rtsopts=-N
8 changes: 4 additions & 4 deletions summoner-cli/examples/cabal-full/src/CabalFull.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Cabal-only example with all integrations
-}

module CabalFull
( someFunc
) where
( projectName
) where


someFunc :: IO ()
someFunc = putStrLn ("someFunc" :: String)
projectName :: String
projectName = "cabal-full"
4 changes: 3 additions & 1 deletion summoner-cli/examples/cabal-full/test/Spec.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Main (main) where

import CabalFull (projectName)


main :: IO ()
main = putStrLn ("Test suite is not implemented" :: String)
main = putStrLn ("Tests for " ++ projectName)
2 changes: 1 addition & 1 deletion summoner-cli/examples/cabal-minimal/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module Main (main) where


main :: IO ()
main = putStrLn ("Hello, world!" :: String)
main = putStrLn ("Executable not implemented" :: String)
4 changes: 2 additions & 2 deletions summoner-cli/examples/full-batteries/app/Main.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Main (main) where

import FullBatteries (someFunc)
import FullBatteries (projectName)


main :: IO ()
main = someFunc
main = putStrLn ("Executable for " ++ projectName)
4 changes: 2 additions & 2 deletions summoner-cli/examples/full-batteries/benchmark/Main.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Main (main) where

import Gauge.Main
import FullBatteries (projectName)


main :: IO ()
main = defaultMain [bench "const" (whnf const ())]
main = putStrLn ("Benchmarks for " ++ projectName)
3 changes: 1 addition & 2 deletions summoner-cli/examples/full-batteries/full-batteries.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ benchmark full-batteries-benchmark
type: exitcode-stdio-1.0
hs-source-dirs: benchmark
main-is: Main.hs
build-depends: gauge
, full-batteries
build-depends: full-batteries
ghc-options: -threaded
-rtsopts
-with-rtsopts=-N
8 changes: 4 additions & 4 deletions summoner-cli/examples/full-batteries/src/FullBatteries.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Full-featured test project
-}

module FullBatteries
( someFunc
) where
( projectName
) where


someFunc :: IO ()
someFunc = putStrLn ("someFunc" :: String)
projectName :: String
projectName = "full-batteries"
4 changes: 3 additions & 1 deletion summoner-cli/examples/full-batteries/test/Spec.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Main (main) where

import FullBatteries (projectName)


main :: IO ()
main = putStrLn ("Test suite is not implemented" :: String)
main = putStrLn ("Tests for " ++ projectName)
4 changes: 2 additions & 2 deletions summoner-cli/examples/stack-full/app/Main.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Main (main) where

import StackFull (someFunc)
import StackFull (projectName)


main :: IO ()
main = someFunc
main = putStrLn ("Executable for " ++ projectName)
4 changes: 2 additions & 2 deletions summoner-cli/examples/stack-full/benchmark/Main.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Main (main) where

import Gauge.Main
import StackFull (projectName)


main :: IO ()
main = defaultMain [bench "const" (whnf const ())]
main = putStrLn ("Benchmarks for " ++ projectName)
8 changes: 4 additions & 4 deletions summoner-cli/examples/stack-full/src/StackFull.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Stack-only example with all integrations
-}

module StackFull
( someFunc
) where
( projectName
) where


someFunc :: IO ()
someFunc = putStrLn ("someFunc" :: String)
projectName :: String
projectName = "stack-full"
3 changes: 1 addition & 2 deletions summoner-cli/examples/stack-full/stack-full.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ benchmark stack-full-benchmark
type: exitcode-stdio-1.0
hs-source-dirs: benchmark
main-is: Main.hs
build-depends: gauge
, stack-full
build-depends: stack-full
ghc-options: -threaded
-rtsopts
-with-rtsopts=-N
4 changes: 3 additions & 1 deletion summoner-cli/examples/stack-full/test/Spec.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Main (main) where

import StackFull (projectName)


main :: IO ()
main = putStrLn ("Test suite is not implemented" :: String)
main = putStrLn ("Tests for " ++ projectName)
9 changes: 4 additions & 5 deletions summoner-cli/src/Summoner/Template/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cabalFile Settings{..} = File (toString settingsRepo ++ ".cabal") cabalFileConte
, memptyIfFalse settingsIsLib libraryStanza
, memptyIfFalse settingsIsExe executableStanza
, memptyIfFalse settingsTest testSuiteStanza
, memptyIfFalse settingsBench $ benchmarkStanza $ memptyIfFalse settingsIsLib $ ", " <> settingsRepo
, memptyIfFalse settingsBench benchmarkStanza
]

cabalHeader :: Text
Expand Down Expand Up @@ -175,17 +175,16 @@ cabalFile Settings{..} = File (toString settingsRepo ++ ".cabal") cabalFileConte
<> buildDepends
<> rtsOptions

benchmarkStanza :: Text -> Text
benchmarkStanza commaRepo = unlines $
benchmarkStanza :: Text
benchmarkStanza = unlines $
[ ""
, "benchmark " <> settingsRepo <> "-benchmark"
, " import: common-options"
, " type: exitcode-stdio-1.0"
, " hs-source-dirs: benchmark"
, " main-is: Main.hs"
, " build-depends: gauge"
, " " <> commaRepo
]
<> buildDepends
<> rtsOptions

-- | @build-depends@ for the repo, only if the library is on.
Expand Down
63 changes: 24 additions & 39 deletions summoner-cli/src/Summoner/Template/Haskell.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ haskellFiles Settings{..} = concat
, settingsDescription
, "-}"
, ""
, "module " <>libModuleName
, " ( someFunc"
, " ) where"
, "module " <> libModuleName
, " ( projectName"
, " ) where"
, ""
, ""
, "someFunc :: IO ()"
, "someFunc = putStrLn (" <> quote "someFunc" <> " :: String)"
, "projectName :: String"
, "projectName = " <> quote settingsRepo
]

libModuleName :: Text
Expand All @@ -52,44 +52,29 @@ haskellFiles Settings{..} = concat
licenseName = show settingsLicenseName

exeFile :: TreeFs
exeFile = File "Main.hs" $ if settingsIsLib then createExe else createOnlyExe

createOnlyExe :: Text
createOnlyExe = unlines
[ "module Main (main) where"
, ""
, ""
, "main :: IO ()"
, "main = putStrLn (" <> quote "Hello, world!" <> " :: String)"
]

createExe :: Text
createExe = unlines
[ "module Main (main) where"
, ""
, "import " <> libModuleName <> " (someFunc)"
, ""
, ""
, "main :: IO ()"
, "main = someFunc"
]
exeFile = File "Main.hs" $ stanza "Executable"

testFile :: TreeFs
testFile = File "Spec.hs" $ unlines
[ "module Main (main) where"
, ""
, ""
, "main :: IO ()"
, "main = putStrLn (" <> quote "Test suite is not implemented" <> " :: String)"
]
testFile = File "Spec.hs" $ stanza "Tests"

benchmarkFile :: TreeFs
benchmarkFile = File "Main.hs" $ unlines
[ "module Main (main) where"
, ""
, "import Gauge.Main"
, ""
benchmarkFile = File "Main.hs" $ stanza "Benchmarks"

stanza :: Text -> Text
stanza st = unlines $
"module Main (main) where"
: memptyIfFalse settingsIsLib
[ ""
, "import " <> libModuleName <> " (projectName)"
]
<>
[ ""
, ""
, "main :: IO ()"
, "main = defaultMain [bench " <> quote "const" <> " (whnf const ())]"
, mainContent
]
where
mainContent :: Text
mainContent = if settingsIsLib
then "main = putStrLn (" <> quote (st <> " for ") <> " ++ projectName)"
else "main = putStrLn (" <> quote (st <> " not implemented") <> " :: String)"

0 comments on commit 06f47a7

Please sign in to comment.