From 402f6071d1a892595244c55ed1cc3ac95d4a7e69 Mon Sep 17 00:00:00 2001 From: jgotoh <18658140+jgotoh@users.noreply.github.com> Date: Mon, 3 Apr 2023 08:51:16 +0200 Subject: [PATCH] Add extra-packages parsing --- .../Client/ProjectConfig/FieldGrammar.hs | 10 ++++++++-- .../ProjectConfig/ParsecTests.hs | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cabal-install/src/Distribution/Client/ProjectConfig/FieldGrammar.hs b/cabal-install/src/Distribution/Client/ProjectConfig/FieldGrammar.hs index 11678832edb..e39f1d82564 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig/FieldGrammar.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig/FieldGrammar.hs @@ -4,20 +4,26 @@ module Distribution.Client.ProjectConfig.FieldGrammar ( projectConfigFieldGrammar ) where +import Distribution.Compat.Prelude import Distribution.Client.ProjectConfig.Legacy (ProjectConfigSkeleton) import qualified Distribution.Client.ProjectConfig.Lens as L import Distribution.Client.ProjectConfig.Types (ProjectConfig (..)) import Distribution.FieldGrammar +import Distribution.Types.PackageVersionConstraint (PackageVersionConstraint (..)) projectConfigFieldGrammar :: ParsecFieldGrammar' ProjectConfig projectConfigFieldGrammar = ProjectConfig <$> monoidalFieldAla "packages" (alaList' FSep Token') L.projectPackages <*> monoidalFieldAla "optional-packages" (alaList' FSep Token') L.projectPackagesOptional + <*> pure mempty -- source-repository-package stanza + <*> monoidalFieldAla "extra-packages" formatPackagesNamedList L.projectPackagesNamed <*> pure mempty <*> pure mempty <*> pure mempty <*> pure mempty <*> pure mempty <*> pure mempty - <*> pure mempty - <*> pure mempty + +formatPackagesNamedList :: [PackageVersionConstraint] -> List CommaVCat (Identity PackageVersionConstraint) PackageVersionConstraint +formatPackagesNamedList = alaList CommaVCat + diff --git a/cabal-install/tests/IntegrationTests2/ProjectConfig/ParsecTests.hs b/cabal-install/tests/IntegrationTests2/ProjectConfig/ParsecTests.hs index 62a80fe03e1..c1ce66d9797 100644 --- a/cabal-install/tests/IntegrationTests2/ProjectConfig/ParsecTests.hs +++ b/cabal-install/tests/IntegrationTests2/ProjectConfig/ParsecTests.hs @@ -14,6 +14,10 @@ import Distribution.Client.DistDirLayout import Distribution.Client.ProjectConfig import Distribution.Client.RebuildMonad (runRebuild) import Distribution.Types.CondTree (CondTree (..)) +import Distribution.Types.PackageName +import Distribution.Types.PackageVersionConstraint (PackageVersionConstraint (..)) +import Distribution.Types.Version (Version, mkVersion) +import Distribution.Types.VersionRange.Internal (VersionRange (..)) import Distribution.Verbosity -- TODO create tests: @@ -24,6 +28,7 @@ parserTests = [ -- testCase "read with legacy parser" testLegacyRead testCase "read packages" testPackages , testCase "read optional-packages" testOptionalPackages + , testCase "read extra-packages" testExtraPackages ] -- Currently I compare the results of legacy parser with the new parser @@ -51,7 +56,7 @@ testLegacyRead = do testPackages :: Assertion testPackages = do - let expected = [".", "packages/packages.cabal"] -- TODO https link, what does legacy parse? + let expected = [".", "packages/packages.cabal"] -- TODO also test https link -- Note that I currently also run the legacy parser to make sure my expected values -- do not differ from the non-Parsec implementation, this will be removed in the future (config, legacy) <- readConfigDefault "packages" @@ -63,6 +68,15 @@ testOptionalPackages = do (config, legacy) <- readConfigDefault "optional-packages" assertConfig expected config legacy (projectPackagesOptional . condTreeData) +testExtraPackages :: Assertion +testExtraPackages = do + let expected = [ + PackageVersionConstraint (mkPackageName "a") (OrLaterVersion (mkVersion [0])), + PackageVersionConstraint (mkPackageName "b") (IntersectVersionRanges (OrLaterVersion (mkVersion [0,7,3])) (EarlierVersion (mkVersion [0,9]))) + ] + (config, legacy) <- readConfigDefault "extra-packages" + assertConfig expected config legacy (projectPackagesNamed . condTreeData) + readConfigDefault :: FilePath -> IO (ProjectConfigSkeleton, ProjectConfigSkeleton) readConfigDefault rootFp = readConfig rootFp "cabal.project"