diff --git a/.travis.yml b/.travis.yml index 5a343413..c9a2f3d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,8 +55,10 @@ script: echo "Testing that generated projects are built with cabal..." cd "$TRAVIS_BUILD_DIR/summoner-cli/test/golden/smallProject/" + echo "packages: ." > cabal.project cabal v2-build all cd "$TRAVIS_BUILD_DIR/summoner-cli/test/golden/fullProject/" + echo "packages: ." > cabal.project cabal v2-build all else stack test --system-ghc --no-terminal diff --git a/CHANGELOG.md b/CHANGELOG.md index 93c459c8..3af10b9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,20 @@ The changelog is available [on GitHub][2]. (by [@vrom911](https://github.com/vrom911)) * [#363](https://github.com/kowainik/summoner/issues/363): Move from `generic-deriving` to `generic-data`. + (by [@chshersh](https://github.com/chshersh)) +* [#361](https://github.com/kowainik/summoner/issues/361): + Always put all default warnings in `ghc-options` inside common + stanza under cabal conditionals on the `GHC` version. Now they look + like this: + + ```haskell + if impl(ghc >= 8.4) + ghc-options: -Wmissing-export-lists + -Wpartial-fields + if impl(ghc >= 8.8) + ghc-options: -Wmissing-deriving-strategies + ``` + (by [@chshersh](https://github.com/chshersh)) * Use `colourista` for pretty terminal formatting. (by [@chshersh](https://github.com/chshersh)) diff --git a/README.md b/README.md index 1f1d0f39..0acd77ad 100644 --- a/README.md +++ b/README.md @@ -100,15 +100,15 @@ Features related to the structure and content of the generated projects. ``` -Wall - -Wincomplete-uni-patterns - -Wincomplete-record-updates -Wcompat -Widentities - -Wredundant-constraints (GHC >= 8.0) - -fhide-source-paths (GHC >= 8.2.2) - -Wmissing-export-lists (GHC >= 8.4.1) - -Wpartial-fields (GHC >= 8.4.1) - -Wmissing-deriving-strategies (GHC >= 8.8.1) + -Wincomplete-uni-patterns + -Wincomplete-record-updates + -Wredundant-constraints (GHC ⩾ 8.0) + -fhide-source-paths (GHC ⩾ 8.2) + -Wmissing-export-lists (GHC ⩾ 8.4) + -Wpartial-fields (GHC ⩾ 8.4) + -Wmissing-deriving-strategies (GHC ⩾ 8.8) ``` Besides, the following GHC options are added to the executable, tests and benchmark stanzas: @@ -190,8 +190,8 @@ To start using Summoner make sure that you have the following tools installed on We also have minimal version requirements for build tools: -* [Cabal >= 2.4](https://www.haskell.org/cabal/) -* [Stack >= 2.1](http://haskellstack.org) +* [Cabal ⩾ 2.4](https://www.haskell.org/cabal/) +* [Stack ⩾ 2.1.3](http://haskellstack.org) However, it is always recommended to use the newest versions of build tools. diff --git a/summoner-cli/src/Summoner/License.hs b/summoner-cli/src/Summoner/License.hs index 0e54eb9e..d1612f15 100644 --- a/summoner-cli/src/Summoner/License.hs +++ b/summoner-cli/src/Summoner/License.hs @@ -10,7 +10,6 @@ to work with them. module Summoner.License ( LicenseName(..) , License(..) - , cabalLicense , customizeLicense , githubLicenseQueryNames , parseLicenseName @@ -41,7 +40,7 @@ data LicenseName | AGPL3 | Apache20 | MPL20 - | None + | NONE deriving stock (Eq, Ord, Enum, Bounded, Generic) instance Show LicenseName where @@ -55,7 +54,7 @@ instance Show LicenseName where show AGPL3 = "AGPL-3" show Apache20 = "Apache-2.0" show MPL20 = "MPL-2.0" - show None = "None" + show NONE = "NONE" newtype License = License { unLicense :: Text @@ -65,11 +64,6 @@ newtype License = License instance FromJSON License where parseJSON = withObject "License" $ \o -> License <$> o .: "body" --- | As it will be shown in the @cabal@ file. -cabalLicense :: LicenseName -> Text -cabalLicense None = "AllRightsReserved" -cabalLicense l = show l - -- | Used for downloading the license text form @Github@. githubLicenseQueryNames :: LicenseName -> Text githubLicenseQueryNames = \case @@ -83,7 +77,7 @@ githubLicenseQueryNames = \case AGPL3 -> "agpl-3.0" Apache20 -> "apache-2.0" MPL20 -> "mpl-2.0" - None -> "none" + NONE -> "none" parseLicenseName :: Text -> Maybe LicenseName parseLicenseName = inverseMap show @@ -103,7 +97,7 @@ customizeLicense l license@(License licenseText) nm year in beforeY <> year <> beforeN <> nm <> afterN fetchLicense :: LicenseName -> IO License -fetchLicense None = pure $ License $ licenseShortDesc None +fetchLicense NONE = pure $ License $ licenseShortDesc NONE fetchLicense name = do let licenseLink = "https://api.github.com/licenses/" <> githubLicenseQueryNames name licenseJson <- "curl" $| @@ -130,7 +124,7 @@ licenseShortDesc = \case AGPL3 -> "GNU Affero General Public License, version 3" Apache20 -> "Apache License, version 2.0" MPL20 -> "Mozilla Public License, version 2.0." - None -> "License file won't be added. Explicitly 'All Rights Reserved', eg \ + NONE -> "License file won't be added. Explicitly 'All Rights Reserved', eg \ \for proprietary software. The package may not be legally modified or \ \redistributed by anyone but the rightsholder" diff --git a/summoner-cli/src/Summoner/Project.hs b/summoner-cli/src/Summoner/Project.hs index 446939a3..9a3e206f 100644 --- a/summoner-cli/src/Summoner/Project.hs +++ b/summoner-cli/src/Summoner/Project.hs @@ -63,7 +63,7 @@ generateProject isOffline projectName Config{..} = do putText licenseText settingsLicenseName <- if isOffline - then None <$ infoMessage "'AllRightsReserved' license is used in offline mode" + then NONE <$ infoMessage "'NONE' license is used in offline mode" else choose parseLicenseName "License: " $ ordNub (cLicense : universe) -- License creation diff --git a/summoner-cli/src/Summoner/Template/Cabal.hs b/summoner-cli/src/Summoner/Template/Cabal.hs index 2bfac540..fefc6e66 100644 --- a/summoner-cli/src/Summoner/Template/Cabal.hs +++ b/summoner-cli/src/Summoner/Template/Cabal.hs @@ -16,8 +16,8 @@ import NeatInterpolation (text) import Summoner.CustomPrelude (CustomPrelude (..)) import Summoner.Default (defaultCabal) -import Summoner.GhcVer (GhcVer (..), cabalBaseVersions, showGhcVer) -import Summoner.License (LicenseName (..), cabalLicense) +import Summoner.GhcVer (cabalBaseVersions, showGhcVer) +import Summoner.License (LicenseName (..)) import Summoner.Settings (Settings (..)) import Summoner.Template.Mempty (memptyIfFalse) import Summoner.Text (endLine, intercalateMap, packageToModule) @@ -52,7 +52,7 @@ cabalFile Settings{..} = File (toString settingsRepo ++ ".cabal") cabalFileConte [ "homepage: " <> githubUrl | settingsGitHub ] ++ [ "bug-reports: " <> githubBugReports | settingsGitHub ] ++ ( "license: " <> licenseName) : - [ "license-file: LICENSE" | settingsLicenseName /= None] ++ + [ "license-file: LICENSE" | settingsLicenseName /= NONE] ++ [ "author: " <> settingsFullName , "maintainer: " <> settingsEmail , "copyright: " <> settingsYear <> " " <> settingsFullName ] ++ @@ -68,7 +68,7 @@ cabalFile Settings{..} = File (toString settingsRepo ++ ".cabal") cabalFileConte githubBugReports = githubUrl <> "/issues" licenseName, libModuleName :: Text - licenseName = cabalLicense settingsLicenseName + licenseName = show settingsLicenseName libModuleName = packageToModule settingsRepo testedGhcs :: Text @@ -86,7 +86,6 @@ cabalFile Settings{..} = File (toString settingsRepo ++ ".cabal") cabalFileConte location: ${githubUrl}.git |] - commonStanza :: Text commonStanza = [text| @@ -95,8 +94,7 @@ cabalFile Settings{..} = File (toString settingsRepo ++ ".cabal") cabalFileConte build-depends: $settingsBaseType $baseBounds $commaPreludeLibrary - ghc-options: -Wall - $ghcOptions + $ghcOptions default-language: Haskell2010 |] <> defaultExtensions @@ -104,6 +102,34 @@ cabalFile Settings{..} = File (toString settingsRepo ++ ".cabal") cabalFileConte baseBounds :: Text baseBounds = cabalBaseVersions settingsTestedVersions + ghcOptions :: Text + ghcOptions = case settingsGhcOptions of + [] -> defaultGhcOptions + x:xs -> + let customGhcOptions = T.intercalate "\n" $ x : map (T.replicate 21 " " <>) xs in + [text| + ghc-options: $customGhcOptions + |] + + defaultGhcOptions :: Text + defaultGhcOptions = + [text| + ghc-options: -Wall + -Wcompat + -Widentities + -Wincomplete-uni-patterns + -Wincomplete-record-updates + if impl(ghc >= 8.0) + ghc-options: -Wredundant-constraints + if impl(ghc >= 8.2) + ghc-options: -fhide-source-paths + if impl(ghc >= 8.4) + ghc-options: -Wmissing-export-lists + -Wpartial-fields + if impl(ghc >= 8.8) + ghc-options: -Wmissing-deriving-strategies + |] + libraryStanza :: Text libraryStanza = [text| @@ -180,35 +206,3 @@ cabalFile Settings{..} = File (toString settingsRepo ++ ".cabal") cabalFileConte xs -> " default-extensions: " <> T.intercalate "\n " xs <> "\n" - - ghcOptions :: Text - ghcOptions = case settingsGhcOptions of - [] -> defaultGhcOptions - xs -> T.intercalate "\n" xs - - defaultGhcOptions :: Text - defaultGhcOptions = - [text| - -Wincomplete-uni-patterns - -Wincomplete-record-updates - -Wcompat - -Widentities - $versionGhcOptions - |] - - versionGhcOptions :: Text - versionGhcOptions - = memptyIfFalse (settingsTestedVersions `hasLeast` Ghc802) - "-Wredundant-constraints\n" - <> memptyIfFalse (settingsTestedVersions `hasLeast` Ghc822) - "-fhide-source-paths\n" - <> memptyIfFalse (settingsTestedVersions `hasLeast` Ghc844) - [text| - -Wmissing-export-lists - -Wpartial-fields - |] - <> memptyIfFalse (settingsTestedVersions `hasLeast` Ghc882) - "-Wmissing-deriving-strategies\n" - where - hasLeast :: [GhcVer] -> GhcVer -> Bool - hasLeast list el = all (>= el) list diff --git a/summoner-cli/src/Summoner/Template/Doc.hs b/summoner-cli/src/Summoner/Template/Doc.hs index 95814456..7c0f5eac 100644 --- a/summoner-cli/src/Summoner/Template/Doc.hs +++ b/summoner-cli/src/Summoner/Template/Doc.hs @@ -15,7 +15,7 @@ module Summoner.Template.Doc ( docFiles ) where -import Summoner.License (License (..), LicenseName (None)) +import Summoner.License (License (..), LicenseName (NONE)) import Summoner.Settings (Settings (..)) import Summoner.Tree (TreeFs (..)) @@ -30,7 +30,7 @@ docFiles Settings{..} = maybeToList (File "CONTRIBUTING.md" <$> settingsContributing) where hasLicense :: Bool - hasLicense = settingsLicenseName /= None + hasLicense = settingsLicenseName /= NONE licenseName :: Text licenseName = show settingsLicenseName diff --git a/summoner-cli/test/Test/Golden.hs b/summoner-cli/test/Test/Golden.hs index 68ab8ee2..90ee3b2d 100644 --- a/summoner-cli/test/Test/Golden.hs +++ b/summoner-cli/test/Test/Golden.hs @@ -132,7 +132,7 @@ smallProject = Settings , settingsEmail = "xrom.xkov@gmail.com" , settingsYear = "2018" , settingsCategories = "" - , settingsLicenseName = None + , settingsLicenseName = NONE , settingsLicenseText = "" , settingsGitHub = False , settingsGhActions = False diff --git a/summoner-cli/test/golden/fullProject/fullProject.cabal b/summoner-cli/test/golden/fullProject/fullProject.cabal index 03ce2461..b5083235 100644 --- a/summoner-cli/test/golden/fullProject/fullProject.cabal +++ b/summoner-cli/test/golden/fullProject/fullProject.cabal @@ -28,8 +28,7 @@ common common-options build-depends: base-noprelude >= 4.9.1.0 && < 4.14 , relude - ghc-options: -Wall - -Wcompat + ghc-options: -Wcompat -Widentities default-language: Haskell2010 diff --git a/summoner-cli/test/golden/smallProject/smallProject.cabal b/summoner-cli/test/golden/smallProject/smallProject.cabal index ee9f66b8..1a143c34 100644 --- a/summoner-cli/test/golden/smallProject/smallProject.cabal +++ b/summoner-cli/test/golden/smallProject/smallProject.cabal @@ -3,7 +3,7 @@ name: smallProject version: 0.0.0.0 synopsis: Small test project description: Small test project -license: AllRightsReserved +license: NONE author: Kowainik maintainer: xrom.xkov@gmail.com copyright: 2018 Kowainik @@ -17,15 +17,19 @@ common common-options ghc-options: -Wall - -Wincomplete-uni-patterns - -Wincomplete-record-updates -Wcompat -Widentities - -Wredundant-constraints - -fhide-source-paths - -Wmissing-export-lists + -Wincomplete-uni-patterns + -Wincomplete-record-updates + if impl(ghc >= 8.0) + ghc-options: -Wredundant-constraints + if impl(ghc >= 8.2) + ghc-options: -fhide-source-paths + if impl(ghc >= 8.4) + ghc-options: -Wmissing-export-lists -Wpartial-fields - -Wmissing-deriving-strategies + if impl(ghc >= 8.8) + ghc-options: -Wmissing-deriving-strategies default-language: Haskell2010 diff --git a/summoner-tui/src/Summoner/Tui/Kit.hs b/summoner-tui/src/Summoner/Tui/Kit.hs index 3b8b1386..043d764f 100644 --- a/summoner-tui/src/Summoner/Tui/Kit.hs +++ b/summoner-tui/src/Summoner/Tui/Kit.hs @@ -248,7 +248,7 @@ configToSummonKit cRepo cOffline cConfigFile files Config{..} = SummonKit { projectRepo = cRepo , projectDesc = defaultDescription , projectCategory = "" - , projectLicense = if cOffline then None else cLicense + , projectLicense = if cOffline then NONE else cLicense } , summonKitProjectMeta = ProjectMeta { projectMetaLib = kitLib