hpack 0.35.5 → 0.36.0
raw patch · 6 files changed
+244/−187 lines, 6 filesdep +mtlPVP ok
version bump matches the API change (PVP)
Dependencies added: mtl
API changes (from Hackage documentation)
+ Hpack.Config: instance GHC.Classes.Eq Hpack.Config.SpecVersion
+ Hpack.Config: instance GHC.Classes.Ord Hpack.Config.SpecVersion
+ Hpack.Config: instance GHC.Show.Show Hpack.Config.SpecVersion
Files
- CHANGELOG.md +6/−0
- hpack.cabal +10/−5
- resources/test/hpack.cabal +10/−5
- src/Hpack/Config.hs +100/−69
- src/Imports.hs +1/−0
- test/EndToEndSpec.hs +117/−108
CHANGELOG.md view
@@ -1,3 +1,9 @@+## Changes in 0.36.0+ - Don't infer `Paths_`-module with `spec-version: 0.36.0` or later++## Changes in 0.35.5+ - Add (undocumented) `list` command+ ## Changes in 0.35.4 - Add `--canonical`, which can be used to produce canonical output instead of trying to produce minimal diffs
hpack.cabal view
@@ -1,11 +1,11 @@-cabal-version: 1.12+cabal-version: 2.0 --- This file has been generated from package.yaml by hpack version 0.35.4.+-- This file has been generated from package.yaml by hpack version 0.36.0. -- -- see: https://github.com/sol/hpack name: hpack-version: 0.35.5+version: 0.36.0 synopsis: A modern format for Haskell packages description: See README at <https://github.com/sol/hpack#readme> category: Development@@ -44,6 +44,7 @@ , http-client-tls >=0.3.6.2 , http-types , infer-license >=0.2.0 && <0.3+ , mtl , pretty , scientific , text@@ -83,6 +84,8 @@ Imports Path Paths_hpack+ autogen-modules:+ Paths_hpack default-language: Haskell2010 if impl(ghc >= 9.4.5) && os(windows) build-depends:@@ -110,6 +113,7 @@ , http-client-tls >=0.3.6.2 , http-types , infer-license >=0.2.0 && <0.3+ , mtl , pretty , scientific , text@@ -117,8 +121,6 @@ , unordered-containers , vector , yaml >=0.10.0- other-modules:- Paths_hpack default-language: Haskell2010 if impl(ghc >= 9.4.5) && os(windows) build-depends:@@ -153,6 +155,7 @@ , infer-license >=0.2.0 && <0.3 , interpolate , mockery >=0.3+ , mtl , pretty , scientific , template-haskell@@ -216,6 +219,8 @@ Hpack.Yaml Imports Path+ Paths_hpack+ autogen-modules: Paths_hpack default-language: Haskell2010 if impl(ghc >= 9.4.5) && os(windows)
resources/test/hpack.cabal view
@@ -1,11 +1,11 @@-cabal-version: 1.12+cabal-version: 2.0 --- This file has been generated from package.yaml by hpack version 0.35.4.+-- This file has been generated from package.yaml by hpack version 0.36.0. -- -- see: https://github.com/sol/hpack name: hpack-version: 0.35.5+version: 0.36.0 synopsis: A modern format for Haskell packages description: See README at <https://github.com/sol/hpack#readme> category: Development@@ -44,6 +44,7 @@ , http-client-tls >=0.3.6.2 , http-types , infer-license >=0.2.0 && <0.3+ , mtl , pretty , scientific , text@@ -83,6 +84,8 @@ Imports Path Paths_hpack+ autogen-modules:+ Paths_hpack default-language: Haskell2010 if impl(ghc >= 9.4.5) && os(windows) build-depends:@@ -110,6 +113,7 @@ , http-client-tls >=0.3.6.2 , http-types , infer-license >=0.2.0 && <0.3+ , mtl , pretty , scientific , text@@ -117,8 +121,6 @@ , unordered-containers , vector , yaml >=0.10.0- other-modules:- Paths_hpack default-language: Haskell2010 if impl(ghc >= 9.4.5) && os(windows) build-depends:@@ -153,6 +155,7 @@ , infer-license >=0.2.0 && <0.3 , interpolate , mockery >=0.3+ , mtl , pretty , scientific , template-haskell@@ -216,6 +219,8 @@ Hpack.Yaml Imports Path+ Paths_hpack+ autogen-modules: Paths_hpack default-language: Haskell2010 if impl(ghc >= 9.4.5) && os(windows)
src/Hpack/Config.hs view
@@ -1,19 +1,20 @@-{-# LANGUAGE DeriveGeneric #-}-{-# LANGUAGE DeriveFunctor #-}+{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveFoldable #-}+{-# LANGUAGE DeriveFunctor #-}+{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveTraversable #-}-{-# LANGUAGE DeriveAnyClass #-}+{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE LiberalTypeSynonyms #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RankNTypes #-} {-# LANGUAGE RecordWildCards #-}-{-# LANGUAGE CPP #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ViewPatterns #-}-{-# LANGUAGE RankNTypes #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE DataKinds #-} module Hpack.Config ( -- | /__NOTE:__/ This module is exposed to allow integration of Hpack into -- other tools. It is not meant for general use by end users. The following@@ -98,10 +99,10 @@ import Data.Scientific (Scientific) import System.Directory import System.FilePath-import Control.Monad.Trans.Class-import Control.Monad.Trans.Writer-import Control.Monad.Trans.Except-import Control.Monad.IO.Class+import Control.Monad.State (MonadState, StateT, evalStateT)+import qualified Control.Monad.State as State+import Control.Monad.Writer (MonadWriter, WriterT, runWriterT, tell)+import Control.Monad.Except import Data.Version (Version, makeVersion, showVersion) import Distribution.Pretty (prettyShow)@@ -635,17 +636,14 @@ instance FromValue ParsePackageConfig -type Warnings m = WriterT [String] m-type Errors = ExceptT HpackError--liftEither :: IO (Either HpackError a) -> Warnings (Errors IO) a-liftEither = lift . ExceptT+liftIOEither :: (MonadIO m, Errors m) => IO (Either HpackError a) -> m a+liftIOEither action = liftIO action >>= liftEither type FormatYamlParseError = FilePath -> Yaml.ParseException -> String -decodeYaml :: FromValue a => FormatYamlParseError -> FilePath -> Warnings (Errors IO) a+decodeYaml :: (FromValue a, MonadIO m, Warnings m, Errors m, State m) => FormatYamlParseError -> FilePath -> m a decodeYaml formatYamlParseError file = do- (warnings, a) <- liftEither $ first (ParseError . formatYamlParseError file) <$> Yaml.decodeYamlWithParseError file+ (warnings, a) <- liftIOEither $ first (ParseError . formatYamlParseError file) <$> Yaml.decodeYamlWithParseError file tell warnings decodeValue file a @@ -670,9 +668,18 @@ readPackageConfig :: DecodeOptions -> IO (Either String DecodeResult) readPackageConfig options = first (formatHpackError $ decodeOptionsProgramName options) <$> readPackageConfigWithError options +type Errors = MonadError HpackError+type Warnings = MonadWriter [String]+type State = MonadState SpecVersion++type ConfigM m = StateT SpecVersion (WriterT [String] (ExceptT HpackError m))++runConfigM :: Monad m => ConfigM m a -> m (Either HpackError (a, [String]))+runConfigM = runExceptT . runWriterT . (`evalStateT` NoSpecVersion)+ readPackageConfigWithError :: DecodeOptions -> IO (Either HpackError DecodeResult)-readPackageConfigWithError (DecodeOptions _ file mUserDataDir readValue formatYamlParseError) = runExceptT $ fmap addCabalFile . runWriterT $ do- (warnings, value) <- liftEither $ first ParseError <$> readValue file+readPackageConfigWithError (DecodeOptions _ file mUserDataDir readValue formatYamlParseError) = fmap (fmap addCabalFile) . runConfigM $ do+ (warnings, value) <- liftIOEither $ first ParseError <$> readValue file tell warnings config <- decodeValue file value dir <- liftIO $ takeDirectory <$> canonicalizePath file@@ -895,32 +902,44 @@ hasSubcomponents :: String -> Bool hasSubcomponents = elem ':' -sectionAll :: (Semigroup b, Monoid b) => (Section a -> b) -> Section a -> b+sectionAll :: Monoid b => (Section a -> b) -> Section a -> b sectionAll f sect = f sect <> foldMap (foldMap $ sectionAll f) (sectionConditionals sect) -decodeValue :: FromValue a => FilePath -> Value -> Warnings (Errors IO) a+decodeValue :: (FromValue a, State m, Warnings m, Errors m) => FilePath -> Value -> m a decodeValue file value = do- (r, unknown, deprecated) <- liftEither . return $ first (DecodeValueError file) (Config.decodeValue value)+ (r, unknown, deprecated) <- liftEither $ first (DecodeValueError file) (Config.decodeValue value) case r of UnsupportedSpecVersion v -> do- lift . throwE $ HpackVersionNotSupported file v Hpack.version- SupportedSpecVersion a -> do+ throwError $ HpackVersionNotSupported file v Hpack.version+ SupportedSpecVersion v a -> do tell (map formatUnknownField unknown) tell (map formatDeprecatedField deprecated)+ State.modify $ max v return a where+ prefix :: String prefix = file ++ ": "++ formatUnknownField :: String -> String formatUnknownField name = prefix ++ "Ignoring unrecognized field " ++ name++ formatDeprecatedField :: (String, String) -> String formatDeprecatedField (name, substitute) = prefix <> name <> " is deprecated, use " <> substitute <> " instead" -data CheckSpecVersion a = SupportedSpecVersion a | UnsupportedSpecVersion Version+data SpecVersion = NoSpecVersion | SpecVersion Version+ deriving (Eq, Show, Ord) +toSpecVersion :: Maybe ParseSpecVersion -> SpecVersion+toSpecVersion = maybe NoSpecVersion (SpecVersion . unParseSpecVersion)++data CheckSpecVersion a = SupportedSpecVersion SpecVersion a | UnsupportedSpecVersion Version+ instance FromValue a => FromValue (CheckSpecVersion a) where fromValue = withObject $ \ o -> o .:? "spec-version" >>= \ case Just (ParseSpecVersion v) | Hpack.version < v -> return $ UnsupportedSpecVersion v- _ -> SupportedSpecVersion <$> fromValue (Object o)+ v -> SupportedSpecVersion (toSpecVersion v) <$> fromValue (Object o) -newtype ParseSpecVersion = ParseSpecVersion Version+newtype ParseSpecVersion = ParseSpecVersion {unParseSpecVersion :: Version} instance FromValue ParseSpecVersion where fromValue value = do@@ -1058,7 +1077,7 @@ type CommonOptionsWithDefaults a = Product DefaultsConfig (CommonOptions ParseCSources ParseCxxSources ParseJsSources a) type WithCommonOptionsWithDefaults a = Product DefaultsConfig (WithCommonOptions ParseCSources ParseCxxSources ParseJsSources a) -toPackage :: FormatYamlParseError -> FilePath -> FilePath -> ConfigWithDefaults -> Warnings (Errors IO) (Package, String)+toPackage :: FormatYamlParseError -> FilePath -> FilePath -> ConfigWithDefaults -> ConfigM IO (Package, String) toPackage formatYamlParseError userDataDir dir = expandDefaultsInConfig formatYamlParseError userDataDir dir >=> setDefaultLanguage "Haskell2010"@@ -1070,28 +1089,31 @@ setLanguage = (mempty { commonOptionsLanguage = Alias . Last $ Just (Just language) } <>) expandDefaultsInConfig- :: FormatYamlParseError+ :: (MonadIO m, Warnings m, Errors m, State m) =>+ FormatYamlParseError -> FilePath -> FilePath -> ConfigWithDefaults- -> Warnings (Errors IO) (Config ParseCSources ParseCxxSources ParseJsSources)+ -> m (Config ParseCSources ParseCxxSources ParseJsSources) expandDefaultsInConfig formatYamlParseError userDataDir dir = bitraverse (expandGlobalDefaults formatYamlParseError userDataDir dir) (expandSectionDefaults formatYamlParseError userDataDir dir) expandGlobalDefaults- :: FormatYamlParseError+ :: (MonadIO m, Warnings m, Errors m, State m) =>+ FormatYamlParseError -> FilePath -> FilePath -> CommonOptionsWithDefaults Empty- -> Warnings (Errors IO) (CommonOptions ParseCSources ParseCxxSources ParseJsSources Empty)+ -> m (CommonOptions ParseCSources ParseCxxSources ParseJsSources Empty) expandGlobalDefaults formatYamlParseError userDataDir dir = do fmap (`Product` Empty) >>> expandDefaults formatYamlParseError userDataDir dir >=> \ (Product c Empty) -> return c expandSectionDefaults- :: FormatYamlParseError+ :: (MonadIO m, Warnings m, Errors m, State m) =>+ FormatYamlParseError -> FilePath -> FilePath -> PackageConfigWithDefaults ParseCSources ParseCxxSources ParseJsSources- -> Warnings (Errors IO) (PackageConfig ParseCSources ParseCxxSources ParseJsSources)+ -> m (PackageConfig ParseCSources ParseCxxSources ParseJsSources) expandSectionDefaults formatYamlParseError userDataDir dir p@PackageConfig{..} = do library <- traverse (expandDefaults formatYamlParseError userDataDir dir) packageConfigLibrary internalLibraries <- traverse (traverse (expandDefaults formatYamlParseError userDataDir dir)) packageConfigInternalLibraries@@ -1109,43 +1131,44 @@ } expandDefaults- :: (FromValue a, Semigroup a, Monoid a)+ :: forall a m. (MonadIO m, Warnings m, Errors m, State m) =>+ (FromValue a, Monoid a) => FormatYamlParseError -> FilePath -> FilePath -> WithCommonOptionsWithDefaults a- -> Warnings (Errors IO) (WithCommonOptions ParseCSources ParseCxxSources ParseJsSources a)+ -> m (WithCommonOptions ParseCSources ParseCxxSources ParseJsSources a) expandDefaults formatYamlParseError userDataDir = expand [] where- expand :: (FromValue a, Semigroup a, Monoid a) =>+ expand :: [FilePath] -> FilePath -> WithCommonOptionsWithDefaults a- -> Warnings (Errors IO) (WithCommonOptions ParseCSources ParseCxxSources ParseJsSources a)+ -> m (WithCommonOptions ParseCSources ParseCxxSources ParseJsSources a) expand seen dir (Product DefaultsConfig{..} c) = do d <- mconcat <$> mapM (get seen dir) (fromMaybeList defaultsConfigDefaults) return (d <> c) - get :: forall a. (FromValue a, Semigroup a, Monoid a) =>+ get :: [FilePath] -> FilePath -> Defaults- -> Warnings (Errors IO) (WithCommonOptions ParseCSources ParseCxxSources ParseJsSources a)+ -> m (WithCommonOptions ParseCSources ParseCxxSources ParseJsSources a) get seen dir defaults = do- file <- liftEither (ensure userDataDir dir defaults)- seen_ <- lift (checkCycle seen file)+ file <- liftIOEither (ensure userDataDir dir defaults)+ seen_ <- checkCycle seen file let dir_ = takeDirectory file decodeYaml formatYamlParseError file >>= expand seen_ dir_ - checkCycle :: [FilePath] -> FilePath -> Errors IO [FilePath]+ checkCycle :: [FilePath] -> FilePath -> m [FilePath] checkCycle seen file = do canonic <- liftIO $ canonicalizePath file let seen_ = canonic : seen when (canonic `elem` seen) $ do- throwE $ CycleInDefaults (reverse seen_)+ throwError $ CycleInDefaults (reverse seen_) return seen_ -toExecutableMap :: Monad m => String -> Maybe (Map String a) -> Maybe a -> Warnings m (Maybe (Map String a))+toExecutableMap :: Warnings m => String -> Maybe (Map String a) -> Maybe a -> m (Maybe (Map String a)) toExecutableMap name executables mExecutable = do case mExecutable of Just executable -> do@@ -1156,7 +1179,7 @@ type GlobalOptions = CommonOptions CSources CxxSources JsSources Empty -toPackage_ :: MonadIO m => FilePath -> Product GlobalOptions (PackageConfig CSources CxxSources JsSources) -> Warnings m (Package, String)+toPackage_ :: (MonadIO m, Warnings m, State m) => FilePath -> Product GlobalOptions (PackageConfig CSources CxxSources JsSources) -> m (Package, String) toPackage_ dir (Product g PackageConfig{..}) = do executableMap <- toExecutableMap packageName_ packageConfigExecutables packageConfigExecutable let@@ -1165,14 +1188,14 @@ executableNames = maybe [] Map.keys executableMap - toSect :: (Monad m, Monoid a) => WithCommonOptions CSources CxxSources JsSources a -> Warnings m (Section a)+ toSect :: (Warnings m, Monoid a) => WithCommonOptions CSources CxxSources JsSources a -> m (Section a) toSect = toSection packageName_ executableNames . first ((mempty <$ globalOptions) <>) - toSections :: (Monad m, Monoid a) => Maybe (Map String (WithCommonOptions CSources CxxSources JsSources a)) -> Warnings m (Map String (Section a))+ toSections :: (Warnings m, Monoid a) => Maybe (Map String (WithCommonOptions CSources CxxSources JsSources a)) -> m (Map String (Section a)) toSections = maybe (return mempty) (traverse toSect) - toLib = liftIO . toLibrary dir packageName_- toExecutables = toSections >=> traverse (liftIO . toExecutable dir packageName_)+ toLib = toLibrary dir packageName_+ toExecutables = toSections >=> traverse (toExecutable dir packageName_) mLibrary <- traverse (toSect >=> toLib) packageConfigLibrary internalLibraries <- toSections packageConfigInternalLibraries >>= traverse toLib@@ -1303,9 +1326,9 @@ _ -> Nothing expandForeignSources- :: MonadIO m+ :: (MonadIO m, Warnings m) => FilePath- -> Traverse (Warnings m) ParseCSources CSources ParseCxxSources CxxSources ParseJsSources JsSources+ -> Traverse m ParseCSources CSources ParseCxxSources CxxSources ParseJsSources JsSources expandForeignSources dir = Traverse { traverseCSources = expand "c-sources" , traverseCxxSources = expand "cxx-sources"@@ -1321,7 +1344,7 @@ instance IsString Path where fromString = Path -expandGlobs :: MonadIO m => String -> FilePath -> [String] -> Warnings m [Path]+expandGlobs :: (MonadIO m, Warnings m) => String -> FilePath -> [String] -> m [Path] expandGlobs name dir patterns = map Path <$> do (warnings, files) <- liftIO $ Util.expandGlobs name dir patterns tell warnings@@ -1364,7 +1387,7 @@ where p = (/= CondBool False) . conditionalCondition -inferModules ::+inferModules :: (MonadIO m, State m) => FilePath -> String -> (a -> [Module])@@ -1372,14 +1395,23 @@ -> ([Module] -> [Module] -> a -> b) -> ([Module] -> a -> b) -> Section a- -> IO (Section b)-inferModules dir packageName_ getMentionedModules getInferredModules fromData fromConditionals = fmap removeConditionalsThatAreAlwaysFalse . traverseSectionAndConditionals- (fromConfigSection fromData [pathsModuleFromPackageName packageName_])- (fromConfigSection (\ [] -> fromConditionals) [])- []+ -> m (Section b)+inferModules dir packageName_ getMentionedModules getInferredModules fromData fromConditionals sect_ = do+ specVersion <- State.get+ let+ pathsModule :: [Module]+ pathsModule = case specVersion of+ SpecVersion v | v >= makeVersion [0,36,0] -> []+ _ -> [pathsModuleFromPackageName packageName_]++ removeConditionalsThatAreAlwaysFalse <$> traverseSectionAndConditionals+ (fromConfigSection fromData pathsModule)+ (fromConfigSection (\ [] -> fromConditionals) [])+ []+ sect_ where fromConfigSection fromConfig pathsModule_ outerModules sect@Section{sectionData = conf} = do- modules <- listModules dir sect+ modules <- liftIO $ listModules dir sect let mentionedModules = concatMap getMentionedModules sect inferableModules = (modules \\ outerModules) \\ mentionedModules@@ -1387,7 +1419,7 @@ r = fromConfig pathsModule inferableModules conf return (outerModules ++ getInferredModules r, r) -toLibrary :: FilePath -> String -> Section LibrarySection -> IO (Section Library)+toLibrary :: (MonadIO m, State m) => FilePath -> String -> Section LibrarySection -> m (Section Library) toLibrary dir name = inferModules dir name getMentionedLibraryModules getLibraryModules fromLibrarySectionTopLevel fromLibrarySectionInConditional where@@ -1431,7 +1463,7 @@ getMentionedExecutableModules (ExecutableSection (Alias (Last main)) otherModules generatedModules)= maybe id (:) (toModule . Path.fromFilePath <$> main) $ fromMaybeList (otherModules <> generatedModules) -toExecutable :: FilePath -> String -> Section ExecutableSection -> IO (Section Executable)+toExecutable :: (MonadIO m, State m) => FilePath -> String -> Section ExecutableSection -> m (Section Executable) toExecutable dir packageName_ = inferModules dir packageName_ getMentionedExecutableModules getExecutableModules fromExecutableSection (fromExecutableSection []) . expandMain@@ -1462,7 +1494,7 @@ , sectionConditionals = map (fmap flatten) sectionConditionals } -toSection :: Monad m => String -> [String] -> WithCommonOptions CSources CxxSources JsSources a -> Warnings m (Section a)+toSection :: forall a m. Warnings m => String -> [String] -> WithCommonOptions CSources CxxSources JsSources a -> m (Section a) toSection packageName_ executableNames = go where go (Product CommonOptions{..} a) = do@@ -1500,15 +1532,15 @@ , sectionSystemBuildTools = systemBuildTools <> fromMaybe mempty commonOptionsSystemBuildTools , sectionVerbatim = fromMaybeList commonOptionsVerbatim }- toBuildTools :: Monad m => BuildTools -> Warnings m (SystemBuildTools, Map BuildTool DependencyVersion)- toBuildTools = fmap (mkSystemBuildTools &&& mkBuildTools) . mapM (toBuildTool packageName_ executableNames). unBuildTools+ toBuildTools :: BuildTools -> m (SystemBuildTools, Map BuildTool DependencyVersion)+ toBuildTools = fmap (mkSystemBuildTools &&& mkBuildTools) . mapM (toBuildTool packageName_ executableNames) . unBuildTools where mkSystemBuildTools :: [Either (String, VersionConstraint) b] -> SystemBuildTools mkSystemBuildTools = SystemBuildTools . Map.fromList . lefts mkBuildTools = Map.fromList . rights - toConditional :: Monad m => ConditionalSection CSources CxxSources JsSources a -> Warnings m (Conditional (Section a))+ toConditional :: ConditionalSection CSources CxxSources JsSources a -> m (Conditional (Section a)) toConditional x = case x of ThenElseConditional (Product (ThenElse then_ else_) c) -> conditional c <$> go then_ <*> (Just <$> go else_) FlatConditional (Product sect c) -> conditional c <$> (go sect) <*> pure Nothing@@ -1517,8 +1549,7 @@ type SystemBuildTool = (String, VersionConstraint) -toBuildTool :: Monad m => String -> [String] -> (ParseBuildTool, DependencyVersion)- -> Warnings m (Either SystemBuildTool (BuildTool, DependencyVersion))+toBuildTool :: Warnings m => String -> [String] -> (ParseBuildTool, DependencyVersion) -> m (Either SystemBuildTool (BuildTool, DependencyVersion)) toBuildTool packageName_ executableNames = \ case (QualifiedBuildTool pkg executable, v) | pkg == packageName_ && executable `elem` executableNames -> localBuildTool executable v
src/Imports.hs view
@@ -4,6 +4,7 @@ import Control.Arrow as Imports ((>>>), (&&&)) import Control.Exception as Imports (Exception(..)) import Control.Monad as Imports+import Control.Monad.IO.Class as Imports import Data.Bifunctor as Imports import Data.List as Imports hiding (sort, nub) import Data.Monoid as Imports (Monoid(..))
test/EndToEndSpec.hs view
@@ -28,7 +28,7 @@ writeFile file c = touch file >> Prelude.writeFile file c spec :: Spec-spec = around_ (inTempDirectoryNamed "foo") $ do+spec = around_ (inTempDirectoryNamed "my-package") $ do describe "hpack" $ do it "ignores fields that start with an underscore" $ do [i|@@ -73,10 +73,19 @@ library: {} |] `shouldRenderTo` library [i| other-modules:- Paths_foo+ Paths_my_package default-language: Haskell2010 |] + context "when spec-version is >= 0.36.0" $ do+ it "does not add Paths_" $ do+ [i|+ spec-version: 0.36.0+ library: {}+ |] `shouldRenderTo` library [i|+ default-language: Haskell2010+ |]+ context "when cabal-version is >= 2" $ do it "adds Paths_ to autogen-modules" $ do [i|@@ -85,9 +94,9 @@ library: {} |] `shouldRenderTo` (library [i| other-modules:- Paths_foo+ Paths_my_package autogen-modules:- Paths_foo+ Paths_my_package default-language: Haskell2010 |]) { packageCabalVersion = "2.0" } @@ -97,12 +106,12 @@ verbatim: cabal-version: 2.0 library:- generated-other-modules: Paths_foo+ generated-other-modules: Paths_my_package |] `shouldRenderTo` (library [i| other-modules:- Paths_foo+ Paths_my_package autogen-modules:- Paths_foo+ Paths_my_package default-language: Haskell2010 |]) { packageCabalVersion = "2.0" } @@ -112,12 +121,12 @@ verbatim: cabal-version: 2.0 library:- generated-exposed-modules: Paths_foo+ generated-exposed-modules: Paths_my_package |] `shouldRenderTo` (library [i| exposed-modules:- Paths_foo+ Paths_my_package autogen-modules:- Paths_foo+ Paths_my_package default-language: Haskell2010 |]) { packageCabalVersion = "2.0" } @@ -127,7 +136,7 @@ library: when: - condition: false- other-modules: Paths_foo+ other-modules: Paths_my_package |] `shouldRenderTo` library [i| default-language: Haskell2010 |]@@ -142,9 +151,9 @@ RebindableSyntax OverloadedStrings other-modules:- Paths_foo+ Paths_my_package autogen-modules:- Paths_foo+ Paths_my_package default-language: Haskell2010 |]) {packageCabalVersion = "2.2"} @@ -155,7 +164,7 @@ library: when: - condition: false- other-modules: Paths_foo+ other-modules: Paths_my_package |] `shouldRenderTo` (library [i| default-extensions: RebindableSyntax@@ -359,7 +368,7 @@ [i| executable: defaults: sol/hpack-template@2017- |] `shouldRenderTo` executable_ "foo" [i|+ |] `shouldRenderTo` executable_ "my-package" [i| main-is: Foo.hs |] @@ -372,7 +381,7 @@ executable: main: Bar.hs defaults: sol/hpack-template@2017- |] `shouldRenderTo` executable_ "foo" [i|+ |] `shouldRenderTo` executable_ "my-package" [i| main-is: Bar.hs |] @@ -522,9 +531,9 @@ license: BSD-3-Clause library other-modules:- Paths_foo+ Paths_my_package autogen-modules:- Paths_foo+ Paths_my_package cxx-options: -Wall default-language: Haskell2010 |]) {packageCabalVersion = "2.2"}@@ -538,9 +547,9 @@ license: some-license library other-modules:- Paths_foo+ Paths_my_package autogen-modules:- Paths_foo+ Paths_my_package cxx-options: -Wall default-language: Haskell2010 |]) {packageCabalVersion = "2.2"}@@ -635,7 +644,7 @@ executable: build-tools: alex == 0.1.0- |] `shouldRenderTo` executable_ "foo" [i|+ |] `shouldRenderTo` executable_ "my-package" [i| build-tools: alex ==0.1.0 |]@@ -645,7 +654,7 @@ executable: build-tools: hspec-discover: 0.1.0- |] `shouldRenderTo` (executable_ "foo" [i|+ |] `shouldRenderTo` (executable_ "my-package" [i| build-tool-depends: hspec-discover:hspec-discover ==0.1.0 |]) {@@ -659,7 +668,7 @@ executable: build-tool-depends: hspec-discover: 0.1.0- |] `shouldRenderTo` (executable_ "foo" [i|+ |] `shouldRenderTo` (executable_ "my-package" [i| build-tool-depends: hspec-discover:hspec-discover ==0.1.0 |]) {@@ -682,7 +691,7 @@ it "gives per-section unqualified names precedence over global qualified names" $ do [i| build-tools:- - foo:bar == 0.1.0+ - my-package:bar == 0.1.0 executables: bar: build-tools:@@ -699,7 +708,7 @@ executables: bar: build-tools:- - foo:bar == 0.2.0+ - my-package:bar == 0.2.0 |] `shouldRenderTo` executable_ "bar" [i| build-tools: bar ==0.2.0@@ -711,7 +720,7 @@ executable: build-tools: ghc >= 7.10- |] `shouldRenderTo` (executable_ "foo" [i|+ |] `shouldRenderTo` (executable_ "my-package" [i| build-tools: ghc >=7.10 |]) { packageWarnings = ["Listing \"ghc\" under build-tools is deperecated! Please list system executables under system-build-tools instead!"] }@@ -722,7 +731,7 @@ executable: system-build-tools: ghc >= 7.10- |] `shouldRenderTo` executable_ "foo" [i|+ |] `shouldRenderTo` executable_ "my-package" [i| build-tools: ghc >=7.10 |]@@ -733,7 +742,7 @@ executable: system-build-tools: hpc- |] `shouldRenderTo` (executable_ "foo" [i|+ |] `shouldRenderTo` (executable_ "my-package" [i| build-tools: hpc |]) {packageCabalVersion = "1.14"}@@ -744,7 +753,7 @@ executable: system-build-tools: ghcjs- |] `shouldRenderTo` (executable_ "foo" [i|+ |] `shouldRenderTo` (executable_ "my-package" [i| build-tools: ghcjs |]) {packageCabalVersion = "1.22"}@@ -755,9 +764,9 @@ executable: system-build-tools: g++ >= 5.4.0- |] `shouldRenderTo` (executable_ "foo" [i|+ |] `shouldRenderTo` (executable_ "my-package" [i| autogen-modules:- Paths_foo+ Paths_my_package build-tools: g++ >=5.4.0 |]) {packageCabalVersion = "2.0"}@@ -767,7 +776,7 @@ [i| executable: dependencies: base- |] `shouldRenderTo` executable_ "foo" [i|+ |] `shouldRenderTo` executable_ "my-package" [i| build-depends: base |]@@ -776,7 +785,7 @@ [i| executable: build-depends: base- |] `shouldRenderTo` (executable_ "foo" [i|+ |] `shouldRenderTo` (executable_ "my-package" [i| build-depends: base |]) {@@ -787,9 +796,9 @@ [i| executable: dependencies: foo:bar- |] `shouldRenderTo` (executable_ "foo" [i|+ |] `shouldRenderTo` (executable_ "my-package" [i| autogen-modules:- Paths_foo+ Paths_my_package build-depends: foo:bar |]) {packageCabalVersion = "3.0"}@@ -800,7 +809,7 @@ dependencies: - base - transformers- |] `shouldRenderTo` executable_ "foo" [i|+ |] `shouldRenderTo` executable_ "my-package" [i| build-depends: base , transformers@@ -813,7 +822,7 @@ - base executable: dependencies: hspec- |] `shouldRenderTo` executable_ "foo" [i|+ |] `shouldRenderTo` executable_ "my-package" [i| build-depends: base , hspec@@ -825,7 +834,7 @@ - base executable: dependencies: base >= 2- |] `shouldRenderTo` executable_ "foo" [i|+ |] `shouldRenderTo` executable_ "my-package" [i| build-depends: base >=2 |]@@ -837,7 +846,7 @@ - QtWebKit - weston executable: {}- |] `shouldRenderTo` executable_ "foo" [i|+ |] `shouldRenderTo` executable_ "my-package" [i| pkgconfig-depends: QtWebKit , weston@@ -849,7 +858,7 @@ - QtWebKit - weston executable: {}- |] `shouldRenderTo` executable_ "foo" [i|+ |] `shouldRenderTo` executable_ "my-package" [i| pkgconfig-depends: QtWebKit , weston@@ -862,7 +871,7 @@ - foo - bar executable: {}- |] `shouldRenderTo` executable_ "foo" [i|+ |] `shouldRenderTo` executable_ "my-package" [i| include-dirs: foo bar@@ -875,7 +884,7 @@ - foo.h - bar.h executable: {}- |] `shouldRenderTo` executable_ "foo" [i|+ |] `shouldRenderTo` executable_ "my-package" [i| install-includes: foo.h bar.h@@ -886,7 +895,7 @@ [i| ghc-shared-options: -Wall executable: {}- |] `shouldRenderTo` executable_ "foo" [i|+ |] `shouldRenderTo` executable_ "my-package" [i| ghc-shared-options: -Wall |] @@ -897,7 +906,7 @@ js-sources: - foo.js - jsbits/*.js- |] `shouldRenderTo` executable_ "foo" [i|+ |] `shouldRenderTo` executable_ "my-package" [i| js-sources: foo.js jsbits/bar.js@@ -909,7 +918,7 @@ - foo.js - jsbits/*.js executable: {}- |] `shouldRenderTo` executable_ "foo" [i|+ |] `shouldRenderTo` executable_ "my-package" [i| js-sources: foo.js jsbits/bar.js@@ -920,9 +929,9 @@ [i| executable: cxx-options: -Wall- |] `shouldRenderTo` (executable_ "foo" [i|+ |] `shouldRenderTo` (executable_ "my-package" [i| autogen-modules:- Paths_foo+ Paths_my_package cxx-options: -Wall |]) {packageCabalVersion = "2.2"} @@ -937,11 +946,11 @@ when: condition: True cxx-options: -Wall- |] `shouldRenderTo` (executable "foo" [i|+ |] `shouldRenderTo` (executable "my-package" [i| other-modules:- Paths_foo+ Paths_my_package autogen-modules:- Paths_foo+ Paths_my_package default-language: Haskell2010 if true if true@@ -956,9 +965,9 @@ cxx-sources: - foo.cc - cxxbits/*.cc- |] `shouldRenderTo` (executable_ "foo" [i|+ |] `shouldRenderTo` (executable_ "my-package" [i| autogen-modules:- Paths_foo+ Paths_my_package cxx-sources: foo.cc cxxbits/bar.cc@@ -969,9 +978,9 @@ [i| language: GHC2021 executable: {}- |] `shouldRenderTo` executable "foo" [i|+ |] `shouldRenderTo` executable "my-package" [i| other-modules:- Paths_foo+ Paths_my_package default-language: GHC2021 |] @@ -979,18 +988,18 @@ [i| language: null executable: {}- |] `shouldRenderTo` executable "foo" [i|+ |] `shouldRenderTo` executable "my-package" [i| other-modules:- Paths_foo+ Paths_my_package |] it "accepts default-language as an alias" $ do [i| default-language: GHC2021 executable: {}- |] `shouldRenderTo` (executable "foo" [i|+ |] `shouldRenderTo` (executable "my-package" [i| other-modules:- Paths_foo+ Paths_my_package default-language: GHC2021 |]) { packageWarnings = ["package.yaml: $.default-language is deprecated, use $.language instead"]@@ -1001,9 +1010,9 @@ language: Haskell2010 executable: language: GHC2021- |] `shouldRenderTo` executable "foo" [i|+ |] `shouldRenderTo` executable "my-package" [i| other-modules:- Paths_foo+ Paths_my_package default-language: GHC2021 |] @@ -1017,7 +1026,7 @@ library: {} |] `shouldRenderTo` library [i| other-modules:- Paths_foo+ Paths_my_package default-language: GHC2021 |] @@ -1028,7 +1037,7 @@ - foo - bar executable: {}- |] `shouldRenderTo` executable_ "foo" [i|+ |] `shouldRenderTo` executable_ "my-package" [i| extra-lib-dirs: foo bar@@ -1041,7 +1050,7 @@ - foo - bar executable: {}- |] `shouldRenderTo` executable_ "foo" [i|+ |] `shouldRenderTo` executable_ "my-package" [i| extra-libraries: foo bar@@ -1054,7 +1063,7 @@ - foo - bar executable: {}- |] `shouldRenderTo` executable_ "foo" [i|+ |] `shouldRenderTo` executable_ "my-package" [i| extra-frameworks-dirs: foo bar@@ -1067,7 +1076,7 @@ - foo - bar executable: {}- |] `shouldRenderTo` executable_ "foo" [i|+ |] `shouldRenderTo` executable_ "my-package" [i| frameworks: foo bar@@ -1167,7 +1176,7 @@ signatures: Foo |] `shouldRenderTo` (library_ [i| autogen-modules:- Paths_foo+ Paths_my_package signatures: Foo |]) {packageCabalVersion = "2.0"}@@ -1197,9 +1206,9 @@ - (Blah as Etc) |] `shouldRenderTo` (library [i| other-modules:- Paths_foo+ Paths_my_package autogen-modules:- Paths_foo+ Paths_my_package build-depends: foo mixins:@@ -1218,9 +1227,9 @@ exposed-modules: Foo other-modules:- Paths_foo+ Paths_my_package autogen-modules:- Paths_foo+ Paths_my_package hs-source-dirs: src |]@@ -1249,9 +1258,9 @@ |] `shouldRenderTo` (internalLibrary "bar" [i| visibility: public other-modules:- Paths_foo+ Paths_my_package autogen-modules:- Paths_foo+ Paths_my_package |]) {packageCabalVersion = "3.0"} context "when inferring modules" $ do@@ -1268,7 +1277,7 @@ exposed-modules: Foo other-modules:- Paths_foo+ Paths_my_package default-language: Haskell2010 |] @@ -1284,7 +1293,7 @@ exposed-modules: Foo other-modules:- Paths_foo+ Paths_my_package default-language: Haskell2010 |] @@ -1303,7 +1312,7 @@ Foo other-modules: Bar- Paths_foo+ Paths_my_package default-language: Haskell2010 |] @@ -1358,7 +1367,7 @@ Bar Foo other-modules:- Paths_foo+ Paths_my_package default-language: Haskell2010 |] @@ -1373,7 +1382,7 @@ condition: os(windows) exposed-modules: - Foo- - Paths_foo+ - Paths_my_package |] `shouldRenderTo` package [i| library hs-source-dirs:@@ -1384,7 +1393,7 @@ if os(windows) exposed-modules: Foo- Paths_foo+ Paths_my_package |] context "with a source-dir inside the conditional" $ do@@ -1398,7 +1407,7 @@ |] `shouldRenderTo` package [i| library other-modules:- Paths_foo+ Paths_my_package default-language: Haskell2010 if os(windows) other-modules:@@ -1425,7 +1434,7 @@ exposed-modules: Foo other-modules:- Paths_foo+ Paths_my_package default-language: Haskell2010 if os(windows) hs-source-dirs:@@ -1445,10 +1454,10 @@ exposed-modules: Foo other-modules:- Paths_foo+ Paths_my_package Bar autogen-modules:- Paths_foo+ Paths_my_package Foo Bar default-language: Haskell2010@@ -1468,10 +1477,10 @@ exposed-modules: Exposed other-modules:- Paths_foo+ Paths_my_package Other autogen-modules:- Paths_foo+ Paths_my_package Exposed Other default-language: Haskell2010@@ -1490,9 +1499,9 @@ |] `shouldRenderTo` (package [i| library other-modules:- Paths_foo+ Paths_my_package autogen-modules:- Paths_foo+ Paths_my_package hs-source-dirs: src default-language: Haskell2010@@ -1521,7 +1530,7 @@ src other-modules: Foo- Paths_foo+ Paths_my_package default-language: Haskell2010 |] @@ -1556,10 +1565,10 @@ hs-source-dirs: src other-modules:- Paths_foo+ Paths_my_package Foo autogen-modules:- Paths_foo+ Paths_my_package Foo default-language: Haskell2010 |]) {packageCabalVersion = "2.0"}@@ -1578,7 +1587,7 @@ |] `shouldRenderTo` executable "foo" [i| other-modules: Bar- Paths_foo+ Paths_my_package hs-source-dirs: src default-language: Haskell2010@@ -1600,7 +1609,7 @@ |] `shouldRenderTo` executable "foo" [i| other-modules: Foo- Paths_foo+ Paths_my_package hs-source-dirs: src default-language: Haskell2010@@ -1616,7 +1625,7 @@ [i| executable: main-is: Foo.hs- |] `shouldRenderTo` (executable_ "foo" [i|+ |] `shouldRenderTo` (executable_ "my-package" [i| main-is: Foo.hs |]) { packageWarnings = ["package.yaml: $.executable.main-is is deprecated, use $.executable.main instead"]@@ -1637,7 +1646,7 @@ src other-modules: Bar- Paths_foo+ Paths_my_package default-language: Haskell2010 |] @@ -1654,7 +1663,7 @@ |] `shouldRenderTo` executable "foo" [i| ghc-options: -Wall other-modules:- Paths_foo+ Paths_my_package default-language: Haskell2010 if os(windows) main-is: Foo.hs@@ -1669,7 +1678,7 @@ main: Foo |] `shouldRenderTo` executable "foo" [i| other-modules:- Paths_foo+ Paths_my_package default-language: Haskell2010 if os(windows) main-is: Foo.hs@@ -1683,9 +1692,9 @@ condition: os(windows) dependencies: Win32 executable: {}- |] `shouldRenderTo` executable "foo" [i|+ |] `shouldRenderTo` executable "my-package" [i| other-modules:- Paths_foo+ Paths_my_package default-language: Haskell2010 if os(windows) build-depends:@@ -1720,9 +1729,9 @@ else: dependencies: unix executable: {}- |] `shouldRenderTo` executable "foo" [i|+ |] `shouldRenderTo` executable "my-package" [i| other-modules:- Paths_foo+ Paths_my_package default-language: Haskell2010 if os(windows) build-depends:@@ -1813,7 +1822,7 @@ |] `shouldRenderTo` package [i| library other-modules:- Paths_foo+ Paths_my_package default-language: Haskell2010 foo: 23 bar: 42@@ -1830,7 +1839,7 @@ |] `shouldRenderTo` package [i| library other-modules:- Paths_foo+ Paths_my_package default-language: Haskell2010 build-depneds: foo@@ -1846,7 +1855,7 @@ |] `shouldRenderTo` package [i| library other-modules:- Paths_foo+ Paths_my_package |] context "when specified globally" $ do@@ -1875,7 +1884,7 @@ foo: 23 library other-modules:- Paths_foo+ Paths_my_package default-language: Haskell2010 |] @@ -1890,7 +1899,7 @@ test-suite spec type: detailed-0.9 other-modules:- Paths_foo+ Paths_my_package default-language: Haskell2010 |] describe "default value of maintainer" $ do@@ -1943,7 +1952,7 @@ shouldRenderTo :: HasCallStack => String -> Package -> Expectation shouldRenderTo input p = do- writeFile packageConfig ("name: foo\n" ++ unindent input)+ writeFile packageConfig ("name: my-package\n" ++ unindent input) (warnings, output) <- run "" packageConfig expected RenderResult warnings (dropEmptyLines output) `shouldBe` RenderResult (packageWarnings p) expected where@@ -1975,7 +1984,7 @@ content = [i| library other-modules:- Paths_foo+ Paths_my_package #{indentBy 2 $ unindent l} default-language: Haskell2010 |]@@ -2003,7 +2012,7 @@ content = [i| executable #{name} other-modules:- Paths_foo+ Paths_my_package #{indentBy 2 $ unindent e} default-language: Haskell2010 |]@@ -2017,7 +2026,7 @@ |] package :: String -> Package-package c = Package "foo" "0.0.0" "Simple" "1.12" c []+package c = Package "my-package" "0.0.0" "Simple" "1.12" c [] data Package = Package { packageName :: String