Skip to content

Commit

Permalink
Add extra-packages parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jgotoh committed Apr 3, 2023
1 parent 3d5d582 commit 9ea3fc6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

14 changes: 14 additions & 0 deletions cabal-install/tests/IntegrationTests2/ProjectConfig/ParsecTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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"

Expand Down

0 comments on commit 9ea3fc6

Please sign in to comment.